SortedDictionary   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%
Metric Value
wmc 6
lcom 1
cbo 1
dl 0
loc 49
ccs 20
cts 20
cp 1
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A withValues() 0 6 1
A withValue() 0 6 1
A withoutValue() 0 6 1
A sortValues() 0 4 1
A sortChanged() 0 8 2
1
<?php
2
3
namespace Equip\Structure;
4
5
class SortedDictionary extends Dictionary
6
{
7 2
    public function withValues(array $values)
8
    {
9 2
        return $this->sortChanged(
10 2
            parent::withValues($values)
0 ignored issues
show
Compatibility introduced by
parent::withValues($values) of type object<Equip\Structure\Dictionary> is not a sub-type of object<Equip\Structure\SortedDictionary>. It seems like you assume a child class of the class Equip\Structure\Dictionary to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
11 1
        );
12
    }
13
14 2
    public function withValue($key, $value)
15
    {
16 2
        return $this->sortChanged(
17 2
            parent::withValue($key, $value)
0 ignored issues
show
Compatibility introduced by
parent::withValue($key, $value) of type object<Equip\Structure\Dictionary> is not a sub-type of object<Equip\Structure\SortedDictionary>. It seems like you assume a child class of the class Equip\Structure\Dictionary to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
18 2
        );
19
    }
20
21 1
    public function withoutValue($key)
22
    {
23 1
        return $this->sortChanged(
24 1
            parent::withoutValue($key)
0 ignored issues
show
Compatibility introduced by
parent::withoutValue($key) of type object<Equip\Structure\Dictionary> is not a sub-type of object<Equip\Structure\SortedDictionary>. It seems like you assume a child class of the class Equip\Structure\Dictionary to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
25 1
        );
26
    }
27
28
    /**
29
     * Sorts values, respecting keys.
30
     *
31
     * @return void
32
     */
33 4
    protected function sortValues()
34
    {
35 4
        asort($this->values);
36 4
    }
37
38
    /**
39
     * Sorts the dictionary if it is not the same.
40
     *
41
     * @param SortedDictionary $copy
42
     *
43
     * @return SortedDictionary
44
     */
45 4
    private function sortChanged(SortedDictionary $copy)
46
    {
47 4
        if ($copy !== $this) {
48 4
            $copy->sortValues();
49 4
        }
50
51 4
        return $copy;
52
    }
53
}
54