Completed
Push — master ( 41783b...5d96ba )
by BENOIT
02:49
created

OrSpecification::callErrorCallback()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 7
nc 4
nop 1
dl 0
loc 12
rs 9.2
c 0
b 0
f 0
1
<?php
2
3
namespace BenTools\Specification\Logical;
4
5
use BenTools\Specification\Specification;
6
use BenTools\Specification\SpecificationInterface;
7
8
class OrSpecification extends Specification
9
{
10
11
    const LEFT_SPEC = 'left';
12
    const RIGHT_SPEC = 'right';
13
14
    /**
15
     * @var SpecificationInterface
16
     */
17
    private $leftSpecification;
18
19
    /**
20
     * @var SpecificationInterface
21
     */
22
    private $rightSpecification;
23
24
    /**
25
     * @var string
26
     */
27
    private $unmetSpecification;
28
29
    /**
30
     * AndSpecification constructor.
31
     *
32
     * @param SpecificationInterface $leftSpecification
33
     * @param SpecificationInterface $rightSpecification
34
     */
35
    public function __construct(SpecificationInterface $leftSpecification, SpecificationInterface $rightSpecification)
36
    {
37
        $this->leftSpecification  = $leftSpecification;
38
        $this->rightSpecification = $rightSpecification;
39
    }
40
41
    /**
42
     * @inheritDoc
43
     */
44
    public function callErrorCallback($cascade = false): void
45
    {
46
        parent::callErrorCallback();
47
48
        if (true === $cascade) {
49
            if (self::LEFT_SPEC === $this->unmetSpecification) {
50
                $this->leftSpecification->callErrorCallback($cascade);
0 ignored issues
show
Unused Code introduced by
The call to SpecificationInterface::callErrorCallback() has too many arguments starting with $cascade.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
51
            } elseif (self::RIGHT_SPEC === $this->unmetSpecification) {
52
                $this->rightSpecification->callErrorCallback($cascade);
0 ignored issues
show
Unused Code introduced by
The call to SpecificationInterface::callErrorCallback() has too many arguments starting with $cascade.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
53
            }
54
        }
55
    }
56
57
    /**
58
     * @inheritDoc
59
     */
60
    public function __invoke(): bool
61
    {
62
        $leftSpecification = $this->leftSpecification;
63
        $rightSpecification = $this->rightSpecification;
64
        if (true !== $leftSpecification()) {
65
            $this->unmetSpecification = self::LEFT_SPEC;
66
        } else {
67
            return true;
68
        }
69
        if (true !== $rightSpecification()) {
70
            if (null === $this->unmetSpecification) {
71
                $this->unmetSpecification = self::RIGHT_SPEC;
72
            }
73
        } else {
74
            return true;
75
        }
76
        return false;
77
    }
78
}
79