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 |
||
34 | View Code Duplication | class U2fDevicePossessionProvenEvent extends IdentityEvent implements Forgettable |
|
|
|||
35 | { |
||
36 | /** |
||
37 | * @var \Surfnet\Stepup\Identity\Value\SecondFactorId |
||
38 | */ |
||
39 | public $secondFactorId; |
||
40 | |||
41 | /** |
||
42 | * @var \Surfnet\Stepup\Identity\Value\U2fKeyHandle |
||
43 | */ |
||
44 | public $keyHandle; |
||
45 | |||
46 | /** |
||
47 | * @var \Surfnet\Stepup\Identity\Value\EmailVerificationWindow |
||
48 | */ |
||
49 | public $emailVerificationWindow; |
||
50 | |||
51 | /** |
||
52 | * @var string |
||
53 | */ |
||
54 | public $emailVerificationNonce; |
||
55 | |||
56 | /** |
||
57 | * @var \Surfnet\Stepup\Identity\Value\CommonName |
||
58 | */ |
||
59 | public $commonName; |
||
60 | |||
61 | /** |
||
62 | * @var \Surfnet\Stepup\Identity\Value\Email |
||
63 | */ |
||
64 | public $email; |
||
65 | |||
66 | /** |
||
67 | * @var \Surfnet\Stepup\Identity\Value\Locale Eg. "en_GB" |
||
68 | */ |
||
69 | public $preferredLocale; |
||
70 | |||
71 | /** |
||
72 | * @param IdentityId $identityId |
||
73 | * @param Institution $identityInstitution |
||
74 | * @param SecondFactorId $secondFactorId |
||
75 | * @param U2fKeyHandle $keyHandle |
||
76 | * @param EmailVerificationWindow $emailVerificationWindow |
||
77 | * @param string $emailVerificationNonce |
||
78 | * @param CommonName $commonName |
||
79 | * @param Email $email |
||
80 | * @param Locale $preferredLocale |
||
81 | */ |
||
82 | public function __construct( |
||
103 | |||
104 | public function getAuditLogMetadata() |
||
115 | |||
116 | public static function deserialize(array $data) |
||
130 | |||
131 | public function serialize() |
||
142 | |||
143 | public function getSensitiveData() |
||
150 | |||
151 | public function setSensitiveData(SensitiveData $sensitiveData) |
||
157 | } |
||
158 |
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.