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 |
||
19 | View Code Duplication | class Set extends AbstractSet |
|
|
|||
20 | { |
||
21 | /** |
||
22 | * Sets the optional contained edges. |
||
23 | * |
||
24 | * @param EdgeInterface[] $edges |
||
25 | */ |
||
26 | public function __construct(EdgeInterface ...$edges) |
||
30 | |||
31 | /** |
||
32 | * Sets the contained edges. |
||
33 | * |
||
34 | * @param EdgeInterface[] $edges |
||
35 | */ |
||
36 | public function set(EdgeInterface ...$edges) |
||
40 | |||
41 | /** |
||
42 | * Adds some edges. |
||
43 | * |
||
44 | * @param EdgeInterface[] $edges |
||
45 | */ |
||
46 | public function add(EdgeInterface ...$edges) |
||
50 | |||
51 | /** |
||
52 | * Checks if all the edges are contained. |
||
53 | * |
||
54 | * @param EdgeInterface[] $edges |
||
55 | * |
||
56 | * @return bool |
||
57 | */ |
||
58 | public function has(EdgeInterface ...$edges): bool |
||
70 | |||
71 | /** |
||
72 | * Removes some edges. |
||
73 | * |
||
74 | * @param EdgeInterface[] $edges |
||
75 | */ |
||
76 | public function remove(EdgeInterface ...$edges) |
||
86 | } |
||
87 |
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.