<commit_before><?php
/**
 * @copyright Bluz PHP Team
 * @link https://github.com/bluzphp/skeleton
 */

/**
 * @namespace
 */
namespace Application\Test;

use Bluz\Validator\Validator as v;
use Bluz\Validator\ValidatorBuilder;

/**
 * Crud based on Db\Table
 *
 * @package  Application\Test
 *
 * @method   Table getTable()
 *
 * @author   <NAME>
 * @created  03.09.12 13:11
 */
class Crud extends \Bluz\Crud\Table
{
    /**
     * {@inheritdoc}
     *
     * @param int $offset
     * @param int $limit
     * @param array $params
     * @return array|int|mixed
     */
    public function readSet($offset = 0, $limit = 10, $params = array())
    {
        $select = app()->getDb()
            ->select('*')
            ->from('test', 't');

        if ($limit) {
            $selectPart = $select->getQueryPart('select');
            $selectPart[0] = 'SQL_CALC_FOUND_ROWS ' . current($selectPart);
            $select->select($selectPart);

            $select->setLimit($limit);
            $select->setOffset($offset);
        }

        $result = $select->execute('\\Application\\Test\\Row');

        if ($limit) {
            $total = app()->getDb()->fetchOne('SELECT FOUND_ROWS()');
        } else {
            $total = sizeof($result);
        }

        if (sizeof($result) < $total) {
            app()->getResponse()
                ->setCode(206)
                ->setHeader('Content-Range', 'items '.$offset.'-'.($offset+sizeof($result)).'/'. $total);
        }

        return $result;
    }

    /**
     * {@inheritdoc}
     *
     * @param mixed $id
     * @param array $data
     * @return bool
     */
    public function validate($id, $data)
    {
        $validator = new ValidatorBuilder();

        // name validator
        $validator->add(
            'name',
            v::required()->latin()
        );

        // email validator
        $validator->add(
            'email',
            v::required()->email()
        );

        if (!$validator->validate($data)) {
            $this->setErrors($validator->getErrors());
        }
    }
}<commit_msg>Updated Test for Crud<commit_after><?php
/**
 * @copyright Bluz PHP Team
 * @link https://github.com/bluzphp/skeleton
 */

/**
 * @namespace
 */
namespace Application\Test;

use Bluz\Validator\Validator as v;
use Bluz\Validator\ValidatorBuilder;

/**
 * Crud based on Db\Table
 *
 * @package  Application\Test
 *
 * @method   Table getTable()
 *
 * @author   <NAME>
 * @created  03.09.12 13:11
 */
class Crud extends \Bluz\Crud\Table
{
    /**
     * {@inheritdoc}
     *
     * @param int $offset
     * @param int $limit
     * @param array $params
     * @return array|int|mixed
     */
    public function readSet($offset = 0, $limit = 10, $params = array())
    {
        $select = app()->getDb()
            ->select('*')
            ->from('test', 't');

        if ($limit) {
            $selectPart = $select->getQueryPart('select');
            $selectPart[0] = 'SQL_CALC_FOUND_ROWS ' . current($selectPart);
            $select->select($selectPart);

            $select->setLimit($limit);
            $select->setOffset($offset);
        }

        $result = $select->execute('\\Application\\Test\\Row');

        if ($limit) {
            $total = app()->getDb()->fetchOne('SELECT FOUND_ROWS()');
        } else {
            $total = sizeof($result);
        }

        if (sizeof($result) < $total) {
            app()->getResponse()
                ->setCode(206)
                ->setHeader('Content-Range', 'items '.$offset.'-'.($offset+sizeof($result)).'/'. $total);
        }

        return $result;
    }

    /**
     * {@inheritdoc}
     *
     * @param array $data
     * @return bool
     */
    public function validateCreate($data)
    {
        $validator = new ValidatorBuilder();

        // name validator
        $validator->add(
            'name',
            v::required()->latin()
        );

        // email validator
        $validator->add(
            'email',
            v::required()->email()
        );

        if (!$validator->validate($data)) {
            $this->setErrors($validator->getErrors());
        }
    }

    /**
     * {@inheritdoc}
     *
     * @param mixed $id
     * @param array $data
     * @return bool
     */
    public function validateUpdate($id, $data)
    {
        $validator = new ValidatorBuilder();

        // name validator
        $validator->add(
            'name',
            v::notEmpty()->latin()
        );

        // email validator
        $validator->add(
            'email',
            v::notEmpty()->email()
        );

        if (!$validator->validate($data)) {
            $this->setErrors($validator->getErrors());
        }
    }
}
{'fraction_non_alphanumeric': 0.17204072974119644, 'fraction_numerical': 0.007212558336868901, 'mean_word_length': 1.7412790697674418, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 52, 'https://': 2, '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': '2992034', 'n_tokens_mistral': 1435, 'n_tokens_neox': 1397, 'n_words': 266}