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 |
||
| 5 | class Account extends AbstractObject |
||
| 6 | { |
||
| 7 | /** |
||
| 8 | * Insert new account. |
||
| 9 | * |
||
| 10 | * @param $params |
||
| 11 | */ |
||
| 12 | public function create(array $params) |
||
| 18 | |||
| 19 | /** |
||
| 20 | * Check if account already exists on SF. |
||
| 21 | * $params = [ |
||
| 22 | * 'PersonEmail' => '[email protected]' |
||
| 23 | * ] |
||
| 24 | * |
||
| 25 | * |
||
| 26 | * @param array $param to search |
||
|
|
|||
| 27 | * @param string $condition |
||
| 28 | * @return bool|array |
||
| 29 | */ |
||
| 30 | public function exists($params, $condition = 'AND', $returnAllRecords = false) |
||
| 57 | } |
||
| 58 |
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
$irelandis not defined by the methodfinale(...).The most likely cause is that the parameter was changed, but the annotation was not.