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 |
||
24 | final class RaListingSearchQuery implements HttpQuery |
||
25 | { |
||
26 | /** |
||
27 | * @var string |
||
28 | */ |
||
29 | private $actorInstitution; |
||
30 | |||
31 | /** |
||
32 | * @var string|null |
||
33 | */ |
||
34 | private $institution; |
||
35 | |||
36 | /** |
||
37 | * @var int |
||
38 | */ |
||
39 | private $pageNumber; |
||
40 | |||
41 | /** |
||
42 | * @var string|null |
||
43 | */ |
||
44 | private $orderBy = 'commonName'; |
||
45 | |||
46 | /** |
||
47 | * @var string|null |
||
48 | */ |
||
49 | private $orderDirection = 'asc'; |
||
50 | |||
51 | /** |
||
52 | * @param string $institution |
||
|
|||
53 | * @param int $pageNumber |
||
54 | */ |
||
55 | View Code Duplication | public function __construct($actorInstitution, $pageNumber) |
|
65 | |||
66 | /** |
||
67 | * @param string $institution |
||
68 | * @return $this |
||
69 | */ |
||
70 | public function setInstitution($institution) |
||
78 | |||
79 | /** |
||
80 | * @param string $orderBy |
||
81 | * @return RaListingSearchQuery |
||
82 | */ |
||
83 | public function setOrderBy($orderBy) |
||
91 | |||
92 | /** |
||
93 | * @param string|null $orderDirection |
||
94 | * @return RaListingSearchQuery |
||
95 | */ |
||
96 | View Code Duplication | public function setOrderDirection($orderDirection) |
|
107 | |||
108 | private function assertNonEmptyString($value, $parameterName) |
||
118 | |||
119 | public function toHttpQuery() |
||
136 | } |
||
137 |
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.