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 |
||
36 | class VettedSecondFactor extends AbstractSecondFactor |
||
37 | { |
||
38 | /** |
||
39 | * @var \Surfnet\Stepup\Identity\Api\Identity |
||
40 | */ |
||
41 | private $identity; |
||
42 | |||
43 | /** |
||
44 | * @var \Surfnet\Stepup\Identity\Value\SecondFactorId |
||
45 | */ |
||
46 | private $id; |
||
47 | |||
48 | /** |
||
49 | * @var \Surfnet\StepupBundle\Value\SecondFactorType |
||
50 | */ |
||
51 | private $type; |
||
52 | |||
53 | /** |
||
54 | * @var \Surfnet\Stepup\Identity\Value\SecondFactorIdentifier |
||
55 | */ |
||
56 | private $secondFactorIdentifier; |
||
57 | |||
58 | /** |
||
59 | * @param SecondFactorId $id |
||
60 | * @param Identity $identity |
||
61 | * @param SecondFactorType $type |
||
62 | * @param SecondFactorIdentifier $secondFactorIdentifier |
||
63 | * @return VettedSecondFactor |
||
64 | */ |
||
65 | public static function create( |
||
79 | |||
80 | final public function __construct() |
||
83 | |||
84 | /** |
||
85 | * @return SecondFactorId |
||
86 | */ |
||
87 | public function getId() |
||
91 | |||
92 | View Code Duplication | public function revoke() |
|
104 | |||
105 | View Code Duplication | public function revokeAll() |
|
117 | |||
118 | View Code Duplication | public function complyWithRevocation(IdentityId $authorityId) |
|
131 | |||
132 | protected function applyIdentityForgottenEvent(IdentityForgottenEvent $event) |
||
138 | |||
139 | public function getType() |
||
143 | } |
||
144 |
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.