CompositeSpecification   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 93.75%

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 1
dl 0
loc 36
ccs 15
cts 16
cp 0.9375
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A isSatisfiedBy() 0 10 3
A remainderUnsatisfiedBy() 0 15 4
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