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 |
||
| 16 | class ViewReferenceHelper |
||
| 17 | { |
||
| 18 | /** |
||
| 19 | * @var ViewReferenceBuilder |
||
| 20 | */ |
||
| 21 | private $viewReferenceBuilder; |
||
| 22 | |||
| 23 | /** |
||
| 24 | * Constructor. |
||
| 25 | * |
||
| 26 | * @param ViewReferenceBuilder $viewReferenceBuilder |
||
| 27 | */ |
||
| 28 | public function __construct(ViewReferenceBuilder $viewReferenceBuilder) |
||
| 32 | |||
| 33 | /** |
||
| 34 | * @param View $view |
||
| 35 | * @param mixed $entity |
||
|
|
|||
| 36 | * |
||
| 37 | * @return string |
||
| 38 | */ |
||
| 39 | public static function generateViewReferenceId(View $view, $entityId = null) |
||
| 66 | |||
| 67 | /** |
||
| 68 | * @param [] $tree |
||
| 69 | */ |
||
| 70 | public function buildViewReferenceRecursively($tree, EntityManager $entityManager, $isRoot = true) |
||
| 90 | } |
||
| 91 |
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.