| Conditions | 19 |
| Paths | 546 |
| Total Lines | 72 |
| Code Lines | 44 |
| 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 |
||
| 182 | public function process(array &$state): void |
||
| 183 | { |
||
| 184 | Assert::keyExists($state, 'Attributes'); |
||
| 185 | |||
| 186 | $authorize = $this->deny; |
||
| 187 | $attributes = &$state['Attributes']; |
||
| 188 | $ctx = []; |
||
| 189 | |||
| 190 | // Store the rejection message array in the $state |
||
| 191 | if (!empty($this->reject_msg)) { |
||
| 192 | $state['authprocAuthorize_reject_msg'] = $this->reject_msg; |
||
| 193 | } |
||
| 194 | $state['authprocAuthorize_errorURL'] = $this->errorURL; |
||
| 195 | $state['authprocAuthorize_allow_reauthentication'] = $this->allow_reauthentication; |
||
| 196 | // Get current SP EntityID from state |
||
| 197 | $currentSpEntityId = null; |
||
| 198 | if (isset($state['saml:sp:State']['core:SP'])) { |
||
| 199 | $currentSpEntityId = $state['saml:sp:State']['core:SP']; |
||
| 200 | } elseif (isset($state['Destination']['entityid'])) { |
||
| 201 | $currentSpEntityId = $state['Destination']['entityid']; |
||
| 202 | } |
||
| 203 | |||
| 204 | $arrayUtils = new Utils\Arrays(); |
||
| 205 | foreach ($this->valid_attribute_values as $name => $ruleConfig) { |
||
| 206 | if (array_key_exists($name, $attributes)) { |
||
| 207 | $patterns = $ruleConfig['values']; |
||
| 208 | $spEntityIDs = $ruleConfig['spEntityIDs']; |
||
| 209 | |||
| 210 | // If spEntityIDs is specified, check if current SP is in the list |
||
| 211 | if ($spEntityIDs !== null) { |
||
| 212 | if ($currentSpEntityId === null || !in_array($currentSpEntityId, $spEntityIDs, true)) { |
||
| 213 | continue; // Skip this rule if SP is not specified or not in allowed list |
||
| 214 | } |
||
| 215 | } |
||
| 216 | |||
| 217 | foreach ($patterns as $pattern) { |
||
| 218 | $values = $arrayUtils->arrayize($attributes[$name]); |
||
| 219 | foreach ($values as $value) { |
||
| 220 | if ($this->regex) { |
||
| 221 | $matched = preg_match($pattern, $value); |
||
| 222 | } else { |
||
| 223 | $matched = ($value === $pattern); |
||
| 224 | } |
||
| 225 | |||
| 226 | if ($matched) { |
||
| 227 | $authorize = ($this->deny ? false : true); |
||
| 228 | array_push($ctx, $name); |
||
| 229 | break 3; |
||
| 230 | } |
||
| 231 | } |
||
| 232 | } |
||
| 233 | } |
||
| 234 | } |
||
| 235 | |||
| 236 | if (!$authorize) { |
||
| 237 | if ($this->show_user_attribute !== null && array_key_exists($this->show_user_attribute, $attributes)) { |
||
| 238 | $userAttribute = $attributes[$this->show_user_attribute][0] ?? null; |
||
| 239 | if ($userAttribute !== null) { |
||
| 240 | $state['authprocAuthorize_user_attribute'] = $userAttribute; |
||
| 241 | } |
||
| 242 | } |
||
| 243 | |||
| 244 | // Try to hint at which attributes may have failed as context for errorURL processing |
||
| 245 | if ($this->deny) { |
||
| 246 | $state['authprocAuthorize_ctx'] = implode(' ', $ctx); |
||
| 247 | } else { |
||
| 248 | $state['authprocAuthorize_ctx'] = implode( |
||
| 249 | ' ', |
||
| 250 | array_diff(array_keys($this->valid_attribute_values), $ctx), |
||
| 251 | ); |
||
| 252 | } |
||
| 253 | $this->unauthorized($state); |
||
| 254 | } |
||
| 279 |