<commit_before><?php

/**
 *  Bluware PHP Lite & Scaleable Web Frame
 *
 *  @package  Frame
 *  @author   <NAME>
 */
namespace Frame;

use Frame\ActiveRecord\Query;

/**
 * @subpackage Active
 */
abstract class ActiveRecord extends Query
{
    /**
     *  @param  array  $data
     *  @return mixed
     */
    public static function create(array $data)
    {
        return (
            new static()
        )->insert(
            $data
        );
    }

    /**
     *  @param  scalar $id
     *  @return mixed
     */
    public static function find($id)
    {
        return (
            new static()
        )->select(
            'one', function(
                $q, $self
            ) use ($id) {
                /**
                 *  @var boolean
                 */
                $primary = is_scalar($self->primary);

                /**
                 *  @var boolean
                 */
                if ($primary === false)
                    throw new \Exception(
                        "Bad primary implementation"
                    );

                /**
                 *  @var boolean
                 */
                $q->where([
                    $self->primary
                        => $id
                ])->limit(
                    1, 0
                );
            }
        );
    }

    /**
     *  @param  mixed   $where
     *  @param  mixed   $order
     *  @param  integer $offset
     *
     *  @return mixed
     */
    public static function one(
        $where  = null,
        $order  = null,
        $offset = null
    ) {
        return (
            new static()
        )->select(
            'one', function(
                $q, $self
            ) use (
                $where,
                $order,
                $offset
            ) {
                is_callable(
                    $where
                ) ? call_user_func(
                    $where, $q
                ) : $q->where(
                    $where
                );

                $q->order(
                    $order
                )->limit(
                    1,
                    $offset
                );
            }
        );
    }

    /**
     *  @param  mixed   $where
     *  @param  mixed   $order
     *  @param  integer $limit
     *  @param  integer $offset
     *
     *  @return mixed
     */
    public static function by(
        $where  = null,
        $order  = null,
        $limit  = null,
        $offset = null
    ) {
        return (
            new static()
        )->select(
            'all', function(<commit_msg>new methods Class::one(query, function($q, $this) {}) and Class::by(query, function($q, $this) {})<commit_after><?php

/**
 *  Bluware PHP Lite & Scaleable Web Frame
 *
 *  @package  Frame
 *  @author   <NAME>
 */
namespace Frame;

use Frame\ActiveRecord\Query;

/**
 * @subpackage Active
 */
abstract class ActiveRecord extends Query
{
    /**
     *  @param  array  $data
     *  @return mixed
     */
    public static function create(array $data)
    {
        return (new static)->insert(
            $data
        );
    }

    /**
     *  @param  scalar $id
     *  @return mixed
     */
    public static function find($id)
    {
        return (new static)->select(
            'one', function(
                $q, $self
            ) use ($id) {
                /**
                 *  @var boolean
                 */
                $primary = is_scalar($self->primary);

                /**
                 *  @var boolean
                 */
                if ($primary === false)
                    throw new \Exception(
                        "Bad primary implementation"
                    );

                /**
                 *  @var boolean
                 */
                $q->where([
                    $self->primary
                        => $id
                ])->limit(
                    1, 0
                );
            }
        );
    }

    /**
     *  @param  mixed   $where
     *  @param  mixed   $order
     *  @param  integer $offset
     *
     *  @return mixed
     */
    public static function one(
        $where  = null,
        $order  = null,
        $offset = null
    ) {
        if (gettype($where) === 'string' && $where === 'query')
            return (new static)->query('one', $order);

        return (new static)->select(
            'one', function(
                $q, $self
            ) use (
                $where,
                $order,
                $offset
            ) {
                is_callable(
                    $where
                ) ? call_user_func(
                    $where, $q
                ) : $q->where(
                    $where
                );

                $q->order(
                    $order
                )->limit(
                    1,
                    $offset
                );
            }
        );
    }

    /**
     *  @param  mixed   $where
     *  @param  mixed   $order
     *  @param  integer $limit
     *  @param  integer $offset
     *
     *  @return mixed
     */
    public static function by(
        $where  = null,
        $order  = null,
        $limit  = null,
        $offset = null
    ) {
        if (gettype($where) === 'string' && $where === 'query')
            return (new static)->query('all', $order);

        return (new static)->select(
            'all', function(
{'fraction_non_alphanumeric': 0.11792887414777962, 'fraction_numerical': 0.001105583195135434, 'mean_word_length': 0.8672170622635019, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '336879', 'n_tokens_mistral': 1491, 'n_tokens_neox': 1407, 'n_words': 334}