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 |
||
| 7 | trait TypedMapTrait |
||
| 8 | { |
||
| 9 | private $compositeMap; |
||
| 10 | |||
| 11 | private $itemFqcn; |
||
| 12 | |||
| 13 | public function has(string $key): bool |
||
| 17 | |||
| 18 | public function get(string $key) |
||
| 22 | |||
| 23 | public function set($key, $item): self |
||
| 30 | |||
| 31 | public function count(): int |
||
| 35 | |||
| 36 | public function toArray(): array |
||
| 40 | |||
| 41 | public function isEmpty(): bool |
||
| 45 | |||
| 46 | public function getIterator(): \Iterator |
||
| 50 | |||
| 51 | public function getItemFqcn() |
||
| 55 | |||
| 56 | public function __get(string $key) |
||
| 60 | |||
| 61 | private function init(array $items, string $itemFqcn) |
||
| 70 | |||
| 71 | View Code Duplication | private function assertItemKey($key) |
|
| 81 | |||
| 82 | View Code Duplication | private function assertItemType($item) |
|
| 93 | |||
| 94 | public function __clone() |
||
| 98 | } |
||
| 99 |