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 |
||
44 | abstract class AbstractStructureDefinition extends AbstractDefinition implements StructureDefinitionInterface |
||
45 | { |
||
46 | /** |
||
47 | * File path to the class definition |
||
48 | * |
||
49 | * @var string $path |
||
50 | */ |
||
51 | protected $path; |
||
52 | |||
53 | /** |
||
54 | * The namespace the class belongs to |
||
55 | * |
||
56 | * @var string $namespace |
||
57 | */ |
||
58 | protected $namespace; |
||
59 | |||
60 | /** |
||
61 | * All classes which are referenced by the "use" keyword |
||
62 | * |
||
63 | * @var array $usedStructures |
||
64 | */ |
||
65 | protected $usedStructures; |
||
66 | |||
67 | /** |
||
68 | * The initial class docblock header |
||
69 | * |
||
70 | * @var string $docBlock |
||
71 | */ |
||
72 | protected $docBlock; |
||
73 | |||
74 | /** |
||
75 | * Name of the class |
||
76 | * |
||
77 | * @var string $name |
||
78 | */ |
||
79 | protected $name; |
||
80 | |||
81 | /** |
||
82 | * List of methods this class defines |
||
83 | * |
||
84 | * @var \AppserverIo\Doppelgaenger\Entities\Lists\FunctionDefinitionList $functionDefinitions |
||
85 | */ |
||
86 | protected $functionDefinitions; |
||
87 | |||
88 | /** |
||
89 | * List of directly defined invariant conditions |
||
90 | * |
||
91 | * @var \AppserverIo\Doppelgaenger\Entities\Lists\AssertionList $invariantConditions |
||
92 | */ |
||
93 | protected $invariantConditions; |
||
94 | |||
95 | /** |
||
96 | * List of lists of any ancestral invariants |
||
97 | * |
||
98 | * @var \AppserverIo\Doppelgaenger\Entities\Lists\TypedListList $ancestralInvariants |
||
99 | */ |
||
100 | protected $ancestralInvariants; |
||
101 | |||
102 | /** |
||
103 | * Getter method for attribute $docBlock |
||
104 | * |
||
105 | * @return string |
||
106 | */ |
||
107 | public function getDocBlock() |
||
111 | |||
112 | /** |
||
113 | * Getter method for attribute $functionDefinitions |
||
114 | * |
||
115 | * @return null|\AppserverIo\Doppelgaenger\Entities\Lists\FunctionDefinitionList |
||
116 | */ |
||
117 | public function getFunctionDefinitions() |
||
121 | |||
122 | /** |
||
123 | * Will return all invariants. direct and introduced (by ancestral structures) alike. |
||
124 | * |
||
125 | * @param boolean $nonPrivateOnly Make this true if you only want conditions which do not have a private context |
||
126 | * |
||
127 | * @return \AppserverIo\Doppelgaenger\Entities\Lists\AssertionList |
||
128 | */ |
||
129 | View Code Duplication | public function getInvariants($nonPrivateOnly = false) |
|
155 | |||
156 | /** |
||
157 | * Getter method for attribute $name |
||
158 | * |
||
159 | * @return string |
||
160 | */ |
||
161 | public function getName() |
||
165 | |||
166 | /** |
||
167 | * Getter method for attribute $namespace |
||
168 | * |
||
169 | * @return string |
||
170 | */ |
||
171 | public function getNamespace() |
||
175 | |||
176 | /** |
||
177 | * Getter method for attribute $path |
||
178 | * |
||
179 | * @return string |
||
180 | */ |
||
181 | public function getPath() |
||
185 | |||
186 | /** |
||
187 | * Getter method for attribute $usedStructures |
||
188 | * |
||
189 | * @return array |
||
190 | */ |
||
191 | public function getUsedStructures() |
||
195 | |||
196 | /** |
||
197 | * Will return the qualified name of a structure |
||
198 | * |
||
199 | * @return string |
||
200 | */ |
||
201 | View Code Duplication | public function getQualifiedName() |
|
210 | |||
211 | /** |
||
212 | * Will return the type of the definition. |
||
213 | * |
||
214 | * @return string |
||
215 | */ |
||
216 | public function getType() |
||
220 | |||
221 | /** |
||
222 | * Does this structure have parent structures. |
||
223 | * We are talking parents here, not implemented interfaces or used traits |
||
224 | * |
||
225 | * @return boolean |
||
226 | */ |
||
227 | public function hasParents() |
||
231 | |||
232 | /** |
||
233 | * Setter method for attribute $docBlock |
||
234 | * |
||
235 | * @param string $docBlock Doc block of the structure |
||
236 | * |
||
237 | * @return null |
||
238 | */ |
||
239 | public function setDocBlock($docBlock) |
||
243 | |||
244 | /** |
||
245 | * Setter method for attribute $functionDefinitions |
||
246 | * |
||
247 | * @param \AppserverIo\Doppelgaenger\Entities\Lists\FunctionDefinitionList $functionDefinitions List of functions |
||
248 | * |
||
249 | * @return null |
||
250 | */ |
||
251 | public function setFunctionDefinitions(FunctionDefinitionList $functionDefinitions) |
||
255 | |||
256 | /** |
||
257 | * Setter method for attribute $name |
||
258 | * |
||
259 | * @param string $name Name of the structure |
||
260 | * |
||
261 | * @return null |
||
262 | */ |
||
263 | public function setName($name) |
||
267 | |||
268 | /** |
||
269 | * Getter method for attribute $namespace |
||
270 | * |
||
271 | * @param string $namespace The namespace of the structure |
||
272 | * |
||
273 | * @return null |
||
274 | */ |
||
275 | public function setNamespace($namespace) |
||
279 | |||
280 | /** |
||
281 | * Setter method for attribute $path |
||
282 | * |
||
283 | * @param string $path Path the definition's file |
||
284 | * |
||
285 | * @return null |
||
286 | */ |
||
287 | public function setPath($path) |
||
291 | |||
292 | /** |
||
293 | * Getter method for attribute $usedStructures |
||
294 | * |
||
295 | * @param array $usedStructures Array of structures referenced using the "use" statement |
||
296 | * |
||
297 | * @return null |
||
298 | */ |
||
299 | public function setUsedStructures($usedStructures) |
||
303 | } |
||
304 |