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 |
||
9 | class VacancyManager |
||
10 | { |
||
11 | protected $business; |
||
12 | |||
13 | 1 | public function __construct(Business $business) |
|
17 | |||
18 | /** |
||
19 | * Get a Vacancy for a given DateTime and Service combination. |
||
20 | * |
||
21 | * @param Carbon $targetDateTime |
||
22 | * @param int $serviceId |
||
23 | * |
||
24 | * @return Timegridio\Concierge\Models\Vacancy |
||
25 | */ |
||
26 | // public function getSlotFor(Carbon $targetDateTime, $serviceId) |
||
|
|||
27 | // { |
||
28 | // return $this->business |
||
29 | // ->vacancies() |
||
30 | // ->forDateTime($targetDateTime) |
||
31 | // ->forService($serviceId) |
||
32 | // ->first(); |
||
33 | // } |
||
34 | |||
35 | 1 | public function publish($date, Carbon $startAt, Carbon $finishAt, $serviceId, $capacity = 1) |
|
50 | |||
51 | |||
52 | /** |
||
53 | * [generateAvailability description]. |
||
54 | * |
||
55 | * @param Illuminate\Database\Eloquent\Collection $vacancies |
||
56 | * @param string $startDate |
||
57 | * @param int $futureDays |
||
58 | * |
||
59 | * @return array |
||
60 | */ |
||
61 | public static function generateAvailability($vacancies, $startDate = 'today', $futureDays = 10) |
||
76 | |||
77 | } |
||
78 |
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.