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 |
||
35 | class Action |
||
36 | { |
||
37 | |||
38 | /** |
||
39 | * The value of the name attribute. |
||
40 | * |
||
41 | * @var string |
||
42 | */ |
||
43 | protected $name; |
||
44 | |||
45 | /** |
||
46 | * The value of the restrictions attribute. |
||
47 | * |
||
48 | * @var string |
||
49 | */ |
||
50 | protected $restrictions; |
||
51 | |||
52 | /** |
||
53 | * The value of the defaults attribute. |
||
54 | * |
||
55 | * @var string |
||
56 | */ |
||
57 | protected $defaults; |
||
58 | |||
59 | /** |
||
60 | * The constructor the initializes the instance with the |
||
61 | * data passed with the token. |
||
62 | * |
||
63 | * @param array $values The annotation values |
||
64 | */ |
||
65 | 9 | View Code Duplication | public function __construct(array $values = array()) |
83 | |||
84 | /** |
||
85 | * Returns the value of the name attribute. |
||
86 | * |
||
87 | * @return string|null The annotations name attribute |
||
88 | */ |
||
89 | 9 | public function getName() |
|
93 | |||
94 | /** |
||
95 | * Returns the value of the restrictions attribute. |
||
96 | * |
||
97 | * @return string|null The annotations restrictions attribute |
||
98 | */ |
||
99 | 8 | public function getRestrictions() |
|
103 | |||
104 | /** |
||
105 | * Returns the value of the defaults attribute. |
||
106 | * |
||
107 | * @return string|null The annotations defaults attribute |
||
108 | */ |
||
109 | 8 | public function getDefaults() |
|
113 | } |
||
114 |
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.