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 |
||
17 | abstract class NumericField extends TextField |
||
18 | { |
||
19 | /** |
||
20 | * @var int|float|null minimum value |
||
21 | */ |
||
22 | public $min_value; |
||
23 | |||
24 | /** |
||
25 | * var int|float|null maximum value |
||
26 | */ |
||
27 | public $max_value; |
||
28 | |||
29 | /** |
||
30 | * {@inheritdoc} |
||
31 | */ |
||
32 | 2 | View Code Duplication | public function renderInput(InputRenderer $renderer, InputModel $model, array $attr) |
50 | |||
51 | /** |
||
52 | * @return ValidatorInterface |
||
53 | */ |
||
54 | abstract protected function createTypeValidator(); |
||
55 | |||
56 | /** |
||
57 | * @inheritdoc |
||
58 | */ |
||
59 | 3 | public function createValidators() |
|
77 | } |
||
78 |
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.