<commit_before><?php

class Chequer {

    protected $query;
    protected $matchAll;
    protected $lookInsideArray;
    
    /**
     * @param $query Default query
     * @param $matchAll Default matchAll
     * @param $lookInsideArray Enable searching for subkey in arrays
     */
    function __construct($query = false, $matchAll = null, $lookInsideArray = true) {
        $this->query = $query;
        $this->matchAll = $matchAll;
        $this->lookInsideArray = $lookInsideArray;
    }

    public function getQuery() {
        return $this->query;
    }


    public function setQuery( $query ) {
        $this->query = $query;
    }


    public function getLookInsideArray() {
        return $this->lookInsideArray;
    }


    public function setLookInsideArray( $lookInsideArray ) {
        $this->lookInsideArray = $lookInsideArray;
    }


    public function getMatchAll() {
        return $this->matchAll;
    }


    public function setMatchAll( $matchAll ) {
        $this->matchAll = $matchAll;
    }


    /** Checks rules against current server environment. 
     * Available keys are everything from $_SERVER, _ENV, _COOKIE, _SESSION, _GET, _POST, _REQUEST.
     * 
     *  */
    public static function checkEnvironment($query, $matchAll = true) {
        $ch = new Chequer;
        $table = array(
            $_SERVER, 
            '_SERVER' => $_SERVER,
            '_ENV' => $_ENV,
            '_COOKIE' => $_COOKIE,
            '_SESSION' => $_SESSION,
            '_GET' => $_GET,
            '_POST' => $_POST,
            '_REQUEST' => $_REQUEST,
        );
        
        return $ch->query($table, $query, $matchAll);
    }
    
    public static function checkValue($value, $query, $matchAll = null) {
        $ch = new static;
        return $ch->query($value, $query, $matchAll);
    }
    
    public function __invoke($value) {
        return $this->check($value);
    }
    
    /** Checks the value against the instance's query
     * 
     * See Readme.md for documentation
     */
    public function check($value) {
        return $this->query($value, $this->query, $this->matchAll);
    }
    
    /** Checks the value against provided query
     * 
     * See Readme.md for documentation
     * 
     * @param $value Value to check
     * @param $query Query to match
     * @param $matchAll TRUE to require all first level queries, FALSE to require only one
     *  */
    public function query($value, $query, $matchAll = null) {
        if ($query === null || $query === false) {
            return $value === $query;
        } elseif (is_scalar($query)) {
            if (is_array($value) && is_bool($query) == false) {
                return in_array($query, $value);
            } else {
                return $value == $query;
            }
        } elseif (is_object($query) && is_callable($query)) {
            return call_user_func($query, $value, $query, $matchAll);
        } else {
            if ($matchAll === null) $matchAll = false === (isset($query[0]) && is_scalar($query[0]));
            foreach($query as $key => $rule) {
                $result = null;
                if (is_int($key)) {
                    $result = $this->query($value, $rule);<commit_msg>query accepts Chequer as query<commit_after><?php

class Chequer {

    protected $query;
    protected $matchAll;
    protected $lookInsideArray;
    
    /**
     * @param $query Default query
     * @param $matchAll Default matchAll
     * @param $lookInsideArray Enable searching for subkey in arrays
     */
    function __construct($query = false, $matchAll = null, $lookInsideArray = true) {
        $this->query = $query;
        $this->matchAll = $matchAll;
        $this->lookInsideArray = $lookInsideArray;
    }

    public function getQuery() {
        return $this->query;
    }


    public function setQuery( $query ) {
        $this->query = $query;
    }


    public function getLookInsideArray() {
        return $this->lookInsideArray;
    }


    public function setLookInsideArray( $lookInsideArray ) {
        $this->lookInsideArray = $lookInsideArray;
    }


    public function getMatchAll() {
        return $this->matchAll;
    }


    public function setMatchAll( $matchAll ) {
        $this->matchAll = $matchAll;
    }


    /** Checks rules against current server environment. 
     * Available keys are everything from $_SERVER, _ENV, _COOKIE, _SESSION, _GET, _POST, _REQUEST.
     * 
     *  */
    public static function checkEnvironment($query, $matchAll = true) {
        $ch = new Chequer($query, $matchAll);
        $table = array(
            $_SERVER, 
            '_SERVER' => $_SERVER,
            '_ENV' => $_ENV,
            '_COOKIE' => $_COOKIE,
            '_SESSION' => $_SESSION,
            '_GET' => $_GET,
            '_POST' => $_POST,
            '_REQUEST' => $_REQUEST,
        );
        return $ch->check($table);
    }
    
    public static function checkValue($value, $query, $matchAll = null) {
        $ch = new static($query, $matchAll);
        return $ch->check($value);
    }
    
    public function __invoke($value) {
        return $this->check($value);
    }
    
    /** Checks the value against the instance's query
     * 
     * See Readme.md for documentation
     */
    public function check($value, $matchAll = null) {
        return $this->query($value, $this->query, $matchAll === null ? $this->matchAll : $matchAll);
    }
    
    /** Checks the value against provided query
     * 
     * See Readme.md for documentation
     * 
     * @param $value Value to check
     * @param $query Query to match
     * @param $matchAll TRUE to require all first level queries, FALSE to require only one
     *  */
    public function query($value, $query, $matchAll = null) {
        if ($query === null || $query === false) {
            return $value === $query;
        } elseif (is_scalar($query)) {
            if (is_array($value) && is_bool($query) == false) {
                return in_array($query, $value);
            } else {
                return $value == $query;
            }
        } elseif (is_object($query) && is_callable($query)) {
            if ($query instanceof Chequer) return $query->check($value, $matchAll);
            return call_user_func($query, $value, $query, $matchAll);
        } else {
            if ($matchAll === null) $matchAll = false === (isset($query[0]) && is_scalar($query[0]));
            foreach($query as $key => $rule) {
                $result = null;
                if (is_int($key)) {
                    $result = $this->query($value, $rule);
{'fraction_non_alphanumeric': 0.13254652746255108, 'fraction_numerical': 0.0006052352852171282, 'mean_word_length': 2.0672853828306264, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 52, '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': '3038820', 'n_tokens_mistral': 1929, 'n_tokens_neox': 1860, 'n_words': 501}