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 |
||
| 9 | class EnumerationField implements CliField { |
||
| 10 | |||
| 11 | /** @var FieldRegistry */ |
||
| 12 | private $fields; |
||
| 13 | |||
| 14 | /** |
||
| 15 | * EnumerationField constructor. |
||
| 16 | * @param FieldRegistry $fields |
||
| 17 | */ |
||
| 18 | public function __construct(FieldRegistry $fields) { |
||
| 21 | |||
| 22 | /** |
||
| 23 | * @param Parameter $parameter |
||
| 24 | * @return bool |
||
| 25 | */ |
||
| 26 | public function handles(Parameter $parameter) { |
||
| 29 | |||
| 30 | /** |
||
| 31 | * @param Parameter $parameter |
||
| 32 | * @param string $serialized |
||
| 33 | * @return mixed |
||
| 34 | * @throws \Exception |
||
| 35 | */ |
||
| 36 | public function inflate(Parameter $parameter, $serialized) { |
||
| 44 | |||
| 45 | /** |
||
| 46 | * @param Parameter $parameter |
||
| 47 | * @return EnumerationType |
||
| 48 | */ |
||
| 49 | private function getType(Parameter $parameter) { |
||
| 56 | |||
| 57 | /** |
||
| 58 | * @param Parameter $parameter |
||
| 59 | * @return string |
||
| 60 | */ |
||
| 61 | View Code Duplication | public function getDescription(Parameter $parameter) { |
|
| 69 | } |
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.