<commit_before><?php

namespace Oro\Bundle\ApiBundle\Processor\GetList;

use Oro\Bundle\ApiBundle\Filter\SortFilter;
use Oro\Bundle\ApiBundle\Util\ConfigUtil;
use Oro\Component\ChainProcessor\ContextInterface;
use Oro\Component\ChainProcessor\ProcessorInterface;

class BuildCriteria implements ProcessorInterface
{
    /**
     * {@inheritdoc}
     */
    public function process(ContextInterface $context)
    {
        /** @var GetListContext $context */

        if ($context->hasQuery()) {
            // a query is already built
            return;
        }

        $criteria     = $context->getCriteria();
        $filterValues = $context->getFilterValues();
        $filters      = $context->getFilters();
        foreach ($filters as $filterKey => $filter) {
            $filterValue = null;
            if ($filterValues->has($filterKey)) {
                $filterValue = $filterValues->get($filterKey);
            }

            if ($filter instanceof SortFilter) {
                $sortersConfigFields = $context->getConfigOfSorters()[ConfigUtil::FIELDS];
                foreach ($filterValue->getValue() as $field => $direction) {
                    if (!array_key_exists($field, $sortersConfigFields)) {
                        throw new \InvalidArgumentException(
                            sprintf(
                                'Sorting by the field "%s" does not supports',
                                $field
                            )
                        );
                    }
                }
            }
            $filter->apply($criteria, $filterValue);
        }
    }
}<commit_msg>BAP-9409: Restrict sorters by indexed fields only  - fix error string<commit_after><?php

namespace Oro\Bundle\ApiBundle\Processor\GetList;

use Oro\Bundle\ApiBundle\Filter\SortFilter;
use Oro\Bundle\ApiBundle\Util\ConfigUtil;
use Oro\Component\ChainProcessor\ContextInterface;
use Oro\Component\ChainProcessor\ProcessorInterface;

class BuildCriteria implements ProcessorInterface
{
    /**
     * {@inheritdoc}
     */
    public function process(ContextInterface $context)
    {
        /** @var GetListContext $context */

        if ($context->hasQuery()) {
            // a query is already built
            return;
        }

        $criteria     = $context->getCriteria();
        $filterValues = $context->getFilterValues();
        $filters      = $context->getFilters();
        foreach ($filters as $filterKey => $filter) {
            $filterValue = null;
            if ($filterValues->has($filterKey)) {
                $filterValue = $filterValues->get($filterKey);
            }

            if ($filter instanceof SortFilter) {
                $sortersConfigFields = $context->getConfigOfSorters()[ConfigUtil::FIELDS];
                foreach ($filterValue->getValue() as $field => $direction) {
                    if (!array_key_exists($field, $sortersConfigFields)) {
                        throw new \InvalidArgumentException(
                            sprintf(
                                'Sorting by the field "%s" is not supported',
                                $field
                            )
                        );
                    }
                }
            }
            $filter->apply($criteria, $filterValue);
        }
    }
}
{'fraction_non_alphanumeric': 0.10937029225670383, 'fraction_numerical': 0.0012051822838204278, 'mean_word_length': 1.6688102893890675, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 25, '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': '2140981', 'n_tokens_mistral': 828, 'n_tokens_neox': 801, 'n_words': 163}