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 namespace Maqe\Qwatcher\Tracks\Transformers; |
||
8 | class TrackTransformer implements TrackTransformerInterface |
||
9 | { |
||
10 | protected $sequentialStatus = ['succeed_at', 'failed_at', 'process_at', 'queue_at']; |
||
11 | |||
12 | /** |
||
13 | * Transform records in tracks collection |
||
14 | * |
||
15 | * @param Tracks $tracks The tracks collection |
||
|
|||
16 | * @return Collection The tracks collection after transform |
||
17 | */ |
||
18 | public function transform(Tracks $track) |
||
26 | |||
27 | /** |
||
28 | * Transform records in tracks collection |
||
29 | * |
||
30 | * @param Collection $tracks The tracks collection |
||
31 | * @return Collection The tracks collection after transform |
||
32 | */ |
||
33 | public function transforms(Collection $tracks) |
||
39 | |||
40 | /** |
||
41 | * Transform records in tracks collection as paginate |
||
42 | * |
||
43 | * @param Collection $tracks The tracks collection |
||
44 | * @return LengthAwarePaginator The tracks LengthAwarePaginator after transform |
||
45 | */ |
||
46 | public function transformPaginator(LengthAwarePaginator $tracks) |
||
55 | |||
56 | /** |
||
57 | * Get current Status as text, tracking by sequential of status datetime |
||
58 | * |
||
59 | * @param $track The track object |
||
60 | * @return string |
||
61 | */ |
||
62 | View Code Duplication | public function getTrackStatus($track) |
|
72 | |||
73 | /** |
||
74 | * Get current Status prias text, tracking by sequential of status datetime |
||
75 | * |
||
76 | * @param $track The track object |
||
77 | * @return string |
||
78 | */ |
||
79 | View Code Duplication | public function getTrackStatusTime($track) |
|
89 | } |
||
90 |
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. It has, however, found a similar but not annotated parameter which might be a good fit.
Consider the following example. The parameter
$ireland
is not defined by the methodfinale(...)
.The most likely cause is that the parameter was changed, but the annotation was not.