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 |
||
14 | class CommandDocBlockParser3 extends AbstractCommandDocBlockParser |
||
15 | { |
||
16 | /** |
||
17 | * Parse the docBlock comment for this command, and set the |
||
18 | * fields of this class with the data thereby obtained. |
||
19 | */ |
||
20 | public function parse() |
||
41 | |||
42 | public function createDocBlock() |
||
52 | |||
53 | /** |
||
54 | * Save any tag that we do not explicitly recognize in the |
||
55 | * 'otherAnnotations' map. |
||
56 | */ |
||
57 | protected function processGenericTag($tag) |
||
61 | |||
62 | /** |
||
63 | * Set the name of the command from a @command or @name annotation. |
||
64 | */ |
||
65 | protected function processCommandTag($tag) |
||
72 | |||
73 | /** |
||
74 | * The @description and @desc annotations may be used in |
||
75 | * place of the synopsis (which we call 'description'). |
||
76 | * This is discouraged. |
||
77 | * |
||
78 | * @deprecated |
||
79 | */ |
||
80 | protected function processAlternateDescriptionTag($tag) |
||
84 | |||
85 | /** |
||
86 | * Store the data from a @arg annotation in our argument descriptions. |
||
87 | */ |
||
88 | protected function processArgumentTag($tag) |
||
92 | |||
93 | /** |
||
94 | * Store the data from a @param annotation in our argument descriptions. |
||
95 | */ |
||
96 | View Code Duplication | protected function processParamTag($tag) |
|
109 | |||
110 | /** |
||
111 | * Store the data from a @return annotation in our argument descriptions. |
||
112 | */ |
||
113 | protected function processReturnTag($tag) |
||
121 | |||
122 | /** |
||
123 | * Store the data from an @option annotation in our option descriptions. |
||
124 | */ |
||
125 | protected function processOptionTag($tag) |
||
129 | |||
130 | View Code Duplication | protected function addOptionOrArgumentTag($tag, DefaultsWithDescriptions $set) |
|
140 | |||
141 | /** |
||
142 | * Store the data from a @default annotation in our argument or option store, |
||
143 | * as appropriate. |
||
144 | */ |
||
145 | View Code Duplication | protected function processDefaultTag($tag) |
|
161 | |||
162 | /** |
||
163 | * Process the comma-separated list of aliases |
||
164 | */ |
||
165 | protected function processAliases($tag) |
||
169 | |||
170 | /** |
||
171 | * Store the data from a @usage annotation in our example usage list. |
||
172 | */ |
||
173 | View Code Duplication | protected function processUsageTag($tag) |
|
181 | } |
||
182 |
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.