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 |
||
92 | public function destroy($sessionId) |
||
93 | { |
||
94 | if (\PHP_VERSION_ID < 70000) { |
||
95 | $this->prefetchData = null; |
||
96 | } |
||
97 | if (!headers_sent() && filter_var(ini_get('session.use_cookies'), FILTER_VALIDATE_BOOLEAN)) { |
||
98 | if (!$this->sessionName) { |
||
99 | throw new \LogicException(sprintf('Session name cannot be empty, did you forget to call "parent::open()" in "%s"?.', \get_class($this))); |
||
100 | } |
||
101 | $sessionCookie = sprintf(' %s=', urlencode($this->sessionName)); |
||
102 | $sessionCookieWithId = sprintf('%s%s;', $sessionCookie, urlencode($sessionId)); |
||
103 | $sessionCookieFound = false; |
||
104 | $otherCookies = []; |
||
105 | foreach (headers_list() as $h) { |
||
106 | if (0 !== stripos($h, 'Set-Cookie:')) { |
||
107 | continue; |
||
108 | } |
||
109 | if (11 === strpos($h, $sessionCookie, 11)) { |
||
110 | $sessionCookieFound = true; |
||
111 | |||
112 | if (11 !== strpos($h, $sessionCookieWithId, 11)) { |
||
113 | $otherCookies[] = $h; |
||
114 | } |
||
115 | } else { |
||
116 | $otherCookies[] = $h; |
||
117 | } |
||
118 | } |
||
119 | if ($sessionCookieFound) { |
||
120 | header_remove('Set-Cookie'); |
||
121 | foreach ($otherCookies as $h) { |
||
122 | header($h, false); |
||
123 | } |
||
124 | } else { |
||
125 | if (\PHP_VERSION_ID < 70300) { |
||
126 | 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)); |
||
127 | } else { |
||
128 | setcookie($this->sessionName, '', |
||
129 | [ |
||
130 | 'expires' => 0, |
||
131 | 'path' => $this->getCookiePath(), |
||
132 | 'domain' => ini_get('session.cookie_domain'), |
||
133 | 'secure' => filter_var(ini_get('session.cookie_secure'), FILTER_VALIDATE_BOOLEAN), |
||
134 | 'httponly' => filter_var(ini_get('session.cookie_httponly'), FILTER_VALIDATE_BOOLEAN), |
||
135 | 'samesite' => $this->getCookieSameSite(), |
||
136 | ] |
||
137 | ); |
||
138 | } |
||
139 | } |
||
140 | } |
||
141 | |||
142 | return $this->newSessionId === $sessionId || $this->doDestroy($sessionId); |
||
143 | } |
||
144 | |||
214 |