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 |
||
19 | View Code Duplication | trait ExpirePasswordTrait |
|
|
|||
20 | { |
||
21 | /** |
||
22 | * @var int Unix Epoch timestamp when the password expires. |
||
23 | * |
||
24 | * @ORM\Column(name="password_expires_at", type="integer", nullable=true) |
||
25 | */ |
||
26 | protected $passwordExpiresAt; |
||
27 | |||
28 | /** |
||
29 | * Makes password to expire at specified moment of time (NULL for no expiration). |
||
30 | * |
||
31 | * @param \DateTime $time |
||
32 | * |
||
33 | * @return self |
||
34 | */ |
||
35 | 1 | public function expirePasswordAt(\DateTime $time = null) |
|
43 | |||
44 | /** |
||
45 | * Makes password to expire in specified period of time. |
||
46 | * |
||
47 | * @param \DateInterval $interval |
||
48 | * |
||
49 | * @return self |
||
50 | */ |
||
51 | 1 | public function expirePasswordIn(\DateInterval $interval) |
|
59 | |||
60 | /** |
||
61 | * Specifies whether the "password expiration" feature is available for this user. |
||
62 | * |
||
63 | * @return bool |
||
64 | */ |
||
65 | 2 | protected function canPasswordBeExpired(): bool |
|
69 | } |
||
70 |
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.