<commit_before><?php

namespace UWDOEM\Framework\Filter;

use Propel\Runtime\ActiveQuery\ModelCriteria;

use UWDOEM\Framework\Etc\ORMUtils;
use UWDOEM\Framework\Row\RowInterface;
use UWDOEM\Framework\FilterStatement\FilterStatementInterface;
use UWDOEM\Framework\Visitor\VisitableTrait;


class Filter implements FilterInterface {

    const TYPE_SEARCH = "search";
    const TYPE_SORT = "sort";
    const TYPE_SELECT = "select";
    const TYPE_STATIC = "static";
    const TYPE_PAGINATION = "pagination";

    /** @var array|FilterStatementInterface[] */
    protected $_statements = [];

    /** @var array|FilterStatementInterface[] */
    protected $_queryStatements = [];

    /** @var string */
    protected $_handle;

    /** @var array */
    protected $_options = [];

    /** @var string */
    protected $_feedback;

    /**
     * @var FilterInterface The next filter in this chain
     */
    protected $_nextFilter;

    use VisitableTrait;

    /**
     * @param $handle
     * @param FilterStatementInterface[] $statements
     * @param FilterInterface|null $nextFilter
     */
    public function __construct($handle, array $statements, FilterInterface $nextFilter = null) {

        if (is_null($nextFilter)) {
            $this->_nextFilter = new DummyFilter();
        } else {
            $this->_nextFilter = $nextFilter;
        }

        $this->_handle = $handle;
        $this->_statements = $statements;
    }

    /**
     * @return string[]
     */
    public function getFeedback() {
        return $this->_feedback;
    }

    /**
     * @param FilterInterface $filter
     * @return FilterInterface
     */
    public function combine(FilterInterface $filter) {
        $this->_nextFilter = $filter;
        return $this;
    }

    /**
     * @return string
     */
    public function getHandle() {
        return $this->_handle;
    }

    /**
     * @return null|FilterInterface
     */
    function getNextFilter() {
        return $this->_nextFilter;
    }

    /**
     * @return FilterStatement[]
     */
    public function getStatements() {
        return $this->_statements;
    }

    /**
     * @return FilterStatement[]
     */
    protected function getRowStatements() {
        $queryStatements = $this->_queryStatements;
        return array_filter(
            $this->_statements,
            function($statement) use ($queryStatements) {
                return array_search($statement, $queryStatements) === false;
            }
        );
    }

    /**
     * @param ModelCriteria $query
     * @return ModelCriteria
     */
    public function queryFilter(ModelCriteria $query) {
        $query = $this->getNextFilter()->queryFilter($query);

        $queryFilterBroken = false;

        if ($this->getNextFilter()->getRowStatements()) {
            $queryFilterBroken = true;
        }

        foreach ($this->_statements as $statement) {

            $fieldName = $statement->getFieldName();
            if ($fieldName && !ORMUtils::queryContainsFieldName($query, $fieldName)) {
                $queryFilterBroken = true;
            }

            if ($queryFilterBroken === false) {
                $this->setOptionsByQuery($query);
                $this->setFeedbackByQuery($query);
                $query = $statement->applyToQuery($query);

                $this->_queryStatements[] = $statement;
            }
        }
        return $query;
    }

    /**
     * @param ModelCriteria $query
     */
    protected function setOptionsByQuery(ModelCriteria $query) {
    }

    /**
     * @param ModelCriteria $query
     */
    protected function setFeedbackByQuery(ModelCriteria $query) {
    }

    /**
     * @param RowInterface[] $rows
     */
    protected function setOptionsByRows(array $rows) {
    }

    /**
     * @param RowInterface[] $rows
     * @return RowInterface[]
     */
    public function rowFilter(array $rows) {
        $this->setOptionsByRows($rows);

        echo sizeof($this->getRowStatements());

        $rows = $this->getNextFilter()->rowFilter($rows);
        foreach ($this->getRowStatements() as $statement) {<commit_msg>Remove echo statement.<commit_after><?php

namespace UWDOEM\Framework\Filter;

use Propel\Runtime\ActiveQuery\ModelCriteria;

use UWDOEM\Framework\Etc\ORMUtils;
use UWDOEM\Framework\Row\RowInterface;
use UWDOEM\Framework\FilterStatement\FilterStatementInterface;
use UWDOEM\Framework\Visitor\VisitableTrait;


class Filter implements FilterInterface {

    const TYPE_SEARCH = "search";
    const TYPE_SORT = "sort";
    const TYPE_SELECT = "select";
    const TYPE_STATIC = "static";
    const TYPE_PAGINATION = "pagination";

    /** @var array|FilterStatementInterface[] */
    protected $_statements = [];

    /** @var array|FilterStatementInterface[] */
    protected $_queryStatements = [];

    /** @var string */
    protected $_handle;

    /** @var array */
    protected $_options = [];

    /** @var string */
    protected $_feedback;

    /**
     * @var FilterInterface The next filter in this chain
     */
    protected $_nextFilter;

    use VisitableTrait;

    /**
     * @param $handle
     * @param FilterStatementInterface[] $statements
     * @param FilterInterface|null $nextFilter
     */
    public function __construct($handle, array $statements, FilterInterface $nextFilter = null) {

        if (is_null($nextFilter)) {
            $this->_nextFilter = new DummyFilter();
        } else {
            $this->_nextFilter = $nextFilter;
        }

        $this->_handle = $handle;
        $this->_statements = $statements;
    }

    /**
     * @return string[]
     */
    public function getFeedback() {
        return $this->_feedback;
    }

    /**
     * @param FilterInterface $filter
     * @return FilterInterface
     */
    public function combine(FilterInterface $filter) {
        $this->_nextFilter = $filter;
        return $this;
    }

    /**
     * @return string
     */
    public function getHandle() {
        return $this->_handle;
    }

    /**
     * @return null|FilterInterface
     */
    function getNextFilter() {
        return $this->_nextFilter;
    }

    /**
     * @return FilterStatement[]
     */
    public function getStatements() {
        return $this->_statements;
    }

    /**
     * @return FilterStatement[]
     */
    protected function getRowStatements() {
        $queryStatements = $this->_queryStatements;
        return array_filter(
            $this->_statements,
            function($statement) use ($queryStatements) {
                return array_search($statement, $queryStatements) === false;
            }
        );
    }

    /**
     * @param ModelCriteria $query
     * @return ModelCriteria
     */
    public function queryFilter(ModelCriteria $query) {
        $query = $this->getNextFilter()->queryFilter($query);

        $queryFilterBroken = false;

        if ($this->getNextFilter()->getRowStatements()) {
            $queryFilterBroken = true;
        }

        foreach ($this->_statements as $statement) {

            $fieldName = $statement->getFieldName();
            if ($fieldName && !ORMUtils::queryContainsFieldName($query, $fieldName)) {
                $queryFilterBroken = true;
            }

            if ($queryFilterBroken === false) {
                $this->setOptionsByQuery($query);
                $this->setFeedbackByQuery($query);
                $query = $statement->applyToQuery($query);

                $this->_queryStatements[] = $statement;
            }
        }
        return $query;
    }

    /**
     * @param ModelCriteria $query
     */
    protected function setOptionsByQuery(ModelCriteria $query) {
    }

    /**
     * @param ModelCriteria $query
     */
    protected function setFeedbackByQuery(ModelCriteria $query) {
    }

    /**
     * @param RowInterface[] $rows
     */
    protected function setOptionsByRows(array $rows) {
    }

    /**
     * @param RowInterface[] $rows
     * @return RowInterface[]
     */
    public function rowFilter(array $rows) {
        $this->setOptionsByRows($rows);

        $rows = $this->getNextFilter()->rowFilter($rows);
        foreach ($this->getRowStatements() as $statement) {
{'fraction_non_alphanumeric': 0.1269821907782386, 'fraction_numerical': 0.0, 'mean_word_length': 2.2665338645418327, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 54, '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': '3061144', 'n_tokens_mistral': 2292, 'n_tokens_neox': 2198, 'n_words': 456}