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 |
||
16 | View Code Duplication | class FloatField extends NumericField |
|
|
|||
17 | { |
||
18 | /** |
||
19 | * {@inheritdoc} |
||
20 | */ |
||
21 | 1 | public function renderInput(InputRenderer $renderer, InputModel $model, array $attr) |
|
29 | |||
30 | /** |
||
31 | * @param InputModel $model |
||
32 | * |
||
33 | * @return float|null |
||
34 | * |
||
35 | * @throws UnexpectedValueException if unable to parse the input |
||
36 | */ |
||
37 | public function getValue(InputModel $model) |
||
51 | |||
52 | /** |
||
53 | * @param InputModel $model |
||
54 | * @param float|null $value |
||
55 | * |
||
56 | * @return void |
||
57 | * |
||
58 | * @throws InvalidArgumentException if the given value is unacceptable. |
||
59 | */ |
||
60 | public function setValue(InputModel $model, $value) |
||
70 | |||
71 | /** |
||
72 | * @inheritdoc |
||
73 | */ |
||
74 | 1 | protected function createTypeValidator() |
|
78 | } |
||
79 |
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.