Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
1 | <?php |
||
15 | class Container implements \ArrayAccess, ContainerInterface |
||
16 | { |
||
17 | /** |
||
18 | * @var array |
||
19 | */ |
||
20 | private $values; |
||
21 | |||
22 | /** |
||
23 | * @var \SplObjectStorage |
||
24 | */ |
||
25 | private $factories; |
||
26 | |||
27 | /** |
||
28 | * @var array |
||
29 | */ |
||
30 | private $frozen; |
||
31 | |||
32 | /** |
||
33 | * @var array |
||
34 | */ |
||
35 | private $raw; |
||
36 | |||
37 | 10 | public function __construct(array $values = []) |
|
48 | |||
49 | /** |
||
50 | * @inheritDoc |
||
51 | */ |
||
52 | 9 | public function has($id) : bool |
|
56 | |||
57 | /** |
||
58 | * @inheritDoc |
||
59 | */ |
||
60 | 9 | public function get($id) |
|
81 | |||
82 | 7 | View Code Duplication | public function set($id, callable $value) : self |
92 | |||
93 | 2 | View Code Duplication | public function factory($id, callable $value) : self |
104 | |||
105 | 3 | public function remove($id) : self |
|
116 | |||
117 | 1 | public function addProvider(ContainerProviderInterface $provider) : self |
|
123 | |||
124 | /** |
||
125 | * @inheritDoc |
||
126 | */ |
||
127 | 1 | public function offsetExists($offset) : bool |
|
131 | |||
132 | /** |
||
133 | * @inheritDoc |
||
134 | */ |
||
135 | 1 | public function offsetGet($offset) |
|
139 | |||
140 | /** |
||
141 | * @inheritDoc |
||
142 | */ |
||
143 | 1 | public function offsetSet($offset, $value) |
|
147 | |||
148 | /** |
||
149 | * @inheritDoc |
||
150 | */ |
||
151 | 1 | public function offsetUnset($offset) |
|
155 | } |
||
156 |
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..