Conditions | 7 |
Paths | 20 |
Total Lines | 57 |
Code Lines | 31 |
Lines | 0 |
Ratio | 0 % |
Changes | 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 |
||
107 | private function handleAuthorization(Command $command, Metadata $metadata): void |
||
108 | { |
||
109 | // Get the actorId and actorInstitution from the metadata |
||
110 | // Be aware that these values could be null when executing commands where we shouldn't log in for |
||
111 | // - CreateIdentityCommand |
||
112 | // - UpdateIdentityCommand |
||
113 | $actorId = is_null($metadata->actorId) ? null : new IdentityId($metadata->actorId); |
||
114 | $actorInstitution = is_null($metadata->actorInstitution) ? null : new Institution($metadata->actorInstitution); |
||
115 | |||
116 | // The institution of an actor should be whitelisted or the actor should be SRAA |
||
117 | // Be aware that the actor metadata is not always present, see self::resolveInstitution |
||
118 | $this->logger->notice('Ensuring that the actor institution is on the whitelist, or the actor is SRAA'); |
||
119 | $institution = $this->resolveInstitution($command, $metadata); |
||
120 | if (!$this->commandAuthorizationService->isInstitutionWhitelisted($institution, $actorId)) { |
||
121 | throw new AccessDeniedHttpException( |
||
122 | sprintf( |
||
123 | 'Institution "%s" is not on the whitelist and actor "%s" is not an SRAA, processing of command denied', |
||
124 | $institution, |
||
125 | $metadata->actorId, |
||
126 | ), |
||
127 | ); |
||
128 | } |
||
129 | |||
130 | $this->logger->notice( |
||
131 | 'Ensuring that the actor is allowed to execute a command based on the fine grained authorization configuration', |
||
132 | ); |
||
133 | |||
134 | // Validate that if a command is an SelfServiceExecutable we may execute the command |
||
135 | // This should be an SRAA or the actor itself |
||
136 | // Be aware that for the CreateIdentityCommand and UpdateIdentityCommand the actorId is unknown because we aren't logged in yet |
||
137 | if (!$this->commandAuthorizationService->maySelfserviceCommandBeExecutedOnBehalfOf( |
||
138 | $command, |
||
139 | $actorId, |
||
140 | )) { |
||
141 | $message = 'Processing of SelfService command denied, see log entries for details'; |
||
142 | if ($command instanceof SelfServiceExecutable) { |
||
143 | $message = sprintf( |
||
144 | 'The actor "%s" is not allowed to act on behalf of identity "%s" processing of SelfService command denied', |
||
145 | new IdentityId($metadata->actorId), |
||
146 | $command->getIdentityId(), |
||
147 | ); |
||
148 | } |
||
149 | throw new AccessDeniedHttpException($message); |
||
150 | } |
||
151 | |||
152 | // Validate that if a command is an RAExecutable we may execute the command |
||
153 | // This should be an SRAA or an RAA which is configured to act on behalf of the institution |
||
154 | if (!$this->commandAuthorizationService->mayRaCommandBeExecutedOnBehalfOf( |
||
155 | $command, |
||
156 | $actorId, |
||
157 | $actorInstitution, |
||
158 | )) { |
||
159 | throw new AccessDeniedHttpException( |
||
160 | sprintf( |
||
161 | 'The actor "%s" is not allowed to act on behalf of institution "%s" processing of RA command denied', |
||
162 | new IdentityId($metadata->actorId), |
||
163 | $institution, |
||
164 | ), |
||
169 |