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 | View Code Duplication | class Resource extends AbstractBeanAnnotation |
|
|
|||
36 | { |
||
37 | |||
38 | /** |
||
39 | * The value of the bean interface attribute. |
||
40 | * |
||
41 | * @var string |
||
42 | */ |
||
43 | protected $beanInterface; |
||
44 | |||
45 | /** |
||
46 | * The value of the bean name attribute. |
||
47 | * |
||
48 | * @var string |
||
49 | */ |
||
50 | protected $beanName; |
||
51 | |||
52 | /** |
||
53 | * The value of the type attribute. |
||
54 | * |
||
55 | * @var string |
||
56 | */ |
||
57 | protected $type; |
||
58 | |||
59 | /** |
||
60 | * The value of the lookup attribute. |
||
61 | * |
||
62 | * @var string |
||
63 | */ |
||
64 | protected $lookup; |
||
65 | |||
66 | /** |
||
67 | * The constructor the initializes the instance with the |
||
68 | * data passed with the token. |
||
69 | * |
||
70 | * @param array $values The annotation values |
||
71 | */ |
||
72 | public function __construct(array $values = array()) |
||
98 | |||
99 | /** |
||
100 | * Returns the value of the bean interface attribute. |
||
101 | * |
||
102 | * @return string|null The annotations bean interface attribute |
||
103 | */ |
||
104 | public function getBeanInterface() |
||
108 | |||
109 | /** |
||
110 | * Returns the value of the bean name attribute. |
||
111 | * |
||
112 | * @return string|null The annotations bean Name attribute |
||
113 | */ |
||
114 | public function getBeanName() |
||
118 | |||
119 | /** |
||
120 | * Returns the value of the type attribute. |
||
121 | * |
||
122 | * @return string The annotations type attribute |
||
123 | */ |
||
124 | public function getType() |
||
128 | |||
129 | /** |
||
130 | * Returns the value of the lookup name attribute. |
||
131 | * |
||
132 | * @return string|null The annotations lookup name attribute |
||
133 | */ |
||
134 | public function getLookup() |
||
138 | } |
||
139 |
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.