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 ConstSetLikeTrait |
||
8 | { |
||
9 | use CommonContainerMethodsTrait; |
||
10 | |||
11 | /** |
||
12 | * @var array |
||
13 | */ |
||
14 | private $container; |
||
15 | |||
16 | View Code Duplication | protected function init($it = null) |
|
33 | |||
34 | /** |
||
35 | * {@inheritdoc} |
||
36 | */ |
||
37 | public function isEmpty() |
||
41 | |||
42 | /** |
||
43 | * {@inheritdoc} |
||
44 | */ |
||
45 | public function count() |
||
49 | |||
50 | /** |
||
51 | * identical to at, implemented for ArrayAccess |
||
52 | */ |
||
53 | public function offsetGet($offset) |
||
57 | |||
58 | /** |
||
59 | * {@inheritdoc} |
||
60 | */ |
||
61 | public function offsetExists($offset) |
||
65 | |||
66 | /** |
||
67 | * {@inheritdoc} |
||
68 | */ |
||
69 | public function containsKey($key) |
||
73 | |||
74 | /** |
||
75 | * @inheritDoc |
||
76 | */ |
||
77 | public function contains($item) |
||
81 | |||
82 | /** |
||
83 | * Returns an array containing the values from this VectorLike. |
||
84 | */ |
||
85 | View Code Duplication | public function toArray() |
|
98 | } |
||
99 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.