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 | class RaCandidateSearchQuery implements HttpQuery |
||
| 25 | { |
||
| 26 | /** |
||
| 27 | * @var string |
||
| 28 | */ |
||
| 29 | private $actorInstitution; |
||
| 30 | |||
| 31 | /** |
||
| 32 | * @var string |
||
| 33 | */ |
||
| 34 | private $institution; |
||
| 35 | |||
| 36 | /** |
||
| 37 | * @var string |
||
| 38 | */ |
||
| 39 | private $commonName; |
||
| 40 | |||
| 41 | /** |
||
| 42 | * @var string |
||
| 43 | */ |
||
| 44 | private $email; |
||
| 45 | |||
| 46 | /** |
||
| 47 | * @var int |
||
| 48 | */ |
||
| 49 | private $pageNumber = 1; |
||
| 50 | |||
| 51 | /** |
||
| 52 | * @var string |
||
| 53 | */ |
||
| 54 | private $orderBy; |
||
| 55 | |||
| 56 | /** |
||
| 57 | * @var string |
||
| 58 | */ |
||
| 59 | private $orderDirection; |
||
| 60 | |||
| 61 | /** |
||
| 62 | * @var string[] |
||
| 63 | */ |
||
| 64 | private $secondFactorTypes = []; |
||
| 65 | |||
| 66 | /** |
||
| 67 | * @param string $institution |
||
|
|
|||
| 68 | * @param int $pageNumber |
||
| 69 | */ |
||
| 70 | public function __construct($actorInstitution, $pageNumber) |
||
| 80 | |||
| 81 | /** |
||
| 82 | * @param string $commonName |
||
| 83 | * @return $this |
||
| 84 | */ |
||
| 85 | public function setCommonName($commonName) |
||
| 93 | |||
| 94 | /** |
||
| 95 | * @param string $email |
||
| 96 | * @return $this |
||
| 97 | */ |
||
| 98 | public function setEmail($email) |
||
| 106 | |||
| 107 | /** |
||
| 108 | * @param string $institution |
||
| 109 | * @return $this |
||
| 110 | */ |
||
| 111 | public function setInstitution($institution) |
||
| 119 | |||
| 120 | /** |
||
| 121 | * @param string $role |
||
| 122 | * @return $this |
||
| 123 | */ |
||
| 124 | public function setRole($role) |
||
| 132 | |||
| 133 | /** |
||
| 134 | * @param array $secondFactorTypes |
||
| 135 | * |
||
| 136 | * @return void |
||
| 137 | */ |
||
| 138 | public function setSecondFactorTypes(array $secondFactorTypes) |
||
| 144 | |||
| 145 | /** |
||
| 146 | * @param string $orderBy |
||
| 147 | * @return $this |
||
| 148 | */ |
||
| 149 | public function setOrderBy($orderBy) |
||
| 157 | |||
| 158 | /** |
||
| 159 | * @param string $orderDirection |
||
| 160 | * @return $this |
||
| 161 | */ |
||
| 162 | public function setOrderDirection($orderDirection) |
||
| 174 | |||
| 175 | View Code Duplication | public function toHttpQuery() |
|
| 195 | |||
| 196 | /** |
||
| 197 | * @param mixed $value |
||
| 198 | * @param string $parameterName |
||
| 199 | * @param string|null $message |
||
| 200 | */ |
||
| 201 | private function assertNonEmptyString($value, $parameterName, $message = null) |
||
| 211 | |||
| 212 | /** |
||
| 213 | * @param array $values |
||
| 214 | * @param string $parameterName |
||
| 215 | * |
||
| 216 | * @return void |
||
| 217 | */ |
||
| 218 | private function assertAllNonEmptyString(array $values, $parameterName) |
||
| 228 | } |
||
| 229 |
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.