| Conditions | 13 |
| Paths | 28 |
| Total Lines | 114 |
| Code Lines | 67 |
| 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 |
||
| 167 | public function mayRaCommandBeExecutedOnBehalfOf( |
||
| 168 | Command $command, |
||
| 169 | IdentityId $actorId = null, |
||
| 170 | Institution $actorInstitution = null |
||
| 171 | ): bool { |
||
| 172 | $commandName = get_class($command); |
||
| 173 | $identityId = $actorId ? $actorId->getIdentityId() : null; |
||
| 174 | |||
| 175 | $this->logger->notice('Running the mayRaCommandBeExecutedOnBehalfOf sequence'); |
||
| 176 | // Assert RA(A) specific authorizations |
||
| 177 | if ($command instanceof RaExecutable) { |
||
| 178 | $this->logger->notice('Asserting a RA command'); |
||
| 179 | |||
| 180 | // No additional FGA authorization is required for this shared (SS/RA) command |
||
| 181 | if ($command instanceof ExpressLocalePreferenceCommand) { |
||
| 182 | $this->logAllowRa( |
||
| 183 | 'RA(A) is always allowed to perform the ExpressLocalePreferenceCommand', |
||
| 184 | $commandName, |
||
| 185 | $identityId |
||
| 186 | ); |
||
| 187 | return true; |
||
| 188 | } |
||
| 189 | |||
| 190 | // The actor metadata should be set |
||
| 191 | if (is_null($actorId) || is_null($actorInstitution)) { |
||
| 192 | $this->logDenyRA( |
||
| 193 | 'ActorId and/or actorInstitution is missing in mayRaCommandBeExecutedOnBehalfOf', |
||
| 194 | $commandName, |
||
| 195 | $identityId |
||
| 196 | ); |
||
| 197 | return false; |
||
| 198 | } |
||
| 199 | |||
| 200 | // If the actor is SRAA all actions are allowed |
||
| 201 | if ($this->isSraa($actorId)) { |
||
| 202 | $this->logAllowRa( |
||
| 203 | 'SRAA is always allowed to execute RA commands', |
||
| 204 | $commandName, |
||
| 205 | $identityId |
||
| 206 | ); |
||
| 207 | return true; |
||
| 208 | } |
||
| 209 | |||
| 210 | $raInstitution = $command->getRaInstitution(); |
||
| 211 | if (is_null($raInstitution)) { |
||
| 212 | $raInstitution = $actorInstitution->getInstitution(); |
||
| 213 | } |
||
| 214 | |||
| 215 | $this->logger->notice(sprintf('RA institution = %s', $raInstitution)); |
||
| 216 | |||
| 217 | $roleRequirement = RegistrationAuthorityRole::raa(); |
||
| 218 | |||
| 219 | // the VetSecondFactorCommand is used to vet a second factor for a user |
||
| 220 | // the RevokeRegistrantsSecondFactorCommand is used to revoke a user's secondfactor |
||
| 221 | // the RevokeRegistrantsRecoveryTokenCommand is used to revoke a user's recovery token |
||
| 222 | // All three are only sent by the RA where the minimal role requirement is RA |
||
| 223 | // all the other actions require RAA rights |
||
| 224 | if ($command instanceof VetSecondFactorCommand || |
||
| 225 | $command instanceof RevokeRegistrantsSecondFactorCommand || |
||
| 226 | $command instanceof RevokeRegistrantsRecoveryTokenCommand |
||
| 227 | ) { |
||
| 228 | $this->logger->notice('VetSecondFactorCommand and RevokeRegistrantsSecondFactorCommand require a RA role'); |
||
| 229 | $roleRequirement = RegistrationAuthorityRole::ra(); |
||
| 230 | // Use the institution of the identity (the user vetting or having his token revoked). |
||
| 231 | $identity = $this->identityService->find($command->identityId); |
||
| 232 | if (!$identity) { |
||
| 233 | $this->logDenyRA( |
||
| 234 | 'Unable to find the identity of the user that is being vetted, or revoked', |
||
| 235 | $commandName, |
||
| 236 | $identityId |
||
| 237 | ); |
||
| 238 | return false; |
||
| 239 | } |
||
| 240 | $this->logger->notice( |
||
| 241 | sprintf( |
||
| 242 | 'Changed RA institution (before %s) to identity institution: %s', |
||
| 243 | $raInstitution, |
||
| 244 | $identity->institution->getInstitution() |
||
| 245 | ) |
||
| 246 | ); |
||
| 247 | $raInstitution = $identity->institution->getInstitution(); |
||
| 248 | } |
||
| 249 | |||
| 250 | $authorizationContext = $this->authorizationContextService->buildInstitutionAuthorizationContext( |
||
| 251 | $actorId, |
||
| 252 | $roleRequirement |
||
| 253 | ); |
||
| 254 | |||
| 255 | $this->logger->notice( |
||
| 256 | sprintf( |
||
| 257 | 'Identity is authorized RA(A) role in institutions: %s', |
||
| 258 | implode(',', $authorizationContext->getInstitutions()->serialize()) |
||
| 259 | ) |
||
| 260 | ); |
||
| 261 | |||
| 262 | if (!$authorizationContext->getInstitutions()->contains(new Institution($raInstitution))) { |
||
| 263 | $this->logDenyRA( |
||
| 264 | sprintf( |
||
| 265 | 'Identity is not RA(A) for the specified RA institution, "%s". Allowed institutions: "%s"', |
||
| 266 | $raInstitution, |
||
| 267 | implode(',', $authorizationContext->getInstitutions()->serialize()) |
||
| 268 | ), |
||
| 269 | $commandName, |
||
| 270 | $identityId |
||
| 271 | ); |
||
| 272 | return false; |
||
| 273 | } |
||
| 274 | } |
||
| 275 | $this->logAllowRa( |
||
| 276 | 'Allowed', |
||
| 277 | $commandName, |
||
| 278 | $identityId |
||
| 279 | ); |
||
| 280 | return true; |
||
| 281 | } |
||
| 361 |