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 |
||
17 | class OAuthIdentity extends DataObject |
||
18 | { |
||
19 | #region Fields |
||
20 | /** @var int */ |
||
21 | private $user; |
||
22 | /** @var string */ |
||
23 | private $iss; |
||
24 | /** @var int */ |
||
25 | private $sub; |
||
26 | /** @var string */ |
||
27 | private $aud; |
||
28 | /** @var int */ |
||
29 | private $exp; |
||
30 | /** @var int */ |
||
31 | private $iat; |
||
32 | /** @var string */ |
||
33 | private $username; |
||
34 | /** @var int */ |
||
35 | private $editcount; |
||
36 | /** @var int */ |
||
37 | private $confirmed_email; |
||
38 | /** @var int */ |
||
39 | private $blocked; |
||
40 | /** @var string */ |
||
41 | private $registered; |
||
42 | /** @var int */ |
||
43 | private $checkuser; |
||
44 | /** @var int */ |
||
45 | private $grantbasic; |
||
46 | /** @var int */ |
||
47 | private $grantcreateaccount; |
||
48 | /** @var int */ |
||
49 | private $granthighvolume; |
||
50 | /** @var int */ |
||
51 | private $grantcreateeditmovepage; |
||
52 | #endregion |
||
53 | |||
54 | /** |
||
55 | * Saves a data object to the database, either updating or inserting a record. |
||
56 | * @return void |
||
57 | * @throws Exception |
||
58 | * @throws OptimisticLockFailedException |
||
59 | */ |
||
60 | public function save() |
||
151 | |||
152 | #region Properties |
||
153 | |||
154 | /** |
||
155 | * @return int |
||
156 | */ |
||
157 | public function getUserId() |
||
161 | |||
162 | /** |
||
163 | * @param int $user |
||
164 | */ |
||
165 | public function setUserId($user) |
||
169 | |||
170 | /** |
||
171 | * @return string |
||
172 | */ |
||
173 | public function getIssuer() |
||
177 | |||
178 | /** |
||
179 | * @return int |
||
180 | */ |
||
181 | public function getSubject() |
||
185 | |||
186 | /** |
||
187 | * @return string |
||
188 | */ |
||
189 | public function getAudience() |
||
193 | |||
194 | /** |
||
195 | * @return int |
||
196 | */ |
||
197 | public function getExpirationTime() |
||
201 | |||
202 | /** |
||
203 | * @return int |
||
204 | */ |
||
205 | public function getIssuedAtTime() |
||
209 | |||
210 | /** |
||
211 | * @return string |
||
212 | */ |
||
213 | public function getUsername() |
||
217 | |||
218 | /** |
||
219 | * @return int |
||
220 | */ |
||
221 | public function getEditCount() |
||
225 | |||
226 | /** |
||
227 | * @return bool |
||
228 | */ |
||
229 | public function getConfirmedEmail() |
||
233 | |||
234 | /** |
||
235 | * @return bool |
||
236 | */ |
||
237 | public function getBlocked() |
||
241 | |||
242 | /** |
||
243 | * @return string |
||
244 | */ |
||
245 | public function getRegistered() |
||
249 | |||
250 | public function getRegistrationDate() |
||
254 | |||
255 | public function getAccountAge() |
||
262 | |||
263 | /** |
||
264 | * @return bool |
||
265 | */ |
||
266 | public function getCheckuser() |
||
270 | |||
271 | /** |
||
272 | * @return bool |
||
273 | */ |
||
274 | public function getGrantBasic() |
||
278 | |||
279 | /** |
||
280 | * @return bool |
||
281 | */ |
||
282 | public function getGrantCreateAccount() |
||
286 | |||
287 | /** |
||
288 | * @return bool |
||
289 | */ |
||
290 | public function getGrantHighVolume() |
||
294 | |||
295 | /** |
||
296 | * @return bool |
||
297 | */ |
||
298 | public function getGrantCreateEditMovePage() |
||
302 | |||
303 | #endregion Properties |
||
304 | |||
305 | /** |
||
306 | * Populates the fields of this instance from a provided JSON Web Token |
||
307 | * |
||
308 | * @param stdClass $jwt |
||
309 | */ |
||
310 | public function populate($jwt) |
||
354 | } |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.