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 |
||
| 53 | class RaCandidateProjector extends Projector |
||
| 54 | { |
||
| 55 | /** |
||
| 56 | * @var RaCandidateRepository |
||
| 57 | */ |
||
| 58 | private $raCandidateRepository; |
||
| 59 | |||
| 60 | /** |
||
| 61 | * @var RaListingRepository |
||
| 62 | */ |
||
| 63 | private $raListingRepository; |
||
| 64 | |||
| 65 | /** |
||
| 66 | * @var institutionAuthorizationRepository |
||
| 67 | */ |
||
| 68 | private $institutionAuthorizationRepository; |
||
| 69 | /** |
||
| 70 | * @var IdentityRepository |
||
| 71 | */ |
||
| 72 | private $identityRepository; |
||
| 73 | /** |
||
| 74 | * @var RaSecondFactorRepository |
||
| 75 | */ |
||
| 76 | private $raSecondFactorRepository; |
||
| 77 | |||
| 78 | public function __construct( |
||
| 79 | RaCandidateRepository $raCandidateRepository, |
||
| 80 | RaListingRepository $raListingRepository, |
||
| 81 | InstitutionAuthorizationRepository $institutionAuthorizationRepository, |
||
| 82 | IdentityRepository $identityRepository, |
||
| 83 | RaSecondFactorRepository $raSecondFactorRepository |
||
| 84 | ) { |
||
| 85 | $this->raCandidateRepository = $raCandidateRepository; |
||
| 86 | $this->raListingRepository = $raListingRepository; |
||
| 87 | $this->institutionAuthorizationRepository = $institutionAuthorizationRepository; |
||
|
|
|||
| 88 | $this->identityRepository = $identityRepository; |
||
| 89 | $this->raSecondFactorRepository = $raSecondFactorRepository; |
||
| 90 | } |
||
| 91 | |||
| 92 | /** |
||
| 93 | * @param SecondFactorVettedEvent $event |
||
| 94 | * @return void |
||
| 95 | * @throws \Doctrine\ORM\NonUniqueResultException |
||
| 96 | */ |
||
| 97 | public function applySecondFactorVettedEvent(SecondFactorVettedEvent $event) |
||
| 98 | { |
||
| 99 | $this->addCandidateToProjection( |
||
| 100 | $event->identityInstitution, |
||
| 101 | $event->identityId, |
||
| 102 | $event->nameId, |
||
| 103 | $event->commonName, |
||
| 104 | $event->email |
||
| 105 | ); |
||
| 106 | } |
||
| 107 | |||
| 108 | /** |
||
| 109 | * @param YubikeySecondFactorBootstrappedEvent $event |
||
| 110 | * @return void |
||
| 111 | * @throws \Doctrine\ORM\NonUniqueResultException |
||
| 112 | */ |
||
| 113 | public function applyYubikeySecondFactorBootstrappedEvent(YubikeySecondFactorBootstrappedEvent $event) |
||
| 114 | { |
||
| 115 | $this->addCandidateToProjection( |
||
| 116 | $event->identityInstitution, |
||
| 117 | $event->identityId, |
||
| 118 | $event->nameId, |
||
| 119 | $event->commonName, |
||
| 120 | $event->email |
||
| 121 | ); |
||
| 122 | } |
||
| 123 | |||
| 124 | /** |
||
| 125 | * If all vetted tokens are removed we should prevent the identity from becoming an RA candidate |
||
| 126 | * |
||
| 127 | * @param VettedSecondFactorsAllRevokedEvent $event |
||
| 128 | */ |
||
| 129 | public function applyVettedSecondFactorsAllRevokedEvent( |
||
| 130 | VettedSecondFactorsAllRevokedEvent $event |
||
| 131 | ) { |
||
| 132 | $this->raCandidateRepository->removeByIdentityId($event->identityId); |
||
| 133 | } |
||
| 134 | |||
| 135 | /** |
||
| 136 | * @param SraaUpdatedEvent $event |
||
| 137 | * |
||
| 138 | * Removes all RaCandidates that have a nameId matching an SRAA, as they cannot be made RA(A) as they |
||
| 139 | * already are SRAA. |
||
| 140 | */ |
||
| 141 | public function applySraaUpdatedEvent(SraaUpdatedEvent $event) |
||
| 145 | |||
| 146 | /** |
||
| 147 | * @param IdentityAccreditedAsRaForInstitutionEvent $event |
||
| 148 | * @return void |
||
| 149 | */ |
||
| 150 | public function applyIdentityAccreditedAsRaForInstitutionEvent(IdentityAccreditedAsRaForInstitutionEvent $event) |
||
| 154 | |||
| 155 | /** |
||
| 156 | * @param IdentityAccreditedAsRaaForInstitutionEvent $event |
||
| 157 | * @return void |
||
| 158 | */ |
||
| 159 | public function applyIdentityAccreditedAsRaaForInstitutionEvent(IdentityAccreditedAsRaaForInstitutionEvent $event) |
||
| 163 | |||
| 164 | /** |
||
| 165 | * @param RegistrationAuthorityRetractedForInstitutionEvent $event |
||
| 166 | * @return void |
||
| 167 | */ |
||
| 168 | View Code Duplication | public function applyRegistrationAuthorityRetractedForInstitutionEvent(RegistrationAuthorityRetractedForInstitutionEvent $event) |
|
| 181 | |||
| 182 | protected function applyIdentityForgottenEvent(IdentityForgottenEvent $event) |
||
| 186 | |||
| 187 | protected function applySelectRaaOptionChangedEvent(SelectRaaOptionChangedEvent $event) |
||
| 192 | |||
| 193 | protected function applyInstitutionConfigurationRemovedEvent(InstitutionConfigurationRemovedEvent $event) |
||
| 197 | |||
| 198 | /** |
||
| 199 | * This method is kept to be backwards compatible for changes before FGA |
||
| 200 | * |
||
| 201 | * @param IdentityAccreditedAsRaEvent $event |
||
| 202 | * @return void |
||
| 203 | */ |
||
| 204 | public function applyIdentityAccreditedAsRaEvent(IdentityAccreditedAsRaEvent $event) |
||
| 208 | |||
| 209 | /** |
||
| 210 | * This method is kept to be backwards compatible for changes before FGA |
||
| 211 | * |
||
| 212 | * @param IdentityAccreditedAsRaaEvent $event |
||
| 213 | * @return void |
||
| 214 | */ |
||
| 215 | public function applyIdentityAccreditedAsRaaEvent(IdentityAccreditedAsRaaEvent $event) |
||
| 219 | |||
| 220 | /** |
||
| 221 | * This method is kept to be backwards compatible for changes before FGA |
||
| 222 | * |
||
| 223 | * @param RegistrationAuthorityRetractedEvent $event |
||
| 224 | * @return void |
||
| 225 | */ |
||
| 226 | View Code Duplication | public function applyRegistrationAuthorityRetractedEvent(RegistrationAuthorityRetractedEvent $event) |
|
| 239 | |||
| 240 | /** |
||
| 241 | * @param Institution $institution |
||
| 242 | * @param ConfigurationInstitution[] $authorizedInstitutions |
||
| 243 | * @throws \Doctrine\ORM\NonUniqueResultException |
||
| 244 | */ |
||
| 245 | private function updateInstitutionCandidatesFromCollection(Institution $institution, array $authorizedInstitutions) |
||
| 287 | |||
| 288 | /** |
||
| 289 | * @param Institution $identityInstitution |
||
| 290 | * @param IdentityId $identityId |
||
| 291 | * @param NameId $identityNameId |
||
| 292 | * @param CommonName $identityCommonName |
||
| 293 | * @param Email $identityEmail |
||
| 294 | * @throws \Doctrine\ORM\NonUniqueResultException |
||
| 295 | */ |
||
| 296 | private function addCandidateToProjection( |
||
| 333 | } |
||
| 334 |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..