<commit_before><?php
/**
 * Zend Framework (http://framework.zend.com/)
 *
 * @link      http://github.com/zendframework/zf2 for the canonical source repository
 * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
 * @license   http://framework.zend.com/license/new-bsd New BSD License
 * @package   Zend_Validator
 */

namespace Zend\Validator;

use RecursiveArrayIterator;
use RecursiveIteratorIterator;

/**
 * @category Zend
 * @package  Zend_Validate
 */
class InArray extends AbstractValidator
{
    const NOT_IN_ARRAY = 'notInArray';

    /**
     * @var array
     */
    protected $messageTemplates = array(
        self::NOT_IN_ARRAY => 'The input was not found in the haystack',
    );

    /**
     * Haystack of possible values
     *
     * @var array
     */
    protected $haystack;

    /**
     * Whether a strict in_array() invocation is used
     *
     * @var boolean
     */
    protected $strict = false;

    /**
     * Whether a recursive search should be done
     *
     * @var boolean
     */
    protected $recursive = false;

    /**
     * Returns the haystack option
     *
     * @return mixed
     * @throws Exception\RuntimeException if haystack option is not set
     */
    public function getHaystack()
    {
        if ($this->haystack == null) {
            throw new Exception\RuntimeException('haystack option is mandatory');
        }
        return $this->haystack;
    }

    /**
     * Sets the haystack option
     *
     * @param  mixed $haystack
     * @return InArray Provides a fluent interface
     */
    public function setHaystack(array $haystack)
    {
        $this->haystack = $haystack;
        return $this;
    }

    /**
     * Returns the strict option
     *
     * @return boolean
     */
    public function getStrict()
    {
        return $this->strict;
    }

    /**
     * Sets the strict option
     *
     * @param  boolean $strict
     * @return InArray Provides a fluent interface
     */
    public function setStrict($strict)
    {
        $this->strict = (boolean) $strict;
        return $this;
    }

    /**
     * Returns the recursive option
     *
     * @return boolean
     */
    public function getRecursive()
    {
        return $this->recursive;
    }

    /**
     * Sets the recursive option
     *
     * @param  boolean $recursive
     * @return InArray Provides a fluent interface
     */
    public function setRecursive($recursive)
    {
        $this->recursive = (boolean) $recursive;
        return $this;
    }

    /**
     * Returns true if and only if $value is contained in the haystack option. If the strict
     * option is true, then the type of $value is also checked.
     *
     * @param  mixed $value
     * @throws Exception\RuntimeException If 0 is present in the haystack and strict mode is disabled.
     * See {@link http://php.net/manual/function.in-array.php#104501}
     * @return boolean
     */
    public function isValid($value)
    {
        if (!$this->strict && in_array(0, $this->getHaystack(), true)) {
            // Strings are treated as 0 integer by PHP
            // ZF2-337 http://php.net/manual/function.in-array.php#104501
            throw new Exception\RuntimeException('Comparisons with 0 are only possible in strict mode');
        }

        $this->setValue($value);
        if ($this->getRecursive()) {
            $iterator = new RecursiveIteratorIterator(new RecursiveArrayIterator($this->getHaystack()));
            foreach ($iterator as $element) {
                if ($this->strict) {
                    if ($element === $value) {
                        return true;
                    }
                } elseif ($element == $value) {
                    return true;
                }
            }
        } else {
            if (in_array($value, $this->getHaystack(), $this->strict)) {
                return true;
            }
        }

        $this->error(self::NOT_IN_ARRAY);
        return false;
    }
}<commit_msg>isValid cannot force strict if ints appear in haystack, as comparing 0 against array(0,1) becomes impossible.<commit_after><?php
/**
 * Zend Framework (http://framework.zend.com/)
 *
 * @link      http://github.com/zendframework/zf2 for the canonical source repository
 * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
 * @license   http://framework.zend.com/license/new-bsd New BSD License
 * @package   Zend_Validator
 */

namespace Zend\Validator;

use RecursiveArrayIterator;
use RecursiveIteratorIterator;

/**
 * @category Zend
 * @package  Zend_Validate
 */
class InArray extends AbstractValidator
{
    const NOT_IN_ARRAY = 'notInArray';

    /**
     * @var array
     */
    protected $messageTemplates = array(
        self::NOT_IN_ARRAY => 'The input was not found in the haystack',
    );

    /**
     * Haystack of possible values
     *
     * @var array
     */
    protected $haystack;

    /**
     * Whether a strict in_array() invocation is used
     *
     * @var boolean
     */
    protected $strict = false;

    /**
     * Whether a recursive search should be done
     *
     * @var boolean
     */
    protected $recursive = false;

    /**
     * Returns the haystack option
     *
     * @return mixed
     * @throws Exception\RuntimeException if haystack option is not set
     */
    public function getHaystack()
    {
        if ($this->haystack == null) {
            throw new Exception\RuntimeException('haystack option is mandatory');
        }
        return $this->haystack;
    }

    /**
     * Sets the haystack option
     *
     * @param  mixed $haystack
     * @return InArray Provides a fluent interface
     */
    public function setHaystack(array $haystack)
    {
        $this->haystack = $haystack;
        return $this;
    }

    /**
     * Returns the strict option
     *
     * @return boolean
     */
    public function getStrict()
    {
        return $this->strict;
    }

    /**
     * Sets the strict option
     *
     * @param  boolean $strict
     * @return InArray Provides a fluent interface
     */
    public function setStrict($strict)
    {
        $this->strict = (boolean) $strict;
        return $this;
    }

    /**
     * Returns the recursive option
     *
     * @return boolean
     */
    public function getRecursive()
    {
        return $this->recursive;
    }

    /**
     * Sets the recursive option
     *
     * @param  boolean $recursive
     * @return InArray Provides a fluent interface
     */
    public function setRecursive($recursive)
    {
        $this->recursive = (boolean) $recursive;
        return $this;
    }

    /**
     * Returns true if and only if $value is contained in the haystack option. If the strict
     * option is true, then the type of $value is also checked.
     *
     * @param  mixed $value
     * @throws Exception\RuntimeException If 0 is present in the haystack and strict mode is disabled.
     * See {@link http://php.net/manual/function.in-array.php#104501}
     * @return boolean
     */
    public function isValid($value)
    {
        $this->setValue($value);
        if ($this->getRecursive()) {
            $iterator = new RecursiveIteratorIterator(new RecursiveArrayIterator($this->getHaystack()));
            foreach ($iterator as $element) {
                if ($this->strict) {
                    if ($element === $value) {
                        return true;
                    }
                } elseif ($element == $value) {
                    return true;
                }
            }
        } else {
            if (in_array($value, $this->getHaystack(), $this->strict)) {
                return true;
            }
        }

        $this->error(self::NOT_IN_ARRAY);
        return false;
    }
}
{'fraction_non_alphanumeric': 0.10973111395646606, 'fraction_numerical': 0.006145966709346991, 'mean_word_length': 1.9004827330115113, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 35, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '2117822', 'n_tokens_mistral': 2291, 'n_tokens_neox': 2166, 'n_words': 618}