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 |
||
34 | */ |
||
35 | private $actorInstitution; |
||
36 | |||
37 | /** |
||
38 | * @var string|null |
||
39 | */ |
||
40 | private $name; |
||
41 | |||
42 | /** |
||
43 | * @var string|null |
||
44 | */ |
||
45 | private $type; |
||
46 | |||
47 | /** |
||
48 | * @var string|null The second factor type's ID (eg. Yubikey public ID) |
||
49 | */ |
||
50 | private $secondFactorId; |
||
51 | |||
52 | /** |
||
53 | * @var string|null |
||
54 | */ |
||
55 | private $email; |
||
56 | |||
57 | /** |
||
58 | * @var string|null |
||
59 | */ |
||
60 | private $institution; |
||
61 | |||
62 | /** |
||
63 | * @var string|null One of the STATUS_* constants. |
||
64 | */ |
||
65 | private $status; |
||
66 | |||
67 | /** |
||
68 | * @var string|null |
||
69 | */ |
||
70 | private $orderBy; |
||
71 | |||
72 | /** |
||
73 | * @var string|null |
||
74 | */ |
||
75 | private $orderDirection; |
||
76 | |||
77 | /** |
||
78 | * @var string |
||
79 | */ |
||
80 | private $actorId; |
||
81 | |||
82 | /** |
||
83 | * @param string $actorInstitution |
||
84 | * @param string $actorId |
||
85 | */ |
||
86 | public function __construct($actorInstitution, $actorId) |
||
92 | |||
93 | /** |
||
94 | * @param string $actorInstitution |
||
|
|||
95 | * @return VerifiedSecondFactorSearchQuery |
||
96 | */ |
||
97 | public function setActorId($actorId) |
||
105 | |||
106 | public function getFileName() |
||
123 | |||
124 | /** |
||
125 | * @return null|string |
||
126 | */ |
||
127 | public function getName() |
||
131 | |||
132 | /** |
||
133 | * @param null|string $name |
||
134 | */ |
||
135 | public function setName($name) |
||
141 | |||
142 | /** |
||
143 | * @return null|string |
||
144 | */ |
||
145 | public function getType() |
||
149 | |||
150 | /** |
||
151 | * @param null|string $type |
||
152 | */ |
||
153 | public function setType($type) |
||
159 | |||
160 | /** |
||
161 | * @return null|string |
||
162 | */ |
||
163 | public function getSecondFactorId() |
||
167 | |||
168 | /** |
||
169 | * @param null|string $secondFactorId |
||
170 | */ |
||
171 | public function setSecondFactorId($secondFactorId) |
||
177 | |||
178 | /** |
||
179 | * @return null|string |
||
180 | */ |
||
181 | public function getEmail() |
||
185 | |||
186 | /** |
||
187 | * @param null|string $email |
||
188 | */ |
||
189 | public function setEmail($email) |
||
195 | |||
196 | /** |
||
197 | * @return null|string |
||
198 | */ |
||
199 | public function getInstitution() |
||
203 | |||
204 | /** |
||
205 | * @param null|string $institution |
||
206 | */ |
||
207 | public function setInstitution($institution) |
||
211 | |||
212 | /** |
||
213 | * @return null|string |
||
214 | */ |
||
215 | public function getStatus() |
||
219 | |||
220 | /** |
||
221 | * @param string $status |
||
222 | */ |
||
223 | View Code Duplication | public function setStatus($status) |
|
232 | |||
233 | /** |
||
234 | * @param string $orderBy |
||
235 | */ |
||
236 | public function setOrderBy($orderBy) |
||
242 | |||
243 | /** |
||
244 | * @param string|null $orderDirection |
||
245 | */ |
||
246 | View Code Duplication | public function setOrderDirection($orderDirection) |
|
255 | |||
256 | View Code Duplication | private function assertNonEmptyString($value, $name) |
|
266 | |||
267 | /** |
||
268 | * Return the Http Query string as should be used, MUST include the '?' prefix. |
||
269 | * |
||
270 | * @return string |
||
271 | */ |
||
272 | View Code Duplication | public function toHttpQuery() |
|
294 | } |
||
295 |
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
$italy
is not defined by the methodfinale(...)
.The most likely cause is that the parameter was removed, but the annotation was not.