<commit_before><?php
namespace LazyRecord\CollectionFilter;
use Closure;
use Exception;

class CollectionFilter
{

    /**
     * constants for valid value type
     */
    const Integer  = 0;
    const String   = 1;
    const Boolean  = 2;
    const Float    = 3;
    const DateTime = 4;


    /**
     * constants for filter condition types
     */
    const Equal      = 0;
    const Greater    = 1;
    const Lesser     = 2;
    const Contains   = 3;
    const StartsWith = 4;
    const EndsWith   = 5;
    const InSet      = 6;
    const Range      = 7;


    public $collection;


    /**
     * @var LazyRecord\Schema the schema object
     */
    public $schema;

    /**
     * @var validValues contains field-to-definitions data structure:
     *
     *    "field_name" => [ 1,2,3,4 ]
     *    "field_name" => [ "foo", "bar" ]
     *    "field_name" => [ "label" => 1, "label2" => 2]
     */
    public $validValues = array();

    public $validFields = array();

    public function __construct($collection) {
        $this->collection = $collection;
        $this->schema = $collection->getSchema();
    }

    public function setCollection($c) {
        $this->collection = $c;
    }

    public function getCollection($c) {
        return $this->collection;
    }

    public function defineEqual($fieldName, $validValues = null) {
        $this->validFields[$fieldName] = self::Equal;
        if ( $validValues ) {
            $this->validValues[$fieldName] = $validValues;
        }
    }

    public function defineRange($field, $validValues = null) {
        $this->validFields[$field] = self::Range;
        if ( $validValues ) {
            $this->validValues[$field] = $validValues;
        }
    }

    public function defineContains($field) {
        $this->validFields[$field] = self::Contains;
        $this->validValues[$field] = self::String;
    }

    public function defineStartsWith($field) {
        $this->validFields[$field] = self::StartsWith;
        $this->validValues[$field] = self::String;
    }

    public function defineEndsWith($field) {
        $this->validFields[$field] = self::EndsWith;
        $this->validValues[$field] = self::String;
    }

    public function defineInSet($field, $validValues = null) {
        $this->validFields[$field] = self::InSet;
        if ( $validValues ) {
            $this->validValues[$field] = $validValues;
        }
    }


    public function validateValue($validValues, & $val) {
        if ( is_array($validValues) ) {
            if ( isset($validValues[0]) ) {<commit_msg>when using defineInSet, validValues is a requirement.<commit_after><?php
namespace LazyRecord\CollectionFilter;
use Closure;
use Exception;

class CollectionFilter
{

    /**
     * constants for valid value type
     */
    const Integer  = 0;
    const String   = 1;
    const Boolean  = 2;
    const Float    = 3;
    const DateTime = 4;


    /**
     * constants for filter condition types
     */
    const Equal      = 0;
    const Greater    = 1;
    const Lesser     = 2;
    const Contains   = 3;
    const StartsWith = 4;
    const EndsWith   = 5;
    const InSet      = 6;
    const Range      = 7;


    public $collection;


    /**
     * @var LazyRecord\Schema the schema object
     */
    public $schema;

    /**
     * @var validValues contains field-to-definitions data structure:
     *
     *    "field_name" => [ 1,2,3,4 ]
     *    "field_name" => [ "foo", "bar" ]
     *    "field_name" => [ "label" => 1, "label2" => 2]
     */
    public $validValues = array();

    public $validFields = array();

    public function __construct($collection) {
        $this->collection = $collection;
        $this->schema = $collection->getSchema();
    }

    public function setCollection($c) {
        $this->collection = $c;
    }

    public function getCollection($c) {
        return $this->collection;
    }

    public function defineEqual($fieldName, $validValues = null) {
        $this->validFields[$fieldName] = self::Equal;
        if ( $validValues ) {
            $this->validValues[$fieldName] = $validValues;
        }
    }

    public function defineRange($field, $validValues = null) {
        $this->validFields[$field] = self::Range;
        if ( $validValues ) {
            $this->validValues[$field] = $validValues;
        }
    }

    public function defineContains($field) {
        $this->validFields[$field] = self::Contains;
        $this->validValues[$field] = self::String;
    }

    public function defineStartsWith($field) {
        $this->validFields[$field] = self::StartsWith;
        $this->validValues[$field] = self::String;
    }

    public function defineEndsWith($field) {
        $this->validFields[$field] = self::EndsWith;
        $this->validValues[$field] = self::String;
    }

    public function defineInSet($field, $validValues) {
        $this->validFields[$field] = self::InSet;
        $this->validValues[$field] = $validValues;
    }


    public function validateValue($validValues, & $val) {
        if ( is_array($validValues) ) {
            if ( isset($validValues[0]) ) {
{'fraction_non_alphanumeric': 0.13685239491691104, 'fraction_numerical': 0.008211143695014663, 'mean_word_length': 2.3006451612903227, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 47, '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': '6340703', 'n_tokens_mistral': 1567, 'n_tokens_neox': 1504, 'n_words': 339}