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 |
||
32 | class ImplicitlyVerifiedByIdp implements Forgettable, SerializableInterface |
||
33 | { |
||
34 | /** |
||
35 | * @var IdentityId |
||
36 | */ |
||
37 | public $identityId; |
||
38 | |||
39 | /** |
||
40 | * @var Institution |
||
41 | */ |
||
42 | public $identityInstitution; |
||
43 | |||
44 | /** |
||
45 | * @var \Surfnet\Stepup\Identity\Value\SecondFactorId |
||
46 | */ |
||
47 | public $secondFactorId; |
||
48 | |||
49 | /** |
||
50 | * @var \Surfnet\StepupBundle\Value\SecondFactorType |
||
51 | */ |
||
52 | public $secondFactorType; |
||
53 | |||
54 | /** |
||
55 | * @var \Surfnet\Stepup\Identity\Value\SecondFactorIdentifier |
||
56 | */ |
||
57 | public $secondFactorIdentifier; |
||
58 | |||
59 | /** |
||
60 | * @var \Surfnet\Stepup\DateTime\DateTime |
||
61 | */ |
||
62 | public $registrationRequestedAt; |
||
63 | |||
64 | /** |
||
65 | * @var string |
||
66 | */ |
||
67 | public $registrationCode; |
||
68 | |||
69 | /** |
||
70 | * @param IdentityId $identityId |
||
71 | * @param Institution $identityInstitution |
||
72 | * @param SecondFactorId $secondFactorId |
||
73 | * @param SecondFactorType $secondFactorType |
||
74 | * @param SecondFactorIdentifier $secondFactorIdentifier |
||
75 | * @param DateTime $registrationRequestedAt |
||
76 | * @param string $registrationCode |
||
77 | * |
||
78 | * @SuppressWarnings(PHPMD.ExcessiveParameterList) |
||
79 | */ |
||
80 | public function __construct( |
||
97 | |||
98 | View Code Duplication | public static function deserialize(array $data) |
|
112 | |||
113 | public function serialize() |
||
124 | |||
125 | public function getSensitiveData() |
||
130 | |||
131 | public function setSensitiveData(SensitiveData $sensitiveData) |
||
135 | } |
||
136 |
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.