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 Argument extends Input |
||
| 8 | { |
||
| 9 | /** |
||
| 10 | * Default arguement value. |
||
| 11 | * |
||
| 12 | * @var null|string |
||
| 13 | */ |
||
| 14 | protected $default = null; |
||
| 15 | |||
| 16 | /** |
||
| 17 | * Parse the set argument string. |
||
| 18 | * |
||
| 19 | * @return $this |
||
| 20 | */ |
||
| 21 | public function parse() |
||
| 31 | |||
| 32 | /** |
||
| 33 | * Set optional argument mode. |
||
| 34 | * |
||
| 35 | * @return $this |
||
| 36 | */ |
||
| 37 | protected function setOptional() |
||
| 47 | |||
| 48 | /** |
||
| 49 | * Set default option value. |
||
| 50 | * |
||
| 51 | * @return $this |
||
| 52 | */ |
||
| 53 | View Code Duplication | protected function setDefault() |
|
| 63 | |||
| 64 | /** |
||
| 65 | * Set required mode if optional not already set. |
||
| 66 | * |
||
| 67 | * @return $this |
||
| 68 | */ |
||
| 69 | protected function setRequired() |
||
| 77 | |||
| 78 | /** |
||
| 79 | * Get the argument attributes. |
||
| 80 | * |
||
| 81 | * @return array |
||
| 82 | */ |
||
| 83 | public function getAttributes() |
||
| 92 | } |
||
| 93 |