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 |
||
14 | class CheckRequired implements ValidatorInterface |
||
15 | { |
||
16 | /** |
||
17 | * @var string|null |
||
18 | */ |
||
19 | private $error; |
||
20 | |||
21 | /** |
||
22 | * @param string $error optional custom error message |
||
|
|||
23 | */ |
||
24 | 10 | public function __construct($error = null) |
|
28 | |||
29 | 1 | View Code Duplication | public function validate(FieldInterface $field, InputModel $model, InputValidation $validation) |
38 | } |
||
39 |
This check looks for
@param
annotations where the type inferred by our type inference engine differs from the declared type.It makes a suggestion as to what type it considers more descriptive.
Most often this is a case of a parameter that can be null in addition to its declared types.