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 |
||
| 21 | class Issue extends FormAbstract |
||
| 22 | { |
||
| 23 | /** |
||
| 24 | * An instance of project model. |
||
| 25 | * |
||
| 26 | * @var Model\Project |
||
| 27 | */ |
||
| 28 | protected $project; |
||
| 29 | |||
| 30 | /** |
||
| 31 | * Collection of all tags |
||
| 32 | * |
||
| 33 | * @var \Illuminate\Database\Eloquent\Collection |
||
| 34 | */ |
||
| 35 | 6 | protected $tags = null; |
|
| 36 | |||
| 37 | 6 | /** |
|
| 38 | 6 | * @param string $type |
|
| 39 | 2 | * |
|
| 40 | * @return \Illuminate\Database\Eloquent\Collection|null |
||
| 41 | 6 | */ |
|
| 42 | protected function getTags($type = null) |
||
| 54 | |||
| 55 | /** |
||
| 56 | 6 | * Get issue tag for specific type/group |
|
| 57 | * |
||
| 58 | 6 | * @param string $type |
|
| 59 | * |
||
| 60 | 6 | * @return int |
|
| 61 | 6 | */ |
|
| 62 | 6 | protected function getIssueTagId($type) |
|
| 77 | |||
| 78 | /** |
||
| 79 | 6 | * @param array $params |
|
| 80 | * |
||
| 81 | * @return void |
||
| 82 | */ |
||
| 83 | public function setup(array $params) |
||
| 90 | |||
| 91 | /** |
||
| 92 | * @return array |
||
| 93 | 7 | */ |
|
| 94 | public function actions() |
||
| 100 | |||
| 101 | /** |
||
| 102 | 7 | * @return array |
|
| 103 | */ |
||
| 104 | public function fields() |
||
| 124 | |||
| 125 | /** |
||
| 126 | * Return a list of fields for users with issue modify permission |
||
| 127 | * |
||
| 128 | * @return array |
||
| 129 | 2 | */ |
|
| 130 | protected function issueModifyFields() |
||
| 152 | |||
| 153 | /** |
||
| 154 | 6 | * Returns title field. |
|
| 155 | 6 | * |
|
| 156 | 6 | * @return array |
|
| 157 | 6 | */ |
|
| 158 | protected function fieldTitle() |
||
| 167 | 6 | ||
| 168 | /** |
||
| 169 | 6 | * Returns body field. |
|
| 170 | 6 | * |
|
| 171 | 6 | * @return array |
|
| 172 | */ |
||
| 173 | 6 | protected function fieldBody() |
|
| 182 | |||
| 183 | /** |
||
| 184 | * Returns status tag field. |
||
| 185 | 6 | * |
|
| 186 | 6 | * @return array |
|
| 187 | */ |
||
| 188 | View Code Duplication | protected function fieldStatusTags() |
|
| 210 | /** |
||
| 211 | * Returns tags field. |
||
| 212 | 7 | * |
|
| 213 | * @return array |
||
| 214 | */ |
||
| 215 | View Code Duplication | protected function fieldTypeTags() |
|
| 237 | |||
| 238 | 6 | /** |
|
| 239 | * Returns tags field. |
||
| 240 | 6 | * |
|
| 241 | 2 | * @return array |
|
| 242 | 2 | */ |
|
| 243 | 2 | protected function fieldResolutionTags() |
|
| 272 | |||
| 273 | /** |
||
| 274 | * Returns assigned to field. |
||
| 275 | * |
||
| 276 | * @return array |
||
| 277 | */ |
||
| 278 | protected function fieldAssignedTo() |
||
| 289 | |||
| 290 | /** |
||
| 291 | * Returns upload field. |
||
| 292 | * |
||
| 293 | * @return array |
||
| 294 | */ |
||
| 295 | protected function fieldUpload() |
||
| 303 | |||
| 304 | /** |
||
| 305 | * Returns time quote field. |
||
| 306 | * |
||
| 307 | * @return array |
||
| 308 | */ |
||
| 309 | protected function fieldTimeQuote() |
||
| 333 | |||
| 334 | /** |
||
| 335 | * @return array |
||
| 336 | */ |
||
| 337 | public function rules() |
||
| 346 | |||
| 347 | /** |
||
| 348 | * @return string |
||
| 349 | */ |
||
| 350 | public function getRedirectUrl() |
||
| 358 | |||
| 359 | /** |
||
| 360 | * Extract number of hours, or minutes, or seconds from a quote. |
||
| 361 | * |
||
| 362 | * @param string $part |
||
| 363 | * |
||
| 364 | * @return float|int |
||
| 365 | */ |
||
| 366 | protected function extractQuoteValue($part) |
||
| 381 | } |
||
| 382 |
In PHP, under loose comparison (like
==, or!=, orswitchconditions), values of different types might be equal.For
stringvalues, the empty string''is a special case, in particular the following results might be unexpected: