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 |
||
15 | final class Widgets |
||
16 | { |
||
17 | /** @var string Module name. */ |
||
18 | private $moduleName; |
||
19 | |||
20 | /** |
||
21 | * Get instance. |
||
22 | * |
||
23 | * @param string $moduleName |
||
24 | * |
||
25 | * @return self |
||
|
|||
26 | */ |
||
27 | public static function getInstance(string $moduleName): self |
||
33 | |||
34 | /** |
||
35 | * Get all widgets. |
||
36 | * |
||
37 | * @return array |
||
38 | */ |
||
39 | public function getAll(): array |
||
59 | } |
||
60 |
This check compares the return type specified in the
@return
annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.