| Conditions | 13 |
| Paths | 18 |
| Total Lines | 52 |
| 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 |
||
| 29 | public function destroy($sessionId) |
||
| 30 | { |
||
| 31 | if (\PHP_VERSION_ID < 70000) { |
||
| 32 | $this->prefetchData = null; |
||
| 33 | } |
||
| 34 | if (!headers_sent() && filter_var(ini_get('session.use_cookies'), FILTER_VALIDATE_BOOLEAN)) { |
||
| 35 | if (!$this->sessionName) { |
||
| 36 | throw new \LogicException(sprintf('Session name cannot be empty, did you forget to call "parent::open()" in "%s"?.', \get_class($this))); |
||
| 37 | } |
||
| 38 | $sessionCookie = sprintf(' %s=', urlencode($this->sessionName)); |
||
| 39 | $sessionCookieWithId = sprintf('%s%s;', $sessionCookie, urlencode($sessionId)); |
||
| 40 | $sessionCookieFound = false; |
||
| 41 | $otherCookies = []; |
||
| 42 | foreach (headers_list() as $h) { |
||
| 43 | if (0 !== stripos($h, 'Set-Cookie:')) { |
||
| 44 | continue; |
||
| 45 | } |
||
| 46 | if (11 === strpos($h, $sessionCookie, 11)) { |
||
| 47 | $sessionCookieFound = true; |
||
| 48 | |||
| 49 | if (11 !== strpos($h, $sessionCookieWithId, 11)) { |
||
| 50 | $otherCookies[] = $h; |
||
| 51 | } |
||
| 52 | } else { |
||
| 53 | $otherCookies[] = $h; |
||
| 54 | } |
||
| 55 | } |
||
| 56 | if ($sessionCookieFound) { |
||
| 57 | header_remove('Set-Cookie'); |
||
| 58 | foreach ($otherCookies as $h) { |
||
| 59 | header($h, false); |
||
| 60 | } |
||
| 61 | } else { |
||
| 62 | if (\PHP_VERSION_ID < 70300) { |
||
| 63 | setcookie($this->sessionName, '', 0, ini_get('session.cookie_path'), ini_get('session.cookie_domain'), filter_var(ini_get('session.cookie_secure'), FILTER_VALIDATE_BOOLEAN), filter_var(ini_get('session.cookie_httponly'), FILTER_VALIDATE_BOOLEAN)); |
||
| 64 | } else { |
||
| 65 | setcookie($this->sessionName, '', |
||
| 66 | [ |
||
| 67 | 'expires' => 0, |
||
| 68 | 'path' => '/', // TODO |
||
| 69 | 'domain' => ini_get('session.cookie_domain'), |
||
| 70 | 'secure' => filter_var(ini_get('session.cookie_secure'), FILTER_VALIDATE_BOOLEAN), |
||
| 71 | 'httponly' => filter_var(ini_get('session.cookie_httponly'), FILTER_VALIDATE_BOOLEAN), |
||
| 72 | 'samesite' => 'None' // TODO UA で分岐する |
||
| 73 | ] |
||
| 74 | ); |
||
| 75 | } |
||
| 76 | } |
||
| 77 | } |
||
| 78 | |||
| 79 | return $this->newSessionId === $sessionId || $this->doDestroy($sessionId); |
||
| 80 | } |
||
| 81 | } |
||
| 82 |