DataModifierGroup   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 60
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A addModifier() 0 7 1
A getModifiers() 0 11 2
A modify() 0 8 2
1
<?php
2
3
namespace Thruster\Component\DataModifier;
4
5
/**
6
 * Class DataModifierGroup
7
 *
8
 * @package Thruster\Component\DataModifier
9
 * @author  Aurimas Niekis <[email protected]>
10
 */
11
class DataModifierGroup
12
{
13
    /**
14
     * @var DataModifierInterface[]
15
     */
16
    protected $dataModifiers;
17
    /**
18
     * @var DataModifierInterface[]
19
     */
20
    protected $sortedDataModifiers;
21
22 4
    public function __construct()
23
    {
24 4
        $this->dataModifiers       = [];
25 4
        $this->sortedDataModifiers = [];
26 4
    }
27
28
    /**
29
     * @param DataModifierInterface $dataModifier
30
     * @param int                   $priority
31
     *
32
     * @return $this
33
     */
34 2
    public function addModifier(DataModifierInterface $dataModifier, int $priority = 0) : self
35
    {
36 2
        $this->dataModifiers[$priority][] = $dataModifier;
37 2
        $this->sortedDataModifiers = null;
0 ignored issues
show
Documentation Bug introduced by
It seems like null of type null is incompatible with the declared type array<integer,object<Thr...DataModifierInterface>> of property $sortedDataModifiers.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
38
39 2
        return $this;
40
    }
41
42
    /**
43
     * @return DataModifierInterface[]
44
     */
45 2
    public function getModifiers() : array
46
    {
47 2
        if (null !== $this->sortedDataModifiers) {
48 1
            return $this->sortedDataModifiers;
49
        }
50
51 2
        krsort($this->dataModifiers);
52 2
        $this->sortedDataModifiers = call_user_func_array('array_merge', $this->dataModifiers);
0 ignored issues
show
Documentation Bug introduced by
It seems like call_user_func_array('ar..., $this->dataModifiers) of type * is incompatible with the declared type array<integer,object<Thr...DataModifierInterface>> of property $sortedDataModifiers.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
53
54 2
        return $this->sortedDataModifiers;
55
    }
56
57
    /**
58
     * @param mixed $input
59
     *
60
     * @return mixed
61
     */
62 1
    public function modify($input)
63
    {
64 1
        foreach ($this->getModifiers() as $modifier) {
65 1
            $input = $modifier->modify($input);
66
        }
67
68 1
        return $input;
69
    }
70
}
71