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
/**
13
 * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit
14
 */
15
abstract class Operator extends Constraint
16
{
17
    /**
18
     * Returns the name of this operator.
19
     */
20
    abstract public function operator(): string;
21
 
22
    /**
23
     * Returns this operator's precedence.
24
     *
25
     * @see https://www.php.net/manual/en/language.operators.precedence.php
26
     */
27
    abstract public function precedence(): int;
28
 
29
    /**
30
     * Returns the number of operands.
31
     */
32
    abstract public function arity(): int;
33
 
34
    /**
35
     * Validates $constraint argument.
36
     */
37
    protected function checkConstraint($constraint): Constraint
38
    {
39
        if (!$constraint instanceof Constraint) {
40
            return new IsEqual($constraint);
41
        }
42
 
43
        return $constraint;
44
    }
45
 
46
    /**
47
     * Returns true if the $constraint needs to be wrapped with braces.
48
     */
49
    protected function constraintNeedsParentheses(Constraint $constraint): bool
50
    {
51
        return $constraint instanceof self &&
52
               $constraint->arity() > 1 &&
53
               $this->precedence() <= $constraint->precedence();
54
    }
55
}