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 |
||
34 | View Code Duplication | class Factory extends ReflectionAnnotation |
|
|
|||
35 | { |
||
36 | |||
37 | /** |
||
38 | * The annotation for a default timeout method. |
||
39 | * |
||
40 | * @var string |
||
41 | */ |
||
42 | const ANNOTATION = 'Factory'; |
||
43 | |||
44 | /** |
||
45 | * This method returns the class name as |
||
46 | * a string. |
||
47 | * |
||
48 | * @return string |
||
49 | */ |
||
50 | public static function __getClass() |
||
54 | |||
55 | /** |
||
56 | * Returns the value of the name attribute. |
||
57 | * |
||
58 | * @return string|null The annotations name attribute |
||
59 | */ |
||
60 | public function getName() |
||
66 | |||
67 | /** |
||
68 | * Returns the value of the description attribute. |
||
69 | * |
||
70 | * @return string|null The annotations description attribute |
||
71 | */ |
||
72 | public function getDescription() |
||
78 | |||
79 | /** |
||
80 | * Returns the value of the type attribute. |
||
81 | * |
||
82 | * @return string The annotations type attribute |
||
83 | */ |
||
84 | public function getType() |
||
90 | |||
91 | /** |
||
92 | * Returns the value of the factory method attribute. |
||
93 | * |
||
94 | * @return string The annotations factory method attribute |
||
95 | */ |
||
96 | public function getMethod() |
||
102 | } |
||
103 |
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.