CompositeSpecification::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 1
1
<?php
2
3
declare(strict_types = 1);
4
5
namespace Larium\Specification;
6
7
class CompositeSpecification extends LeafSpecification
8
{
9
    private $specifications = [];
10
11 3
    public function __construct(Specification ...$specifications)
12
    {
13 3
        $this->specifications = $specifications;
14 3
    }
15
16 3
    public function isSatisfiedBy(Candidate $candidate): bool
17
    {
18 3
        foreach ($this->specifications as $specification) {
19 3
            if ($specification->isSatisfiedBy($candidate) === false) {
20 3
                return false;
21
            }
22
        }
23
24 2
        return true;
25
    }
26
27 1
    public function remainderUnsatisfiedBy(Candidate $candidate): ?Specification
28
    {
29 1
        if ($this->isSatisfiedBy($candidate)) {
30
            return null;
31
        }
32
33 1
        $unsatisfied = [];
34 1
        foreach ($this->specifications as $specification) {
35 1
            if (!$specification->isSatisfiedBy($candidate)) {
36 1
                $unsatisfied[] = $specification;
37
            }
38
        }
39
40 1
        return new static(...$unsatisfied);
41
    }
42
}
43