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 |
||
10 | trait TypedMapTrait |
||
11 | { |
||
12 | /** |
||
13 | * @var Map internal map to store items |
||
14 | */ |
||
15 | private $compositeMap; |
||
16 | |||
17 | /** |
||
18 | * @var string[] fully qualified class name of acceptable types |
||
19 | */ |
||
20 | private $itemFqcns; |
||
21 | |||
22 | 2 | public function has(string $key): bool |
|
26 | |||
27 | /** |
||
28 | * @throws \OutOfBoundsException |
||
29 | */ |
||
30 | 6 | public function get(string $key) |
|
34 | |||
35 | /** |
||
36 | * @throws InvalidArgumentException |
||
37 | */ |
||
38 | 2 | public function set($key, $item): self |
|
45 | |||
46 | 3 | public function count(): int |
|
50 | |||
51 | 1 | public function toArray(): array |
|
55 | |||
56 | 1 | public function isEmpty(): bool |
|
60 | |||
61 | 1 | public function getIterator(): Iterator |
|
65 | |||
66 | 1 | public function getItemFqcn(): array |
|
70 | |||
71 | /** |
||
72 | * @throws \OutOfBoundsException |
||
73 | */ |
||
74 | 3 | public function __get(string $key) |
|
78 | |||
79 | 18 | private function init(iterable $items, $itemFqcns): void |
|
88 | |||
89 | 16 | View Code Duplication | private function assertItemKey($key): void |
99 | |||
100 | 14 | private function assertItemType($item): void |
|
118 | |||
119 | 1 | public function __clone() |
|
123 | } |
||
124 |