ValueBoundSpecification   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 96.15%

Importance

Changes 0
Metric Value
wmc 10
lcom 1
cbo 1
dl 0
loc 62
ccs 25
cts 26
cp 0.9615
rs 10
c 0
b 0
f 0

8 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A getAttribute() 0 4 1
A getValue() 0 4 1
A isGeneralizationOf() 0 4 1
A isSpecialCaseOf() 0 4 1
A subsumptionProcess() 0 14 3
A getBaseNameOfParentClasses() 0 7 1
A getClassBaseName() 0 6 1
1
<?php
2
3
declare(strict_types = 1);
4
5
namespace Larium\Specification;
6
7
abstract class ValueBoundSpecification extends LeafSpecification
8
{
9
    private $attribute;
10
11
    private $value;
12
13 5
    public function __construct(string $attribute, $value)
14
    {
15 5
        $this->attribute = $attribute;
16 5
        $this->value = $value;
17 5
    }
18
19 5
    public function getAttribute()
20
    {
21 5
        return $this->attribute;
22
    }
23
24 5
    public function getValue()
25
    {
26 5
        return $this->value;
27
    }
28
29 1
    public function isGeneralizationOf(ValueBoundSpecification $specification): bool
30
    {
31 1
        return $this->subsumptionProcess('isGeneralizationOf', $specification);
32
    }
33
34 2
    public function isSpecialCaseOf(ValueBoundSpecification $specification): bool
35
    {
36 2
        return $this->subsumptionProcess('isSpecialCaseOf', $specification);
37
    }
38
39 3
    private function subsumptionProcess(string $type, ValueBoundSpecification $specification): bool
40
    {
41 3
        $parentClasses = $this->getBaseNameOfParentClasses(get_class($specification));
42
43 3
        foreach ($parentClasses as $name) {
44 3
            $method = sprintf('%s%s', $type, $name);
45
46 3
            if (is_callable([$this, $method])) {
47 3
                return $this->$method($specification);
48
            }
49
        }
50
51
        return false;
52
    }
53
54 3
    private function getBaseNameOfParentClasses(string $specificationClass): array
55
    {
56 3
        $parents = class_parents($specificationClass);
57 3
        array_unshift($parents, $this->getClassBaseName($specificationClass));
58
59 3
        return array_map([$this, 'getClassBaseName'], $parents);
60
    }
61
62 3
    private function getClassBaseName(string $className): string
63
    {
64 3
        $parts = explode('\\', $className);
65
66 3
        return end($parts);
67
    }
68
}
69