| Conditions | 13 |
| Paths | 28 |
| Total Lines | 116 |
| Code Lines | 68 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 141 | public function mayRaCommandBeExecutedOnBehalfOf( |
||
| 142 | Command $command, |
||
| 143 | IdentityId $actorId = null, |
||
| 144 | Institution $actorInstitution = null, |
||
| 145 | ): bool { |
||
| 146 | $commandName = $command::class; |
||
| 147 | $identityId = $actorId instanceof IdentityId ? $actorId->getIdentityId() : null; |
||
| 148 | |||
| 149 | $this->logger->notice('Running the mayRaCommandBeExecutedOnBehalfOf sequence'); |
||
| 150 | // Assert RA(A) specific authorizations |
||
| 151 | if ($command instanceof RaExecutable) { |
||
| 152 | $this->logger->notice('Asserting a RA command'); |
||
| 153 | |||
| 154 | // No additional FGA authorization is required for this shared (SS/RA) command |
||
| 155 | if ($command instanceof ExpressLocalePreferenceCommand) { |
||
| 156 | $this->logAllowRa( |
||
| 157 | 'RA(A) is always allowed to perform the ExpressLocalePreferenceCommand', |
||
| 158 | $commandName, |
||
| 159 | $identityId, |
||
| 160 | ); |
||
| 161 | return true; |
||
| 162 | } |
||
| 163 | |||
| 164 | // The actor metadata should be set |
||
| 165 | if (is_null($actorId) || is_null($actorInstitution)) { |
||
| 166 | $this->logDenyRA( |
||
| 167 | 'ActorId and/or actorInstitution is missing in mayRaCommandBeExecutedOnBehalfOf', |
||
| 168 | $commandName, |
||
| 169 | $identityId, |
||
| 170 | ); |
||
| 171 | return false; |
||
| 172 | } |
||
| 173 | |||
| 174 | // If the actor is SRAA all actions are allowed |
||
| 175 | if ($this->isSraa($actorId)) { |
||
| 176 | $this->logAllowRa( |
||
| 177 | 'SRAA is always allowed to execute RA commands', |
||
| 178 | $commandName, |
||
| 179 | $identityId, |
||
| 180 | ); |
||
| 181 | return true; |
||
| 182 | } |
||
| 183 | |||
| 184 | $raInstitution = $command->getRaInstitution(); |
||
| 185 | if (is_null($raInstitution)) { |
||
| 186 | $raInstitution = $actorInstitution->getInstitution(); |
||
| 187 | } |
||
| 188 | |||
| 189 | $this->logger->notice(sprintf('RA institution = %s', $raInstitution)); |
||
| 190 | |||
| 191 | $roleRequirement = RegistrationAuthorityRole::raa(); |
||
| 192 | |||
| 193 | // the VetSecondFactorCommand is used to vet a second factor for a user |
||
| 194 | // the RevokeRegistrantsSecondFactorCommand is used to revoke a user's secondfactor |
||
| 195 | // the RevokeRegistrantsRecoveryTokenCommand is used to revoke a user's recovery token |
||
| 196 | // All three are only sent by the RA where the minimal role requirement is RA |
||
| 197 | // all the other actions require RAA rights |
||
| 198 | if ($command instanceof VetSecondFactorCommand || |
||
| 199 | $command instanceof RevokeRegistrantsSecondFactorCommand || |
||
| 200 | $command instanceof RevokeRegistrantsRecoveryTokenCommand |
||
| 201 | ) { |
||
| 202 | $this->logger->notice( |
||
| 203 | 'VetSecondFactorCommand and RevokeRegistrantsSecondFactorCommand require a RA role', |
||
| 204 | ); |
||
| 205 | $roleRequirement = RegistrationAuthorityRole::ra(); |
||
| 206 | // Use the institution of the identity (the user vetting or having his token revoked). |
||
| 207 | $identity = $this->identityService->find($command->identityId); |
||
| 208 | if (!$identity instanceof Identity) { |
||
| 209 | $this->logDenyRA( |
||
| 210 | 'Unable to find the identity of the user that is being vetted, or revoked', |
||
| 211 | $commandName, |
||
| 212 | $identityId, |
||
| 213 | ); |
||
| 214 | return false; |
||
| 215 | } |
||
| 216 | $this->logger->notice( |
||
| 217 | sprintf( |
||
| 218 | 'Changed RA institution (before %s) to identity institution: %s', |
||
| 219 | $raInstitution, |
||
| 220 | $identity->institution->getInstitution(), |
||
| 221 | ), |
||
| 222 | ); |
||
| 223 | $raInstitution = $identity->institution->getInstitution(); |
||
| 224 | } |
||
| 225 | |||
| 226 | $authorizationContext = $this->authorizationContextService->buildInstitutionAuthorizationContext( |
||
| 227 | $actorId, |
||
| 228 | $roleRequirement, |
||
| 229 | ); |
||
| 230 | |||
| 231 | $this->logger->notice( |
||
| 232 | sprintf( |
||
| 233 | 'Identity is authorized RA(A) role in institutions: %s', |
||
| 234 | implode(',', $authorizationContext->getInstitutions()->serialize()), |
||
| 235 | ), |
||
| 236 | ); |
||
| 237 | |||
| 238 | if (!$authorizationContext->getInstitutions()->contains(new Institution($raInstitution))) { |
||
| 239 | $this->logDenyRA( |
||
| 240 | sprintf( |
||
| 241 | 'Identity is not RA(A) for the specified RA institution, "%s". Allowed institutions: "%s"', |
||
| 242 | $raInstitution, |
||
| 243 | implode(',', $authorizationContext->getInstitutions()->serialize()), |
||
| 244 | ), |
||
| 245 | $commandName, |
||
| 246 | $identityId, |
||
| 247 | ); |
||
| 248 | return false; |
||
| 249 | } |
||
| 250 | } |
||
| 251 | $this->logAllowRa( |
||
| 252 | 'Allowed', |
||
| 253 | $commandName, |
||
| 254 | $identityId, |
||
| 255 | ); |
||
| 256 | return true; |
||
| 257 | } |
||
| 335 |