SortedDictionary::sortValues()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1
Metric Value
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 1
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