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 | class Collection extends CecilCollection |
||
17 | { |
||
18 | /** |
||
19 | * Return all not virtual pages. |
||
20 | */ |
||
21 | public function all(): self |
||
31 | |||
32 | /** |
||
33 | * Sort items by date: the most recent first. |
||
34 | * |
||
35 | * @return self |
||
|
|||
36 | */ |
||
37 | View Code Duplication | public function sortByDate(): self |
|
53 | |||
54 | /** |
||
55 | * Sort items by title (natural sort). |
||
56 | * |
||
57 | * @return self |
||
58 | */ |
||
59 | public function sortByTitle(): self |
||
65 | |||
66 | /** |
||
67 | * Sort by weight: the heaviest first. |
||
68 | * |
||
69 | * @return self |
||
70 | */ |
||
71 | View Code Duplication | public function sortByWeight(): self |
|
87 | } |
||
88 |
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.