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 |
||
| 25 | final class RaSecondFactorExportQuery implements HttpQuery |
||
| 26 | { |
||
| 27 | const STATUS_UNVERIFIED = 'unverified'; |
||
| 28 | const STATUS_VERIFIED = 'verified'; |
||
| 29 | const STATUS_VETTED = 'vetted'; |
||
| 30 | const STATUS_REVOKED = 'revoked'; |
||
| 31 | |||
| 32 | /** |
||
| 33 | * @var string|null |
||
| 34 | */ |
||
| 35 | private $name; |
||
| 36 | |||
| 37 | /** |
||
| 38 | * @var string|null |
||
| 39 | */ |
||
| 40 | private $type; |
||
| 41 | |||
| 42 | /** |
||
| 43 | * @var string|null The second factor type's ID (eg. Yubikey public ID) |
||
| 44 | */ |
||
| 45 | private $secondFactorId; |
||
| 46 | |||
| 47 | /** |
||
| 48 | * @var string|null |
||
| 49 | */ |
||
| 50 | private $email; |
||
| 51 | |||
| 52 | /** |
||
| 53 | * @var string|null |
||
| 54 | */ |
||
| 55 | private $institution; |
||
| 56 | |||
| 57 | /** |
||
| 58 | * @var string|null One of the STATUS_* constants. |
||
| 59 | */ |
||
| 60 | private $status; |
||
| 61 | |||
| 62 | /** |
||
| 63 | * @var string|null |
||
| 64 | */ |
||
| 65 | private $orderBy; |
||
| 66 | |||
| 67 | /** |
||
| 68 | * @var string|null |
||
| 69 | */ |
||
| 70 | private $orderDirection; |
||
| 71 | |||
| 72 | /** |
||
| 73 | * @var string |
||
| 74 | */ |
||
| 75 | private $actorId; |
||
| 76 | |||
| 77 | /** |
||
| 78 | * @param string $actorId |
||
| 79 | */ |
||
| 80 | public function __construct($actorId) |
||
| 86 | |||
| 87 | /** |
||
| 88 | * @param string $actorInstitution |
||
|
|
|||
| 89 | * @return VerifiedSecondFactorSearchQuery |
||
| 90 | */ |
||
| 91 | public function setActorId($actorId) |
||
| 99 | |||
| 100 | public function getFileName() |
||
| 117 | |||
| 118 | /** |
||
| 119 | * @return null|string |
||
| 120 | */ |
||
| 121 | public function getName() |
||
| 125 | |||
| 126 | /** |
||
| 127 | * @param null|string $name |
||
| 128 | */ |
||
| 129 | public function setName($name) |
||
| 135 | |||
| 136 | /** |
||
| 137 | * @return null|string |
||
| 138 | */ |
||
| 139 | public function getType() |
||
| 143 | |||
| 144 | /** |
||
| 145 | * @param null|string $type |
||
| 146 | */ |
||
| 147 | public function setType($type) |
||
| 153 | |||
| 154 | /** |
||
| 155 | * @return null|string |
||
| 156 | */ |
||
| 157 | public function getSecondFactorId() |
||
| 161 | |||
| 162 | /** |
||
| 163 | * @param null|string $secondFactorId |
||
| 164 | */ |
||
| 165 | public function setSecondFactorId($secondFactorId) |
||
| 171 | |||
| 172 | /** |
||
| 173 | * @return null|string |
||
| 174 | */ |
||
| 175 | public function getEmail() |
||
| 179 | |||
| 180 | /** |
||
| 181 | * @param null|string $email |
||
| 182 | */ |
||
| 183 | public function setEmail($email) |
||
| 189 | |||
| 190 | /** |
||
| 191 | * @return null|string |
||
| 192 | */ |
||
| 193 | public function getInstitution() |
||
| 197 | |||
| 198 | /** |
||
| 199 | * @param null|string $institution |
||
| 200 | */ |
||
| 201 | public function setInstitution($institution) |
||
| 205 | |||
| 206 | /** |
||
| 207 | * @return null|string |
||
| 208 | */ |
||
| 209 | public function getStatus() |
||
| 213 | |||
| 214 | /** |
||
| 215 | * @param string $status |
||
| 216 | */ |
||
| 217 | View Code Duplication | public function setStatus($status) |
|
| 226 | |||
| 227 | /** |
||
| 228 | * @param string $orderBy |
||
| 229 | */ |
||
| 230 | public function setOrderBy($orderBy) |
||
| 236 | |||
| 237 | /** |
||
| 238 | * @param string|null $orderDirection |
||
| 239 | */ |
||
| 240 | View Code Duplication | public function setOrderDirection($orderDirection) |
|
| 249 | |||
| 250 | private function assertNonEmptyString($value, $name) |
||
| 260 | |||
| 261 | /** |
||
| 262 | * Return the Http Query string as should be used, MUST include the '?' prefix. |
||
| 263 | * |
||
| 264 | * @return string |
||
| 265 | */ |
||
| 266 | View Code Duplication | public function toHttpQuery() |
|
| 287 | } |
||
| 288 |
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.