Subversion-Projekte lars-tiefland.laravel_shop

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
148 lars 1
<?php declare(strict_types=1);
2
/*
3
 * This file is part of PHPUnit.
4
 *
5
 * (c) Sebastian Bergmann <sebastian@phpunit.de>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
namespace PHPUnit\Framework\Constraint;
11
 
12
use function array_reduce;
13
use function array_shift;
14
 
15
/**
16
 * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit
17
 */
18
final class LogicalXor extends BinaryOperator
19
{
20
    /**
21
     * Returns the name of this operator.
22
     */
23
    public function operator(): string
24
    {
25
        return 'xor';
26
    }
27
 
28
    /**
29
     * Returns this operator's precedence.
30
     *
31
     * @see https://www.php.net/manual/en/language.operators.precedence.php.
32
     */
33
    public function precedence(): int
34
    {
35
        return 23;
36
    }
37
 
38
    /**
39
     * Evaluates the constraint for parameter $other. Returns true if the
40
     * constraint is met, false otherwise.
41
     *
42
     * @param mixed $other value or object to evaluate
43
     */
44
    public function matches($other): bool
45
    {
46
        $constraints = $this->constraints();
47
 
48
        $initial = array_shift($constraints);
49
 
50
        if ($initial === null) {
51
            return false;
52
        }
53
 
54
        return array_reduce(
55
            $constraints,
56
            static function (bool $matches, Constraint $constraint) use ($other): bool
57
            {
58
                return $matches xor $constraint->evaluate($other, '', true);
59
            },
60
            $initial->evaluate($other, '', true)
61
        );
62
    }
63
}