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 |
||
29 | abstract class AbstractCollection extends Arrayy implements CollectionInterface |
||
30 | { |
||
31 | /** |
||
32 | * @var array |
||
33 | * @psalm-var array<T> |
||
34 | */ |
||
35 | protected $array = []; |
||
36 | |||
37 | /** |
||
38 | * @var ArrayyRewindableGenerator|null |
||
39 | * @psalm-var \Arrayy\ArrayyRewindableGenerator<T>|null |
||
40 | */ |
||
41 | protected $generator; |
||
42 | |||
43 | /** |
||
44 | * @var bool |
||
45 | */ |
||
46 | protected $checkPropertyTypes = true; |
||
47 | |||
48 | /** |
||
49 | * @var bool |
||
50 | */ |
||
51 | protected $checkPropertiesMismatch = false; |
||
52 | |||
53 | /** |
||
54 | * @var bool |
||
55 | */ |
||
56 | protected $checkForMissingPropertiesInConstructor = true; |
||
57 | |||
58 | /** |
||
59 | * Constructs a collection object of the specified type, optionally with the |
||
60 | * specified data. |
||
61 | * |
||
62 | * @param mixed $data |
||
63 | * <p> |
||
64 | * The initial items to store in the collection. |
||
65 | * </p> |
||
66 | * @param string $iteratorClass optional <p> |
||
67 | * You can overwrite the ArrayyIterator, but mostly you don't |
||
68 | * need this option. |
||
69 | * </p> |
||
70 | * @param bool $checkPropertiesInConstructor optional <p> |
||
71 | * You need to extend the "Arrayy"-class and you need to set |
||
72 | * the $checkPropertiesMismatchInConstructor class property |
||
73 | * to |
||
74 | * true, otherwise this option didn't not work anyway. |
||
75 | * </p> |
||
76 | * |
||
77 | * @psalm-param array<T> $data |
||
78 | * @psalm-param class-string<\Arrayy\ArrayyIterator> $iteratorClass |
||
79 | */ |
||
80 | 70 | public function __construct( |
|
108 | |||
109 | /** |
||
110 | * {@inheritdoc} |
||
111 | */ |
||
112 | 4 | View Code Duplication | public function append($value, $key = null): Arrayy |
131 | |||
132 | /** |
||
133 | * {@inheritdoc} |
||
134 | */ |
||
135 | 1 | public function offsetSet($offset, $value) |
|
151 | |||
152 | /** |
||
153 | * {@inheritdoc} |
||
154 | */ |
||
155 | 3 | View Code Duplication | public function prepend($value, $key = null): Arrayy |
174 | |||
175 | /** |
||
176 | * {@inheritdoc} |
||
177 | */ |
||
178 | 1 | public function column(string $keyOrPropertyOrMethod): array |
|
189 | |||
190 | /** |
||
191 | * {@inheritdoc} |
||
192 | */ |
||
193 | 6 | public function getCollection(): array |
|
197 | |||
198 | /** |
||
199 | * {@inheritdoc} |
||
200 | */ |
||
201 | abstract public function getType(); |
||
202 | |||
203 | /** |
||
204 | * Merge current items and items of given collections into a new one. |
||
205 | * |
||
206 | * @param CollectionInterface|static ...$collections The collections to merge. |
||
207 | * |
||
208 | * @throws \InvalidArgumentException if any of the given collections are not of the same type |
||
209 | * |
||
210 | * @return $this |
||
211 | * |
||
212 | * @psalm-param array<CollectionInterface<T>> ...$collections |
||
213 | * @psalm-return $this<T> |
||
214 | */ |
||
215 | 1 | public function merge(CollectionInterface ...$collections): self |
|
227 | |||
228 | /** |
||
229 | * {@inheritdoc} |
||
230 | */ |
||
231 | 68 | protected function internalSet( |
|
258 | |||
259 | /** |
||
260 | * @param string|string[]|TypeCheckArray|TypeCheckInterface[]|null $type |
||
261 | * |
||
262 | * @return TypeCheckArray |
||
263 | * |
||
264 | * @psalm-param null|string|class-string|string[]|array<class-string>|TypeCheckArray|array<TypeCheckInterface>|mixed $type |
||
265 | */ |
||
266 | 70 | protected static function convertIntoTypeCheckArray($type): TypeCheckArray |
|
283 | } |
||
284 |
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..