<commit_before><?php

namespace Datatheke\Bundle\PagerBundle\Pager\Handler\Http;

use Symfony\Component\HttpFoundation\Request;

use Datatheke\Bundle\PagerBundle\Pager\PagerInterface;
use Datatheke\Bundle\PagerBundle\Pager\OrderBy;
use Datatheke\Bundle\PagerBundle\Pager\Field;
use Datatheke\Bundle\PagerBundle\Pager\Filter;

class JqGridHandler extends AbstractHandler
{
    public function handleRequest(PagerInterface $pager, Request $request)
    {
        if ($this->has($request, 'page')) {
            $pager->setCurrentPageNumber($this->get($request, 'page'));
        }

        if ($this->has($request, 'rows')) {
            $pager->setItemCountPerPage($this->get($request, 'rows'));
        }

        $fields = $pager->getFields();
        if ($this->has($request, 'sidx') && isset($fields[$field = $this->get($request, 'sidx')])) {
            $order = $this->get($request, 'sord', 'asc') === 'asc' ? OrderBy::ASC : OrderBy::DESC;
            $pager->setOrderBy(new OrderBy(array($field => $order)));
        }

        $filters = array();
        if( $this->has($request, 'filters')) {
            $filters = $this->get($request, 'filters');
            $rules = array();
            if( isset( $filters['rules']) && isset($filters['groupOp']) )
            {
                $rules = $filters['rules'];
                $groupOp = (($filters['groupOp'] == 'OR') ? Filter::LOGICAL_OR : Filter::LOGICAL_AND);

                // map filter operators to jqGrid sOpts
                $opMap = array(
                        'eq' => Filter::OPERATOR_EQUALS,
                        'ne' => Filter::OPERATOR_NOT_EQUALS,
                        'lt' => Filter::OPERATOR_LESS,
                        'le' => Filter::OPERATOR_LESS_EQUALS,
                        'gt' => Filter::OPERATOR_GREATER,
                        'ge' => Filter::OPERATOR_GREATER_EQUALS,
                        'bw' => null,
                        'bn' => null,
                        'in' => Filter::OPERATOR_IN,
                        'ni' => Filter::OPERATOR_NOT_IN,
                        'ew' => null,
                        'en' => null,
                        'cn' => Filter::OPERATOR_CONTAINS,
                        'nc' => Filter::OPERATOR_NOT_CONTAINS,
                        'nu' => Filter::OPERATOR_NULL,
                        'nn' => Filter::OPERATOR_NOT_NULL
                    );


                $searchFields = array();
                $searchData = array();
                $searchOperators = array();
                foreach( $rules as $r ) {
                    array_push($searchFields, $r['field']);
                    array_push($searchData, $r['data']);
                    array_push($searchOperators, $opMap[ $r['op'] ]);
                }

                $pager->setFilter(new Filter($searchFields, $searchData, array($searchOperators), array(array(array($groupOp, null))) ));
            }
        }
    }
}<commit_msg>removes unnecessary instantiations, and removes the use of arrauy_push<commit_after><?php

namespace Datatheke\Bundle\PagerBundle\Pager\Handler\Http;

use Symfony\Component\HttpFoundation\Request;

use Datatheke\Bundle\PagerBundle\Pager\PagerInterface;
use Datatheke\Bundle\PagerBundle\Pager\OrderBy;
use Datatheke\Bundle\PagerBundle\Pager\Field;
use Datatheke\Bundle\PagerBundle\Pager\Filter;

class JqGridHandler extends AbstractHandler
{
    public function handleRequest(PagerInterface $pager, Request $request)
    {
        if ($this->has($request, 'page')) {
            $pager->setCurrentPageNumber($this->get($request, 'page'));
        }

        if ($this->has($request, 'rows')) {
            $pager->setItemCountPerPage($this->get($request, 'rows'));
        }

        $fields = $pager->getFields();
        if ($this->has($request, 'sidx') && isset($fields[$field = $this->get($request, 'sidx')])) {
            $order = $this->get($request, 'sord', 'asc') === 'asc' ? OrderBy::ASC : OrderBy::DESC;
            $pager->setOrderBy(new OrderBy(array($field => $order)));
        }

        if( $this->has($request, 'filters')) {
            $filters = $this->get($request, 'filters');
            if( isset( $filters['rules']) && isset($filters['groupOp']) )
            {
                $rules = $filters['rules'];
                $groupOp = (($filters['groupOp'] == 'OR') ? Filter::LOGICAL_OR : Filter::LOGICAL_AND);

                // map filter operators to jqGrid sOpts
                $opMap = array(
                        'eq' => Filter::OPERATOR_EQUALS,
                        'ne' => Filter::OPERATOR_NOT_EQUALS,
                        'lt' => Filter::OPERATOR_LESS,
                        'le' => Filter::OPERATOR_LESS_EQUALS,
                        'gt' => Filter::OPERATOR_GREATER,
                        'ge' => Filter::OPERATOR_GREATER_EQUALS,
                        'bw' => null,
                        'bn' => null,
                        'in' => Filter::OPERATOR_IN,
                        'ni' => Filter::OPERATOR_NOT_IN,
                        'ew' => null,
                        'en' => null,
                        'cn' => Filter::OPERATOR_CONTAINS,
                        'nc' => Filter::OPERATOR_NOT_CONTAINS,
                        'nu' => Filter::OPERATOR_NULL,
                        'nn' => Filter::OPERATOR_NOT_NULL
                    );


                $searchFields = array();
                $searchData = array();
                $searchOperators = array();
                foreach( $rules as $r ) {
                    $searchFields[] = $r['field'];
                    $searchData[] = $r['data'];
                    $searchOperators[] = $opMap[ $r['op'] ];
                }

                $pager->setFilter(new Filter($searchFields, $searchData, array($searchOperators), array(array(array($groupOp, null))) ));
            }
        }
    }
}
{'fraction_non_alphanumeric': 0.15273037542662116, 'fraction_numerical': 0.0, 'mean_word_length': 1.7620169651272384, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 65, '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': '1991876', 'n_tokens_mistral': 1701, 'n_tokens_neox': 1623, 'n_words': 274}