<commit_before><?php

/**
 * This file is part of the Valit package.
 *
 * @author <NAME> <<EMAIL>>
 * @copyright 2018
 * @license MIT
 */

namespace Valit\Providers;

use Valit\Util\Val;
use Valit\Result\AssertionResult;
use Valit\Contracts\CheckProvider;
use Valit\Traits\ProvideViaReflection;

class BasicCheckProvider implements CheckProvider
{
    use ProvideViaReflection;

    /**
     * Check that $value === $against.
     *
     * @Check(["isIdenticalTo", "identicalTo", "sameAs", "isSameAs"])
     *
     * @param mixed $value
     * @param mixed $against
     *
     * @return AssertionResult
     */
    public function checkIdenticalTo($value, $against)
    {
        return new AssertionResult($value === $against, '{name} must be identical to {0}', [$against]);
    }

    /**
     * Check that $value == $against (loose comparison).
     *
     * Examples:
     *
     * | $value     | $equals       | Valid     |
     * |:-----------|:--------------|:----------|
     * | true       | true          | yes       |
     * | true       | 1             | yes       |
     * | "true"     | 1             | no        |
     * | "true"     | true          | yes       |
     * | "true"     | "foo"         | no        |
     * | "1"        | true          | yes       |
     * | "1"        | 1             | yes       |
     * | "1"        | "foo"         | no        |
     * | "0"        | true          | no        |
     * | "0"        | false         | yes       |
     * | "0"        | 0             | yes       |
     *
     * @Check(["is", "equals"])
     *
     * @param mixed $value
     * @param mixed $equals
     *
     * @return AssertionResult
     */
    public function checkEquals($value, $equals)
    {
        return new AssertionResult($value == $equals, '{name} must equal {0}', [$equals]);
    }

    /**
     * Check that $value is equal to (==) one of the values in $allowedValues.
     *
     * If you give multiple arguments to this function, each argument will
     * be treated as a possible option.
     * If you give only one argument to this function, then that argument must
     * be iterable (array or Traversable). The entries in that variable will
     * be treated as the options allowed.
     *
     * Code examples:
     *
     * ```php
     * // Check that $foo is either 'foo' or 'bar'
     * Check::that($foo)->isOneOf('foo', 'bar');
     * Check::that($foo)->isOneOf(['foo', 'bar']);
     *
     * // Check that $foo is either ['a', 'b'] or ['c', 'd']
     * Check::that($foo)->isOneOf(['a', 'b'], ['c', 'd']);
     * Check::that($foo)->isOneOf([ ['a', 'b'], ['c', 'd'] ]);
     * ```
     *
     * ---
     *
     * @Check(["isOneOf", "oneOf"])
     *
     * @param mixed            $value
     * @param mixed[]|iterable $allowedValues,... The allowed values
     *
     * @return AssertionResult
     */
    public function checkIsOneOf($value, $allowedValues)
    {
        // If $allowedValues is variadic instead of array
        if (func_num_args() > 2) {
            $allowedValues = array_slice(func_get_args(), 1);
        }

        Val::mustBe($allowedValues, 'iterable');

        $msg = '{name} must be one of {0:imploded}';

        foreach ($allowedValues as $match) {
            if ($value == $match) {
                return new AssertionResult(true, $msg, [$allowedValues]);
            }
        }

        return new AssertionResult(false, $msg, [$allowedValues]);
    }

    /**
     * Check that $value is NOT equal to (==) any of the values in $unacceptableValues.
     *
     * See isOneOf() for examples.
     *
     * @Check(["isNotOneOf", "notOneOf"])
     *
     * @param mixed            $value
     * @param mixed[]|iterable $unacceptableValues
     *
     * @return AssertionResult
     */
    public function checkIsNotOneOf($value, $unacceptableValues)
    {
        // If $unacceptableValues is variadic instead of array
        if (func_num_args() > 2) {
            $unacceptableValues = array_slice(func_get_args(), 1);
        }

        Val::mustBe($unacceptableValues, 'iterable');

        $msg = '{name} must be one of {0:imploded}';

        foreach ($unacceptableValues as $match) {
            if ($value == $match) {
                return new AssertionResult(false, $msg, [$unacceptableValues]);<commit_msg>FIX checkIsOneOf to match the documented behavior.<commit_after><?php

/**
 * This file is part of the Valit package.
 *
 * @author <NAME> <<EMAIL>>
 * @copyright 2018
 * @license MIT
 */

namespace Valit\Providers;

use Valit\Util\Val;
use Valit\Result\AssertionResult;
use Valit\Contracts\CheckProvider;
use Valit\Traits\ProvideViaReflection;

class BasicCheckProvider implements CheckProvider
{
    use ProvideViaReflection;

    /**
     * Check that $value === $against.
     *
     * @Check(["isIdenticalTo", "identicalTo", "sameAs", "isSameAs"])
     *
     * @param mixed $value
     * @param mixed $against
     *
     * @return AssertionResult
     */
    public function checkIdenticalTo($value, $against)
    {
        return new AssertionResult($value === $against, '{name} must be identical to {0}', [$against]);
    }

    /**
     * Check that $value == $against (loose comparison).
     *
     * Examples:
     *
     * | $value     | $equals       | Valid     |
     * |:-----------|:--------------|:----------|
     * | true       | true          | yes       |
     * | true       | 1             | yes       |
     * | "true"     | 1             | no        |
     * | "true"     | true          | yes       |
     * | "true"     | "foo"         | no        |
     * | "1"        | true          | yes       |
     * | "1"        | 1             | yes       |
     * | "1"        | "foo"         | no        |
     * | "0"        | true          | no        |
     * | "0"        | false         | yes       |
     * | "0"        | 0             | yes       |
     *
     * @Check(["is", "equals"])
     *
     * @param mixed $value
     * @param mixed $equals
     *
     * @return AssertionResult
     */
    public function checkEquals($value, $equals)
    {
        return new AssertionResult($value == $equals, '{name} must equal {0}', [$equals]);
    }

    /**
     * Check that $value is equal to (==) one of the values in $allowedValues.
     *
     * If you give multiple arguments to this function, each argument will
     * be treated as a possible option.
     * If you give only one argument to this function, then that argument must
     * be iterable (array or Traversable). The entries in that variable will
     * be treated as the options allowed.
     *
     * Code examples:
     *
     * ```php
     * // Check that $foo is either 'foo' or 'bar'
     * Check::that($foo)->isOneOf('foo', 'bar');
     * Check::that($foo)->isOneOf(['foo', 'bar']);
     *
     * // Check that $foo is either ['a', 'b'] or ['c', 'd']
     * Check::that($foo)->isOneOf(['a', 'b'], ['c', 'd']);
     * Check::that($foo)->isOneOf([ ['a', 'b'], ['c', 'd'] ]);
     * ```
     *
     * ---
     *
     * @Check(["isOneOf", "oneOf"])
     *
     * @param mixed            $value
     * @param mixed[]|iterable $allowedValues,... The allowed values
     *
     * @return AssertionResult
     */
    public function checkIsOneOf($value, $allowedValues)
    {
        // If $allowedValues is variadic instead of array
        if (! (func_num_args() === 2 && is_array($allowedValues))) {
            $allowedValues = array_slice(func_get_args(), 1);
        }

        Val::mustBe($allowedValues, 'array');

        return new AssertionResult(
            in_array($value, $allowedValues),
            '{name} must be one of {0:imploded}',
            [$allowedValues]
        );
    }

    /**
     * Check that $value is NOT equal to (==) any of the values in $unacceptableValues.
     *
     * See isOneOf() for examples.
     *
     * @Check(["isNotOneOf", "notOneOf"])
     *
     * @param mixed            $value
     * @param mixed[]|iterable $unacceptableValues
     *
     * @return AssertionResult
     */
    public function checkIsNotOneOf($value, $unacceptableValues)
    {
        // If $unacceptableValues is variadic instead of array
        if (func_num_args() > 2) {
            $unacceptableValues = array_slice(func_get_args(), 1);
        }

        Val::mustBe($unacceptableValues, 'iterable');

        $msg = '{name} must be one of {0:imploded}';

        foreach ($unacceptableValues as $match) {
            if ($value == $match) {
                return new AssertionResult(false, $msg, [$unacceptableValues]);
{'fraction_non_alphanumeric': 0.15480780465007593, 'fraction_numerical': 0.005140787475172333, 'mean_word_length': 1.7846454131424854, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 20, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3814733', 'n_tokens_mistral': 2633, 'n_tokens_neox': 2554, 'n_words': 680}