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 $institution; |
||
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 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 | * @param string $institution |
||
74 | */ |
||
75 | public function __construct($institution) |
||
80 | |||
81 | public function getFileName() |
||
98 | |||
99 | /** |
||
100 | * @return null|string |
||
101 | */ |
||
102 | public function getName() |
||
106 | |||
107 | /** |
||
108 | * @param null|string $name |
||
109 | */ |
||
110 | public function setName($name) |
||
116 | |||
117 | /** |
||
118 | * @return null|string |
||
119 | */ |
||
120 | public function getType() |
||
124 | |||
125 | /** |
||
126 | * @param null|string $type |
||
127 | */ |
||
128 | public function setType($type) |
||
134 | |||
135 | /** |
||
136 | * @return null|string |
||
137 | */ |
||
138 | public function getSecondFactorId() |
||
142 | |||
143 | /** |
||
144 | * @param null|string $secondFactorId |
||
145 | */ |
||
146 | public function setSecondFactorId($secondFactorId) |
||
152 | |||
153 | /** |
||
154 | * @return null|string |
||
155 | */ |
||
156 | public function getEmail() |
||
160 | |||
161 | /** |
||
162 | * @param null|string $email |
||
163 | */ |
||
164 | public function setEmail($email) |
||
170 | |||
171 | /** |
||
172 | * @return null|string |
||
173 | */ |
||
174 | public function getStatus() |
||
178 | |||
179 | /** |
||
180 | * @param string $status |
||
181 | */ |
||
182 | View Code Duplication | public function setStatus($status) |
|
191 | |||
192 | /** |
||
193 | * @param string $orderBy |
||
194 | */ |
||
195 | public function setOrderBy($orderBy) |
||
201 | |||
202 | /** |
||
203 | * @param string|null $orderDirection |
||
204 | */ |
||
205 | View Code Duplication | public function setOrderDirection($orderDirection) |
|
214 | |||
215 | View Code Duplication | private function assertNonEmptyString($value, $name) |
|
225 | |||
226 | /** |
||
227 | * Return the Http Query string as should be used, MUST include the '?' prefix. |
||
228 | * |
||
229 | * @return string |
||
230 | */ |
||
231 | View Code Duplication | public function toHttpQuery() |
|
251 | } |
||
252 |
It is generally a best practice as it is often more readable to use concatenation instead of interpolation for variables inside strings.