| Conditions | 13 |
| Paths | 672 |
| Total Lines | 59 |
| Code Lines | 32 |
| 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 |
||
| 92 | public function logout( |
||
| 93 | Request $request, |
||
| 94 | #[MapQueryParameter] ?string $url = null, |
||
| 95 | #[MapQueryParameter] ?string $service = null, |
||
| 96 | ): Template|RunnableResponse { |
||
| 97 | if (!$this->casConfig->getOptionalValue('enable_logout', false)) { |
||
| 98 | $this->handleExceptionThrown('Logout not allowed'); |
||
| 99 | } |
||
| 100 | |||
| 101 | // note: casv3 says to ignore the casv2 url parameter, however deployments will see a mix of cas v2 and |
||
| 102 | // cas v3 clients so we support both. casv3 makes a query parameter optional |
||
| 103 | $isCasV3 = empty($url); |
||
| 104 | $url = $isCasV3 ? $service : $url; |
||
| 105 | |||
| 106 | // Validate the return $url is valid |
||
| 107 | if (!is_null($url)) { |
||
| 108 | $isValidReturnUrl = !is_null($this->serviceValidator->checkServiceURL($this->sanitize($url))); |
||
| 109 | if (!$isValidReturnUrl) { |
||
| 110 | try { |
||
| 111 | $url = $this->httpUtils->checkURLAllowed($url); |
||
| 112 | $isValidReturnUrl = true; |
||
| 113 | } catch (\Exception $e) { |
||
| 114 | Logger::info('Invalid cas logout url ' . $e->getMessage()); |
||
| 115 | $isValidReturnUrl = false; |
||
| 116 | } |
||
| 117 | } |
||
| 118 | if (!$isValidReturnUrl) { |
||
| 119 | // Protocol does not define behavior if invalid logout url sent |
||
| 120 | // act like no url sent and show logout page |
||
| 121 | Logger::info("Invalid logout url '$url'. Ignoring"); |
||
| 122 | $url = null; |
||
| 123 | } |
||
| 124 | } |
||
| 125 | |||
| 126 | // Skip Logout Page configuration |
||
| 127 | $skipLogoutPage = !is_null($url) && ($isCasV3 || $this->casConfig->getOptionalValue('skip_logout_page', false)); |
||
| 128 | |||
| 129 | |||
| 130 | // Delete the ticket from the session |
||
| 131 | $session = $this->getSession(); |
||
| 132 | if ($session !== null) { |
||
| 133 | $this->ticketStore->deleteTicket($session->getSessionId()); |
||
| 134 | } |
||
| 135 | |||
| 136 | if ($this->authSource->isAuthenticated()) { |
||
| 137 | // Logout and come back here to handle the logout |
||
| 138 | return new RunnableResponse( |
||
| 139 | [$this->authSource, 'logout'], |
||
| 140 | [$this->httpUtils->getSelfURL()], |
||
| 141 | ); |
||
| 142 | } elseif ($skipLogoutPage) { |
||
| 143 | $params = []; |
||
| 144 | return new RunnableResponse([$this->httpUtils, 'redirectTrustedURL'], [$url, $params]); |
||
| 145 | } else { |
||
| 146 | $t = new Template($this->sspConfig, 'casserver:loggedOut.twig'); |
||
| 147 | if ($url) { |
||
| 148 | $t->data['url'] = $url; |
||
| 149 | } |
||
| 150 | return $t; |
||
| 151 | } |
||
| 183 |