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 |
||
26 | View Code Duplication | class ConfigTuple extends Response |
|
|
|||
27 | { |
||
28 | /** |
||
29 | * @var string A configuration object attribute. |
||
30 | */ |
||
31 | private $attribute; |
||
32 | |||
33 | /** |
||
34 | * @var string The value for the attribute. |
||
35 | */ |
||
36 | private $value; |
||
37 | |||
38 | /** |
||
39 | * @return string A configuration object attribute. |
||
40 | */ |
||
41 | public function getAttribute() |
||
45 | |||
46 | /** |
||
47 | * @return string The value for the attribute. |
||
48 | */ |
||
49 | public function getValue() |
||
53 | |||
54 | /** |
||
55 | * @param string $response |
||
56 | */ |
||
57 | public function __construct($response) |
||
64 | |||
65 | /** |
||
66 | * @return string |
||
67 | */ |
||
68 | public function __toString() |
||
72 | |||
73 | } |
||
74 |
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.