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 |
||
| 35 | class GssfPossessionProvenEvent extends IdentityEvent implements Forgettable |
||
| 36 | { |
||
| 37 | /** |
||
| 38 | * @var \Surfnet\Stepup\Identity\Value\SecondFactorId |
||
| 39 | */ |
||
| 40 | public $secondFactorId; |
||
| 41 | |||
| 42 | /** |
||
| 43 | * @var \Surfnet\Stepup\Identity\Value\StepupProvider |
||
| 44 | */ |
||
| 45 | public $stepupProvider; |
||
| 46 | |||
| 47 | /** |
||
| 48 | * @var \Surfnet\Stepup\Identity\Value\GssfId |
||
| 49 | */ |
||
| 50 | public $gssfId; |
||
| 51 | |||
| 52 | /** |
||
| 53 | * @var bool |
||
| 54 | */ |
||
| 55 | public $emailVerificationRequired; |
||
| 56 | |||
| 57 | /** |
||
| 58 | * @var \Surfnet\Stepup\Identity\Value\EmailVerificationWindow |
||
| 59 | */ |
||
| 60 | public $emailVerificationWindow; |
||
| 61 | |||
| 62 | /** |
||
| 63 | * @var string |
||
| 64 | */ |
||
| 65 | public $emailVerificationNonce; |
||
| 66 | |||
| 67 | /** |
||
| 68 | * @var \Surfnet\Stepup\Identity\Value\CommonName |
||
| 69 | */ |
||
| 70 | public $commonName; |
||
| 71 | |||
| 72 | /** |
||
| 73 | * @var \Surfnet\Stepup\Identity\Value\Email |
||
| 74 | */ |
||
| 75 | public $email; |
||
| 76 | |||
| 77 | /** |
||
| 78 | * @var \Surfnet\Stepup\Identity\Value\Locale Eg. "en_GB" |
||
| 79 | */ |
||
| 80 | public $preferredLocale; |
||
| 81 | |||
| 82 | /** |
||
| 83 | * @SuppressWarnings(PHPMD.ExcessiveParameterList) |
||
| 84 | * |
||
| 85 | * @param IdentityId $identityId |
||
| 86 | * @param Institution $identityInstitution |
||
| 87 | * @param SecondFactorId $secondFactorId |
||
| 88 | * @param StepupProvider $stepupProvider |
||
| 89 | * @param GssfId $gssfId |
||
| 90 | * @param bool $emailVerificationRequired |
||
| 91 | * @param EmailVerificationWindow $emailVerificationWindow |
||
| 92 | * @param string $emailVerificationNonce |
||
| 93 | * @param CommonName $commonName |
||
| 94 | * @param Email $email |
||
| 95 | * @param Locale $preferredLocale |
||
| 96 | */ |
||
| 97 | public function __construct( |
||
| 122 | |||
| 123 | public function getAuditLogMetadata() |
||
| 134 | |||
| 135 | public static function deserialize(array $data) |
||
| 155 | |||
| 156 | public function serialize() |
||
| 169 | |||
| 170 | View Code Duplication | public function getSensitiveData() |
|
|
|
|||
| 171 | { |
||
| 172 | return (new SensitiveData) |
||
| 173 | ->withCommonName($this->commonName) |
||
| 174 | ->withEmail($this->email) |
||
| 175 | ->withSecondFactorIdentifier($this->gssfId, new SecondFactorType((string) $this->stepupProvider)); |
||
| 176 | } |
||
| 177 | |||
| 178 | public function setSensitiveData(SensitiveData $sensitiveData) |
||
| 184 | } |
||
| 185 |
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.