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 | /** |
||
11 | * Transform records in tracks collection |
||
12 | * |
||
13 | * @param Tracks $tracks The tracks collection |
||
|
|||
14 | * @return Collection The tracks collection after transform |
||
15 | */ |
||
16 | public function transform(Tracks $track) |
||
24 | |||
25 | /** |
||
26 | * Transform records in tracks collection |
||
27 | * |
||
28 | * @param Collection $tracks The tracks collection |
||
29 | * @return Collection The tracks collection after transform |
||
30 | */ |
||
31 | public function transforms(Collection $tracks) |
||
37 | |||
38 | /** |
||
39 | * Transform records in tracks collection as paginate |
||
40 | * |
||
41 | * @param Collection $tracks The tracks collection |
||
42 | * @return LengthAwarePaginator The tracks LengthAwarePaginator after transform |
||
43 | */ |
||
44 | public function transformPaginator(LengthAwarePaginator $tracks) |
||
53 | |||
54 | /** |
||
55 | * Get current Status as text, tracking by sequential of status datetime |
||
56 | * |
||
57 | * @param $track The track object |
||
58 | * @return string |
||
59 | */ |
||
60 | 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) |
|
91 | } |
||
92 |
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.