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 | * Sort items by date: the most recent first. |
||
| 20 | * |
||
| 21 | * @return self |
||
|
|
|||
| 22 | */ |
||
| 23 | View Code Duplication | public function sortByDate(): self |
|
| 39 | |||
| 40 | /** |
||
| 41 | * Sort items by title (natural sort). |
||
| 42 | * |
||
| 43 | * @return self |
||
| 44 | */ |
||
| 45 | public function sortByTitle(): self |
||
| 51 | |||
| 52 | /** |
||
| 53 | * Sort by weight: the heaviest first. |
||
| 54 | * |
||
| 55 | * @return self |
||
| 56 | */ |
||
| 57 | View Code Duplication | public function sortByWeight(): self |
|
| 73 | } |
||
| 74 |
This check compares the return type specified in the
@returnannotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.