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 | trait BooleanValidatorTrait |
||
11 | { |
||
12 | /** @var UIValidationEngine */ |
||
13 | protected $validationEngine; |
||
14 | |||
15 | /** |
||
16 | * Exceptions are caught in order to be processed later |
||
17 | * @param mixed $value Boolean ? |
||
18 | * |
||
19 | * @return boolean|null Value casted into boolean or null |
||
20 | */ |
||
21 | View Code Duplication | public function mustBeBooleanOrEmpty($value, string $propertyPath = null, UIValidatorInterface $parentValidator = null, string $exceptionMessage = null) |
|
29 | |||
30 | /** |
||
31 | * Exceptions are caught in order to be processed later |
||
32 | * @param mixed $value Boolean ? |
||
33 | * |
||
34 | * @return boolean Value casted into boolean or false |
||
35 | */ |
||
36 | public function mustBeBoolean($value, string $propertyPath = null, UIValidatorInterface $parentValidator = null, string $exceptionMessage = null): bool |
||
69 | } |
||
70 |
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.