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 VerifiedSecondFactorSearchQuery implements HttpQuery |
||
| 25 | { |
||
| 26 | /** |
||
| 27 | * @var string |
||
| 28 | */ |
||
| 29 | private $identityId; |
||
| 30 | |||
| 31 | /** |
||
| 32 | * @var string |
||
| 33 | */ |
||
| 34 | private $secondFactorId; |
||
| 35 | |||
| 36 | /** |
||
| 37 | * @var string |
||
| 38 | */ |
||
| 39 | private $registrationCode; |
||
| 40 | |||
| 41 | /** |
||
| 42 | * @var string |
||
| 43 | */ |
||
| 44 | private $actorInstitution; |
||
| 45 | |||
| 46 | /** |
||
| 47 | * @var string |
||
| 48 | */ |
||
| 49 | private $institution; |
||
| 50 | /** |
||
| 51 | * @var string |
||
| 52 | */ |
||
| 53 | private $actorId; |
||
| 54 | |||
| 55 | /** |
||
| 56 | * @param string $identityId |
||
| 57 | * @return self |
||
| 58 | */ |
||
| 59 | public function setIdentityId($identityId) |
||
| 67 | |||
| 68 | /** |
||
| 69 | * @param string $secondFactorId |
||
| 70 | * @return self |
||
| 71 | */ |
||
| 72 | public function setSecondFactorId($secondFactorId) |
||
| 80 | |||
| 81 | /** |
||
| 82 | * @param string $registrationCode |
||
| 83 | * @return self |
||
| 84 | */ |
||
| 85 | public function setRegistrationCode($registrationCode) |
||
| 93 | |||
| 94 | /** |
||
| 95 | * @param string $actorInstitution |
||
| 96 | * @return VerifiedSecondFactorSearchQuery |
||
| 97 | */ |
||
| 98 | public function setActorInstitution($actorInstitution) |
||
| 106 | |||
| 107 | /** |
||
| 108 | * @param string $institution |
||
| 109 | * @return VerifiedSecondFactorSearchQuery |
||
| 110 | */ |
||
| 111 | public function setInstitution($institution) |
||
| 119 | |||
| 120 | /** |
||
| 121 | * @param string $actorInstitution |
||
|
|
|||
| 122 | * @return VerifiedSecondFactorSearchQuery |
||
| 123 | */ |
||
| 124 | public function setActorId($actorId) |
||
| 132 | |||
| 133 | View Code Duplication | private function assertNonEmptyString($value, $name) |
|
| 134 | { |
||
| 135 | $message = sprintf( |
||
| 136 | '"%s" must be a non-empty string, "%s" given', |
||
| 137 | $name, |
||
| 138 | (is_object($value) ? get_class($value) : gettype($value)) |
||
| 139 | ); |
||
| 140 | |||
| 141 | Assert\that($value)->string($message)->notEmpty($message); |
||
| 142 | } |
||
| 143 | |||
| 144 | public function toHttpQuery() |
||
| 169 | } |
||
| 170 |
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italyis not defined by the methodfinale(...).The most likely cause is that the parameter was removed, but the annotation was not.