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 |
||
69 | class Phase_Result |
||
70 | { |
||
71 | protected $phaseName; |
||
72 | protected $message; |
||
73 | protected $nextAction; |
||
74 | protected $result; |
||
75 | protected $exception; |
||
76 | |||
77 | public $activityLog = []; |
||
78 | |||
79 | const MIN_RESULT = 1; |
||
80 | const MAX_RESULT = 8; |
||
81 | |||
82 | const COMPLETED = 1; |
||
83 | // success is an alias for completed! |
||
84 | const SUCCEEDED = 1; |
||
85 | const FAILED = 2; |
||
86 | const INCOMPLETE = 3; |
||
87 | const ERROR = 4; |
||
88 | const HASNOACTIONS = 5; |
||
89 | const SKIPPED = 6; |
||
90 | const BLACKLISTED = 7; |
||
91 | const CANNOTRUN = 8; |
||
92 | |||
93 | protected $resultTextMap = [ |
||
94 | 1 => "SUCCEEDED", |
||
95 | 2 => "FAILED", |
||
96 | 3 => "INCOMPLETE", |
||
97 | 4 => "ERROR", |
||
98 | 5 => "HASNOACTIONS", |
||
99 | 6 => "SKIPPED", |
||
100 | 7 => "BLACKLISTED", |
||
101 | 8 => "CANNOTRUN", |
||
102 | ]; |
||
103 | |||
104 | public function __construct($phaseName) |
||
108 | |||
109 | /** |
||
110 | * @return string |
||
111 | */ |
||
112 | public function getPhaseName() |
||
116 | |||
117 | /** |
||
118 | * @return boolean |
||
119 | */ |
||
120 | public function hasMessage() |
||
128 | |||
129 | /** |
||
130 | * @return string|null |
||
131 | */ |
||
132 | public function getMessage() |
||
146 | |||
147 | /** |
||
148 | * @return \Exception|null |
||
149 | */ |
||
150 | public function getException() |
||
154 | |||
155 | /** |
||
156 | * @return int |
||
157 | */ |
||
158 | public function getPhaseResult() |
||
162 | |||
163 | /** |
||
164 | * @return string |
||
165 | */ |
||
166 | public function getPhaseResultString() |
||
174 | |||
175 | /** |
||
176 | * @return bool |
||
177 | */ |
||
178 | public function getPhaseCompleted() |
||
186 | |||
187 | /** |
||
188 | * @return bool |
||
189 | */ |
||
190 | public function getPhaseSucceeded() |
||
198 | |||
199 | /** |
||
200 | * @return bool |
||
201 | */ |
||
202 | public function getPhaseFailed() |
||
210 | |||
211 | public function getPhaseHasErrored() |
||
219 | |||
220 | /** |
||
221 | * @return bool |
||
222 | */ |
||
223 | public function getPhaseIsIncomplete() |
||
231 | |||
232 | /** |
||
233 | * @return bool |
||
234 | */ |
||
235 | public function getPhaseHasNoActions() |
||
243 | |||
244 | /** |
||
245 | * @return bool |
||
246 | */ |
||
247 | public function getPhaseIsBlacklisted() |
||
255 | |||
256 | /** |
||
257 | * @return bool |
||
258 | */ |
||
259 | public function getPhaseHasBeenSkipped() |
||
267 | |||
268 | /** |
||
269 | * @return bool |
||
270 | */ |
||
271 | public function getPhaseCannotRun() |
||
279 | |||
280 | /** |
||
281 | * @return int |
||
282 | */ |
||
283 | public function getNextAction() |
||
287 | |||
288 | /** |
||
289 | * @param integer $result |
||
290 | * @param string|null $msg |
||
291 | * @param Exception|null $e |
||
292 | * @return void |
||
293 | */ |
||
294 | View Code Duplication | public function setContinuePlaying($result = 1, $msg = null, $e = null) |
|
301 | |||
302 | /** |
||
303 | * @param integer $result |
||
304 | * @param string $msg |
||
305 | * @param Exception|null $e |
||
306 | * @return void |
||
307 | */ |
||
308 | View Code Duplication | public function setPlayingFailed($result, $msg, $e = null) |
|
315 | |||
316 | /** |
||
317 | * @param integer $result |
||
318 | * @param string $msg |
||
319 | * @return void |
||
320 | */ |
||
321 | View Code Duplication | public function setSkipPlaying($result, $msg, $e = null) |
|
328 | } |
||
329 |