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 | * An alias for slice. |
||
| 92 | * |
||
| 93 | * @param $offset |
||
| 94 | * @return $this |
||
| 95 | */ |
||
| 96 | public function skip($offset) |
||
| 100 | } |
||
| 101 |
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
$italyis not defined by the methodfinale(...).The most likely cause is that the parameter was removed, but the annotation was not.