| Conditions | 11 |
| Paths | 73 |
| Total Lines | 53 |
| Code Lines | 34 |
| 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 |
||
| 47 | public function forbidden(Request $request): Template |
||
| 48 | { |
||
| 49 | $stateId = $request->query->get('StateId', false); |
||
| 50 | if (!is_string($stateId)) { |
||
| 51 | throw new Error\BadRequest('Missing required StateId query parameter.'); |
||
| 52 | } |
||
| 53 | |||
| 54 | /** @var array $state */ |
||
| 55 | $state = Auth\State::loadState($stateId, 'authorize:Authorize'); |
||
| 56 | |||
| 57 | $t = new Template($this->config, 'authorize:authorize_403.twig'); |
||
| 58 | if (isset($state['Source']['auth'])) { |
||
| 59 | $t->data['source'] = $state['Source']['auth']; |
||
| 60 | } |
||
| 61 | if (isset($state['authprocAuthorize_reject_msg'])) { |
||
| 62 | $t->data['reject_msg'] = $state['authprocAuthorize_reject_msg']; |
||
| 63 | } |
||
| 64 | |||
| 65 | if (isset($state['Source']['auth'])) { |
||
| 66 | $t->data['LogoutURL'] = Module::getModuleURL( |
||
| 67 | 'core/logout/' . urlencode($state['Source']['auth']), |
||
| 68 | ); |
||
| 69 | } |
||
| 70 | |||
| 71 | $t->data['allow_reauthentication'] = $state['authprocAuthorize_allow_re_authenticate_on_unauthorized'] ?? false; |
||
| 72 | $stateId = Auth\State::saveState($state, 'authorize:Authorize'); |
||
| 73 | $t->data['url_reauthentication'] = |
||
| 74 | Module::getModuleURL('authorize/error/reauthenticate', ['StateId' => $stateId]); |
||
| 75 | |||
| 76 | if ( |
||
| 77 | isset($state['authprocAuthorize_errorURL']) |
||
| 78 | && $state['authprocAuthorize_errorURL'] === true |
||
| 79 | && isset($state['Source']['errorURL']) |
||
| 80 | ) { |
||
| 81 | $errorURL = $state['Source']['errorURL']; |
||
| 82 | $errorURL = str_replace('ERRORURL_CODE', 'AUTHORIZATION_FAILURE', $errorURL); |
||
| 83 | if (isset($state['saml:sp:State']['core:SP'])) { |
||
| 84 | $errorURL = str_replace('ERRORURL_RP', urlencode($state['saml:sp:State']['core:SP']), $errorURL); |
||
| 85 | } |
||
| 86 | if (isset($state['saml:AuthnInstant'])) { |
||
| 87 | $errorURL = str_replace('ERRORURL_TS', $state['saml:AuthnInstant'], $errorURL); |
||
| 88 | } else { |
||
| 89 | $errorURL = str_replace('ERRORURL_TS', strval(time()), $errorURL); |
||
| 90 | } |
||
| 91 | $errorURL = str_replace('ERRORURL_TID', urlencode($this->session->getTrackID()), $errorURL); |
||
| 92 | if (isset($state['authprocAuthorize_ctx'])) { |
||
| 93 | $errorURL = str_replace('ERRORURL_CTX', urlencode($state['authprocAuthorize_ctx']), $errorURL); |
||
| 94 | } |
||
| 95 | $t->data['errorURL'] = $errorURL; |
||
| 96 | } |
||
| 97 | |||
| 98 | $t->setStatusCode(403); |
||
| 99 | return $t; |
||
| 100 | } |
||
| 126 |