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

PackageMetric::addOutgoingClassDependency()   A

Complexity

Conditions 4
Paths 5

Size

Total Lines 17
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 11
c 0
b 0
f 0
nc 5
nop 2
dl 0
loc 17
rs 9.2
1
<?php
2
3
namespace Hal\Metric;
4
5
use JsonSerializable;
6
7
class PackageMetric implements Metric, JsonSerializable
8
{
9
    use BagTrait;
10
11
    /** @return string[] */
12
    public function getClasses()
13
    {
14
        return $this->has('classes') ? $this->get('classes') : [];
15
    }
16
17
    /** @param string $name */
18
    public function addClass($name)
19
    {
20
        $elements = $this->get('classes');
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $elements is correct as $this->get('classes') (which targets Hal\Metric\BagTrait::get()) seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
21
        $elements[] = (string) $name;
22
        $this->set('classes', $elements);
23
    }
24
25
    /** @param float $abstraction */
26
    public function setAbstraction($abstraction)
27
    {
28
        if ($abstraction !== null) {
29
            $abstraction = (float) $abstraction;
30
        }
31
        $this->set('abstraction', $abstraction);
32
    }
33
34
    /** @return float|null */
35
    public function getAbstraction()
36
    {
37
        return $this->get('abstraction');
38
    }
39
40
    /** @param float $instability */
41
    public function setInstability($instability)
42
    {
43
        if ($instability !== null) {
44
            $instability = (float) $instability;
45
        }
46
        $this->set('instability', $instability);
47
    }
48
49
    /** @return float|null */
50
    public function getInstability()
51
    {
52
        return $this->get('instability');
53
    }
54
55
    /**
56
     * @param string $className
57
     * @param string $packageName
58
     */
59
    public function addOutgoingClassDependency($className, $packageName)
60
    {
61
        if ($packageName === $this->getName()) {
62
            return;
63
        }
64
        $classDependencies = $this->getOutgoingClassDependencies();
65
        $packageDependencies = $this->getOutgoingPackageDependencies();
66
        if (! in_array($className, $classDependencies)) {
67
            $classDependencies[] = $className;
68
            $this->set('outgoing_class_dependencies', $classDependencies);
69
        }
70
        if (! in_array($packageName, $packageDependencies)) {
71
            $packageDependencies[] = $packageName;
72
            $this->set('outgoing_package_dependencies', $packageDependencies);
73
        }
74
75
    }
76
77
    /** @return string[] */
78
    public function getOutgoingClassDependencies()
79
    {
80
        return $this->has('outgoing_class_dependencies') ? $this->get('outgoing_class_dependencies') : [];
81
    }
82
83
    /** @return string[] */
84
    public function getOutgoingPackageDependencies()
85
    {
86
        return $this->has('outgoing_package_dependencies') ? $this->get('outgoing_package_dependencies') : [];
87
    }
88
89
    /**
90
     * @param string $className
91
     * @param string $packageName
92
     */
93
    public function addIncomingClassDependency($className, $packageName)
94
    {
95
        if ($packageName === $this->getName()) {
96
            return;
97
        }
98
        $classDependencies = $this->getIncomingClassDependencies();
99
        $packageDependencies = $this->getIncomingPackageDependencies();
100
        if (! in_array($className, $classDependencies)) {
101
            $classDependencies[] = $className;
102
            $this->set('incoming_class_dependencies', $classDependencies);
103
        }
104
        if (! in_array($packageName, $packageDependencies)) {
105
            $packageDependencies[] = $packageName;
106
            $this->set('incoming_package_dependencies', $packageDependencies);
107
        }
108
109
    }
110
111
    /** @return string[] */
112
    public function getIncomingClassDependencies()
113
    {
114
        return $this->has('incoming_class_dependencies') ? $this->get('incoming_class_dependencies') : [];
115
    }
116
117
    /** @return string[] */
118
    public function getIncomingPackageDependencies()
119
    {
120
        return $this->has('incoming_package_dependencies') ? $this->get('incoming_package_dependencies') : [];
121
    }
122
123
    /** @param float $normalizedDistance */
124
    public function setNormalizedDistance($normalizedDistance)
125
    {
126
        $this->set('distance', $normalizedDistance / sqrt(2.0));
127
        $this->set('normalized_distance', $normalizedDistance);
128
    }
129
130
    /** @return float|null */
131
    public function getDistance()
132
    {
133
        return $this->get('distance');
134
    }
135
136
    /** @return float|null */
137
    public function getNormalizedDistance()
138
    {
139
        return $this->get('normalized_distance');
140
    }
141
142
    /** @param float[] $instabilities */
143
    public function setDependentInstabilities(array $instabilities)
144
    {
145
        $this->set('dependent_instabilities', $instabilities);
146
    }
147
148
    /** @return float[] */
149
    public function getDependentInstabilities()
150
    {
151
        return $this->has('dependent_instabilities') ? $this->get('dependent_instabilities') : [];
152
    }
153
}
154