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 |
||
| 10 | class MultiField implements CliField { |
||
| 11 | |||
| 12 | /** @var FieldRegistry */ |
||
| 13 | private $fields; |
||
| 14 | |||
| 15 | /** @var ParameterReader */ |
||
| 16 | private $reader; |
||
| 17 | |||
| 18 | public function __construct(FieldRegistry $fields, ParameterReader $reader) { |
||
| 22 | |||
| 23 | /** |
||
| 24 | * @param Parameter $parameter |
||
| 25 | * @return bool |
||
| 26 | */ |
||
| 27 | public function handles(Parameter $parameter) { |
||
| 30 | |||
| 31 | /** |
||
| 32 | * @param Parameter $parameter |
||
| 33 | * @param string $serialized |
||
| 34 | * @return mixed |
||
| 35 | */ |
||
| 36 | public function inflate(Parameter $parameter, $serialized) { |
||
| 42 | |||
| 43 | /** |
||
| 44 | * @param Parameter $parameter |
||
| 45 | * @return string |
||
| 46 | */ |
||
| 47 | View Code Duplication | public function getDescription(Parameter $parameter) { |
|
| 55 | |||
| 56 | /** |
||
| 57 | * @param Parameter $optionParameter |
||
| 58 | * @return CliField |
||
| 59 | */ |
||
| 60 | private function getField($optionParameter) { |
||
| 63 | |||
| 64 | View Code Duplication | private function getTypes(Parameter $parameter) { |
|
| 72 | } |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.