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 |
||
63 | class UbLangConsole extends Console |
||
64 | { |
||
65 | protected $currentPhase; |
||
66 | protected $currentPhaseStep; |
||
67 | protected $phaseGroupHasOutput = false; |
||
68 | protected $phaseNumber = 0; |
||
69 | protected $phaseMessages = array(); |
||
70 | |||
71 | /** |
||
72 | * a list of the results we have received from stories |
||
73 | * @var array |
||
74 | */ |
||
75 | protected $storyResults = []; |
||
76 | |||
77 | /** |
||
78 | * called when storyplayer starts |
||
79 | * |
||
80 | * @param string $version |
||
81 | * @param string $url |
||
82 | * @param string $copyright |
||
83 | * @param string $license |
||
84 | * @return void |
||
85 | */ |
||
86 | public function startStoryplayer($version, $url, $copyright, $license) |
||
95 | |||
96 | public function endStoryplayer($duration) |
||
100 | |||
101 | /** |
||
102 | * called when we start a new set of phases |
||
103 | * |
||
104 | * @param string $activity |
||
105 | * what are we doing? (e.g. 'creating', 'running') |
||
106 | * @param string $name |
||
107 | * the name of the phase group |
||
108 | * @param array|null $details |
||
109 | * optional explanation of what this PhaseGroup is trying |
||
110 | * to achieve |
||
111 | * @return void |
||
112 | */ |
||
113 | public function startPhaseGroup($activity, $name, $details = null) |
||
129 | |||
130 | View Code Duplication | public function endPhaseGroup($result) |
|
161 | |||
162 | /** |
||
163 | * called when a story starts a new phase |
||
164 | * |
||
165 | * @return void |
||
166 | */ |
||
167 | public function startPhase($phase) |
||
186 | |||
187 | /** |
||
188 | * called when a story ends a phase |
||
189 | * |
||
190 | * @return void |
||
191 | */ |
||
192 | public function endPhase($phase, $phaseResult) |
||
216 | |||
217 | /** |
||
218 | * called when a story logs an action |
||
219 | * |
||
220 | * @param string $msg |
||
221 | * @return void |
||
222 | */ |
||
223 | public function logPhaseActivity($msg, $codeLine = null) |
||
265 | |||
266 | /** |
||
267 | * called when a story logs the (possibly partial) output from |
||
268 | * running a subprocess |
||
269 | * |
||
270 | * @param string $msg the output to log |
||
271 | * @return void |
||
272 | */ |
||
273 | public function logPhaseSubprocessOutput($msg) |
||
277 | |||
278 | /** |
||
279 | * called when a story logs an error |
||
280 | * |
||
281 | * @param string $phaseName |
||
282 | * @param string $msg |
||
283 | * @return void |
||
284 | */ |
||
285 | public function logPhaseError($phaseName, $msg) |
||
289 | |||
290 | /** |
||
291 | * called when a story is skipped |
||
292 | * |
||
293 | * @param string $phaseName |
||
294 | * @param string $msg |
||
295 | * @return void |
||
296 | */ |
||
297 | public function logPhaseSkipped($phaseName, $msg) |
||
301 | |||
302 | public function logPhaseCodeLine($codeLine) |
||
306 | |||
307 | /** |
||
308 | * called when the outer CLI shell encounters a fatal error |
||
309 | * |
||
310 | * @param string $msg |
||
311 | * the error message to show the user |
||
312 | * |
||
313 | * @return void |
||
314 | */ |
||
315 | public function logCliError($msg) |
||
319 | |||
320 | /** |
||
321 | * |
||
322 | * @param string $msg |
||
323 | * @param Exception $e |
||
324 | * @return void |
||
325 | */ |
||
326 | public function logCliErrorWithException($msg, $e) |
||
332 | |||
333 | /** |
||
334 | * called when the outer CLI shell needs to publish a warning |
||
335 | * |
||
336 | * @param string $msg |
||
337 | * the warning message to show the user |
||
338 | * |
||
339 | * @return void |
||
340 | */ |
||
341 | public function logCliWarning($msg) |
||
345 | |||
346 | /** |
||
347 | * called when the outer CLI shell needs to tell the user something |
||
348 | * |
||
349 | * @param string $msg |
||
350 | * the message to show the user |
||
351 | * |
||
352 | * @return void |
||
353 | */ |
||
354 | public function logCliInfo($msg) |
||
358 | |||
359 | /** |
||
360 | * an alternative to using PHP's built-in var_dump() |
||
361 | * |
||
362 | * @param string $name |
||
363 | * a human-readable name to describe $var |
||
364 | * |
||
365 | * @param mixed $var |
||
366 | * the variable to dump |
||
367 | * |
||
368 | * @return void |
||
369 | */ |
||
370 | public function logVardump($name, $var) |
||
374 | } |
||
375 |
An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.
If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.