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 |
||
37 | class Result extends AbstractBeanAnnotation |
||
38 | { |
||
39 | |||
40 | /** |
||
41 | * The value of the type attribute. |
||
42 | * |
||
43 | * @var string |
||
44 | */ |
||
45 | protected $type; |
||
46 | |||
47 | /** |
||
48 | * The value of the code attribute. |
||
49 | * |
||
50 | * @var string |
||
51 | */ |
||
52 | protected $code; |
||
53 | |||
54 | /** |
||
55 | * The value of the result attribute. |
||
56 | * |
||
57 | * @var string |
||
58 | */ |
||
59 | protected $result; |
||
60 | |||
61 | /** |
||
62 | * The constructor the initializes the instance with the |
||
63 | * data passed with the token. |
||
64 | * |
||
65 | * @param array $values The annotation values |
||
66 | */ |
||
67 | 9 | View Code Duplication | public function __construct(array $values = array()) |
88 | |||
89 | /** |
||
90 | * Returns the value of the type attribute. |
||
91 | * |
||
92 | * @return string|null The annotations type attribute |
||
93 | */ |
||
94 | 5 | public function getType() |
|
98 | |||
99 | /** |
||
100 | * Returns the value of the result attribute. |
||
101 | * |
||
102 | * @return string|null The annotations result attribute |
||
103 | */ |
||
104 | 5 | public function getResult() |
|
108 | |||
109 | /** |
||
110 | * Returns the value of the code attribute. |
||
111 | * |
||
112 | * @return string|null The annotations code attribute |
||
113 | */ |
||
114 | 5 | public function getCode() |
|
118 | } |
||
119 |
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.