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 |
||
| 12 | class CalendarBuilder |
||
| 13 | { |
||
| 14 | /** |
||
| 15 | * @var CalendarExport |
||
| 16 | */ |
||
| 17 | private $calendarExport; |
||
| 18 | |||
| 19 | /** |
||
| 20 | * @var CalendarEventBuilder |
||
| 21 | */ |
||
| 22 | private $calendarEventBuilder; |
||
| 23 | |||
| 24 | /** |
||
| 25 | * CalendarBuilder constructor. |
||
| 26 | * |
||
| 27 | * @param CalendarExport $calendarExport |
||
| 28 | * @param CalendarEventBuilder $calendarEventBuilder |
||
| 29 | */ |
||
| 30 | 3 | public function __construct(CalendarExport $calendarExport, CalendarEventBuilder $calendarEventBuilder) |
|
| 35 | |||
| 36 | /** |
||
| 37 | * @param Plan $plan |
||
| 38 | */ |
||
| 39 | 2 | public function build(Plan $plan) |
|
| 56 | |||
| 57 | /** |
||
| 58 | * @param int $numSeance |
||
| 59 | * |
||
| 60 | * @return array |
||
|
|
|||
| 61 | */ |
||
| 62 | 3 | public function getRecoveryDay($numSeance) |
|
| 80 | |||
| 81 | /** |
||
| 82 | * @param Plan $plan |
||
| 83 | * |
||
| 84 | * @return string |
||
| 85 | */ |
||
| 86 | 1 | public function exportCalendar(Plan $plan) |
|
| 92 | } |
||
| 93 |
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.