Completed
Push — master ( e1173d...cdf0e4 )
by Oskar
05:16 queued 03:02
created

StableAbstractionsPrinciple   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 39
rs 10
c 0
b 0
f 0
wmc 7
lcom 1
cbo 1

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getName() 0 4 1
A apply() 0 10 3
A getLevel() 0 4 1
A getDescription() 0 12 2
1
<?php
2
3
namespace Hal\Violation\Package;
4
5
use Hal\Metric\Metric;
6
use Hal\Metric\PackageMetric;
7
use Hal\Violation\Violation;
8
9
class StableAbstractionsPrinciple implements Violation
10
{
11
    /** @var PackageMetric|null */
12
    private $metric;
13
14
    public function getName()
15
    {
16
        return 'Stable Abstractions Principle';
17
    }
18
19
    public function apply(Metric $metric)
20
    {
21
        if (! $metric instanceof PackageMetric) {
22
            return;
23
        }
24
        if (abs($metric->getDistance()) > sqrt(2)/4) {
25
            $this->metric = $metric;
26
            $metric->get('violations')->add($this);
0 ignored issues
show
Bug introduced by
The method add cannot be called on $metric->get('violations') (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
27
        }
28
    }
29
30
    public function getLevel()
31
    {
32
        return Violation::WARNING;
33
    }
34
35
    public function getDescription()
36
    {
37
        $violation = $this->metric->getDistance() > 0
38
            ? 'instable and abstract'
39
            : 'stable and concrete';
40
41
        return <<<EOT
42
Packages should be either abstract and stable or concrete and instable.
43
44
This package is {$violation}.
45
EOT;
46
    }
47
}
48