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 Anomaly\Streams\Platform\Model; |
||
14 | class EloquentCollection extends Collection |
||
15 | { |
||
16 | |||
17 | /** |
||
18 | * Return the item IDs. |
||
19 | * |
||
20 | * @return array |
||
21 | */ |
||
22 | public function ids() |
||
26 | |||
27 | /** |
||
28 | * Return a collection of decorated items. |
||
29 | * |
||
30 | * @return static |
||
31 | */ |
||
32 | public function decorated() |
||
44 | |||
45 | /** |
||
46 | * Return shuffled items. |
||
47 | * |
||
48 | * @param int $amount |
||
|
|||
49 | * @return static |
||
50 | */ |
||
51 | View Code Duplication | public function shuffle() |
|
65 | |||
66 | /** |
||
67 | * Pad to the specified size with a value. |
||
68 | * |
||
69 | * @param $size |
||
70 | * @param null $value |
||
71 | * @return $this |
||
72 | */ |
||
73 | public function pad($size, $value = null) |
||
89 | |||
90 | /** |
||
91 | * Find a model by key. |
||
92 | * |
||
93 | * @param $key |
||
94 | * @param $value |
||
95 | * @return EloquentModel |
||
96 | */ |
||
97 | public function findBy($key, $value) |
||
105 | |||
106 | /** |
||
107 | * An alias for slice. |
||
108 | * |
||
109 | * @param $offset |
||
110 | * @return $this |
||
111 | */ |
||
112 | public function skip($offset) |
||
116 | } |
||
117 |
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italy
is not defined by the methodfinale(...)
.The most likely cause is that the parameter was removed, but the annotation was not.