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 | * @param string $actorInstitution |
||
79 | */ |
||
80 | public function __construct($actorInstitution) |
||
85 | |||
86 | public function getFileName() |
||
103 | |||
104 | /** |
||
105 | * @return null|string |
||
106 | */ |
||
107 | public function getName() |
||
111 | |||
112 | /** |
||
113 | * @param null|string $name |
||
114 | */ |
||
115 | public function setName($name) |
||
121 | |||
122 | /** |
||
123 | * @return null|string |
||
124 | */ |
||
125 | public function getType() |
||
129 | |||
130 | /** |
||
131 | * @param null|string $type |
||
132 | */ |
||
133 | public function setType($type) |
||
139 | |||
140 | /** |
||
141 | * @return null|string |
||
142 | */ |
||
143 | public function getSecondFactorId() |
||
147 | |||
148 | /** |
||
149 | * @param null|string $secondFactorId |
||
150 | */ |
||
151 | public function setSecondFactorId($secondFactorId) |
||
157 | |||
158 | /** |
||
159 | * @return null|string |
||
160 | */ |
||
161 | public function getEmail() |
||
165 | |||
166 | /** |
||
167 | * @param null|string $email |
||
168 | */ |
||
169 | public function setEmail($email) |
||
175 | |||
176 | /** |
||
177 | * @return null|string |
||
178 | */ |
||
179 | public function getInstitution() |
||
183 | |||
184 | /** |
||
185 | * @param null|string $institution |
||
186 | */ |
||
187 | public function setInstitution($institution) |
||
191 | |||
192 | /** |
||
193 | * @return null|string |
||
194 | */ |
||
195 | public function getStatus() |
||
199 | |||
200 | /** |
||
201 | * @param string $status |
||
202 | */ |
||
203 | View Code Duplication | public function setStatus($status) |
|
212 | |||
213 | /** |
||
214 | * @param string $orderBy |
||
215 | */ |
||
216 | public function setOrderBy($orderBy) |
||
222 | |||
223 | /** |
||
224 | * @param string|null $orderDirection |
||
225 | */ |
||
226 | View Code Duplication | public function setOrderDirection($orderDirection) |
|
235 | |||
236 | View Code Duplication | private function assertNonEmptyString($value, $name) |
|
237 | { |
||
238 | $message = sprintf( |
||
239 | '"%s" must be a non-empty string, "%s" given', |
||
240 | $name, |
||
241 | (is_object($value) ? get_class($value) : gettype($value)) |
||
242 | ); |
||
243 | |||
244 | Assert\that($value)->string($message)->notEmpty($message); |
||
245 | } |
||
246 | |||
247 | /** |
||
248 | * Return the Http Query string as should be used, MUST include the '?' prefix. |
||
249 | * |
||
250 | * @return string |
||
251 | */ |
||
252 | View Code Duplication | public function toHttpQuery() |
|
273 | } |
||
274 |
Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a
@return
annotation as described here.