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 |
||
42 | class VerifiedSecondFactor extends AbstractSecondFactor |
||
43 | { |
||
44 | /** |
||
45 | * @var \Surfnet\Stepup\Identity\Value\SecondFactorId |
||
46 | */ |
||
47 | private $id; |
||
48 | |||
49 | /** |
||
50 | * @var \Surfnet\Stepup\Identity\Api\Identity |
||
51 | */ |
||
52 | private $identity; |
||
53 | |||
54 | /** |
||
55 | * @var \Surfnet\StepupBundle\Value\SecondFactorType |
||
56 | */ |
||
57 | private $type; |
||
58 | |||
59 | /** |
||
60 | * @var \Surfnet\Stepup\Identity\Value\SecondFactorIdentifier |
||
61 | */ |
||
62 | private $secondFactorIdentifier; |
||
63 | |||
64 | /** |
||
65 | * @var \Surfnet\Stepup\DateTime\DateTime |
||
66 | */ |
||
67 | private $registrationRequestedAt; |
||
68 | |||
69 | /** |
||
70 | * @var string |
||
71 | */ |
||
72 | private $registrationCode; |
||
73 | |||
74 | /** |
||
75 | * @param SecondFactorId $id |
||
76 | * @param Identity $identity |
||
77 | * @param SecondFactorType $type |
||
78 | * @param SecondFactorIdentifier $secondFactorIdentifier |
||
79 | * @param DateTime $registrationRequestedAt |
||
80 | * @param string $registrationCode |
||
81 | * @return self |
||
82 | */ |
||
83 | View Code Duplication | public static function create( |
|
105 | |||
106 | final private function __construct() |
||
109 | |||
110 | /** |
||
111 | * @return SecondFactorId |
||
112 | */ |
||
113 | public function getId() |
||
117 | |||
118 | /** |
||
119 | * @param string $registrationCode |
||
120 | * @param SecondFactorIdentifier $secondFactorIdentifier |
||
121 | * @return bool |
||
122 | */ |
||
123 | public function hasRegistrationCodeAndIdentifier($registrationCode, SecondFactorIdentifier $secondFactorIdentifier) |
||
128 | |||
129 | /** |
||
130 | * @return bool |
||
131 | */ |
||
132 | public function canBeVettedNow() |
||
140 | |||
141 | public function vet(DocumentNumber $documentNumber) |
||
158 | |||
159 | View Code Duplication | public function revoke() |
|
171 | |||
172 | View Code Duplication | public function complyWithRevocation(IdentityId $authorityId) |
|
185 | |||
186 | /** |
||
187 | * @return VettedSecondFactor |
||
188 | */ |
||
189 | public function asVetted() |
||
198 | |||
199 | protected function applyIdentityForgottenEvent(IdentityForgottenEvent $event) |
||
205 | |||
206 | public function getType() |
||
210 | } |
||
211 |
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.