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 |
||
| 7 | class Option extends Input |
||
| 8 | { |
||
| 9 | /** |
||
| 10 | * Option shortcut. |
||
| 11 | * |
||
| 12 | * @var null|string |
||
| 13 | */ |
||
| 14 | protected $shortcut = null; |
||
| 15 | |||
| 16 | /** |
||
| 17 | * Default option value. |
||
| 18 | * |
||
| 19 | * @var null|string |
||
| 20 | */ |
||
| 21 | protected $default = null; |
||
| 22 | |||
| 23 | /** |
||
| 24 | * Parse the set input string. |
||
| 25 | * |
||
| 26 | * @return $this |
||
| 27 | */ |
||
| 28 | public function parse() |
||
| 38 | |||
| 39 | /** |
||
| 40 | * Parse option value and value default. |
||
| 41 | * |
||
| 42 | * @return $this |
||
| 43 | */ |
||
| 44 | protected function setValue() |
||
| 60 | |||
| 61 | /** |
||
| 62 | * If mode is empty, set VALUE_NONE. |
||
| 63 | * |
||
| 64 | * @return $this |
||
| 65 | */ |
||
| 66 | protected function setEmptyMode() |
||
| 72 | |||
| 73 | /** |
||
| 74 | * Set option shortcut. |
||
| 75 | * |
||
| 76 | * @return $this |
||
| 77 | */ |
||
| 78 | View Code Duplication | protected function setShortcut() |
|
| 86 | |||
| 87 | /** |
||
| 88 | * Get the option attributes. |
||
| 89 | * |
||
| 90 | * @return array |
||
| 91 | */ |
||
| 92 | public function getAttributes() |
||
| 102 | } |
||
| 103 |