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 |
||
22 | class InvalidateRoute extends ConfigurationAnnotation |
||
23 | { |
||
24 | /** |
||
25 | * @var string |
||
26 | */ |
||
27 | private $name; |
||
28 | |||
29 | /** |
||
30 | * @var array |
||
31 | */ |
||
32 | private $params; |
||
33 | |||
34 | View Code Duplication | public function __construct( |
|
49 | 4 | ||
50 | /** |
||
51 | * Handle route name given without explicit key. |
||
52 | * |
||
53 | * @param string $value The route name |
||
54 | 2 | */ |
|
55 | public function setValue($value) |
||
59 | |||
60 | /** |
||
61 | * @param string $name |
||
62 | 4 | */ |
|
63 | public function setName($name) |
||
67 | 3 | ||
68 | 3 | /** |
|
69 | 3 | * @return string |
|
70 | 1 | */ |
|
71 | 1 | public function getName() |
|
75 | |||
76 | /** |
||
77 | * @param array $params |
||
78 | */ |
||
79 | public function setParams($params) |
||
106 | |||
107 | /** |
||
108 | * @return array |
||
109 | 1 | */ |
|
110 | public function getParams() |
||
114 | |||
115 | /** |
||
116 | * {@inheritdoc} |
||
117 | */ |
||
118 | public function getAliasName() |
||
122 | |||
123 | /** |
||
124 | * {@inheritdoc} |
||
125 | */ |
||
126 | public function allowArray() |
||
130 | } |
||
131 |
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.