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; |
||
9 | class TrackTransformer implements TrackTransformerInterface |
||
10 | { |
||
11 | /** |
||
12 | * Transform records in tracks collection |
||
13 | * |
||
14 | * @param Tracks $tracks The tracks collection |
||
|
|||
15 | * @return Collection The tracks collection after transform |
||
16 | */ |
||
17 | public function transform(Tracks $track) |
||
25 | |||
26 | /** |
||
27 | * Transform records in tracks collection |
||
28 | * |
||
29 | * @param Collection $tracks The tracks collection |
||
30 | * @return Collection The tracks collection after transform |
||
31 | */ |
||
32 | public function transforms(Collection $tracks) |
||
38 | |||
39 | /** |
||
40 | * Transform records in tracks collection as paginate |
||
41 | * |
||
42 | * @param Collection $tracks The tracks collection |
||
43 | * @return LengthAwarePaginator The tracks LengthAwarePaginator after transform |
||
44 | */ |
||
45 | public function transformPaginator(LengthAwarePaginator $tracks) |
||
54 | |||
55 | /** |
||
56 | * Get current Status as text, tracking by sequential of status datetime |
||
57 | * |
||
58 | * @param $track The track object |
||
59 | * @return string |
||
60 | */ |
||
61 | View Code Duplication | public function getTrackStatus($track) |
|
73 | |||
74 | /** |
||
75 | * Get current Status prias text, tracking by sequential of status datetime |
||
76 | * |
||
77 | * @param $track The track object |
||
78 | * @return string |
||
79 | */ |
||
80 | View Code Duplication | public function getTrackStatusTime($track) |
|
92 | } |
||
93 |
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.