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 string|null |
||
| 38 | */ |
||
| 39 | private $identityId; |
||
| 40 | |||
| 41 | /** |
||
| 42 | * @var int |
||
| 43 | */ |
||
| 44 | private $pageNumber; |
||
| 45 | |||
| 46 | /** |
||
| 47 | * @var string|null |
||
| 48 | */ |
||
| 49 | private $orderBy = 'commonName'; |
||
| 50 | |||
| 51 | /** |
||
| 52 | * @var string|null |
||
| 53 | */ |
||
| 54 | private $orderDirection = 'asc'; |
||
| 55 | |||
| 56 | /** |
||
| 57 | * @param string $institution |
||
|
|
|||
| 58 | * @param int $pageNumber |
||
| 59 | */ |
||
| 60 | View Code Duplication | public function __construct($actorInstitution, $pageNumber) |
|
| 70 | |||
| 71 | /** |
||
| 72 | * @param string $institution |
||
| 73 | * @return $this |
||
| 74 | */ |
||
| 75 | public function setInstitution($institution) |
||
| 83 | |||
| 84 | /** |
||
| 85 | * @param string $identityId |
||
| 86 | * @return RaListingSearchQuery |
||
| 87 | */ |
||
| 88 | public function setIdentityId($identityId) |
||
| 96 | |||
| 97 | /** |
||
| 98 | * @param string $orderBy |
||
| 99 | * @return RaListingSearchQuery |
||
| 100 | */ |
||
| 101 | public function setOrderBy($orderBy) |
||
| 109 | |||
| 110 | /** |
||
| 111 | * @param string|null $orderDirection |
||
| 112 | * @return RaListingSearchQuery |
||
| 113 | */ |
||
| 114 | View Code Duplication | public function setOrderDirection($orderDirection) |
|
| 125 | |||
| 126 | private function assertNonEmptyString($value, $parameterName) |
||
| 136 | |||
| 137 | public function toHttpQuery() |
||
| 155 | } |
||
| 156 |
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.