diff --git a/system/Session/Session.php b/system/Session/Session.php index 05d0011dabdc..0540c1508a9e 100644 --- a/system/Session/Session.php +++ b/system/Session/Session.php @@ -233,7 +233,8 @@ public function start() $this->setSaveHandler(); // Sanitize the cookie, because apparently PHP doesn't do that for userspace handlers - if (isset($_COOKIE[$this->config->cookieName]) + if ( + isset($_COOKIE[$this->config->cookieName]) && (! is_string($_COOKIE[$this->config->cookieName]) || preg_match('#\A' . $this->sidRegexp . '\z#', $_COOKIE[$this->config->cookieName]) !== 1) ) { unset($_COOKIE[$this->config->cookieName]); @@ -267,6 +268,8 @@ public function start() * Destroys the current session. * * @deprecated Use destroy() instead. + * + * @return void */ public function stop() { @@ -277,6 +280,8 @@ public function stop() * Configuration. * * Handle input binds and configuration defaults. + * + * @return void */ protected function configure() { @@ -318,6 +323,8 @@ protected function configure() * * To make life easier, we force the PHP defaults. Because PHP9 forces them. * See https://wiki.php.net/rfc/deprecations_php_8_4#sessionsid_length_and_sessionsid_bits_per_character + * + * @return void */ protected function configureSidLength() { @@ -342,6 +349,8 @@ protected function configureSidLength() * * Clears old "flash" data, marks the new one for deletion and handles * "temp" data deletion. + * + * @return void */ protected function initVars() { @@ -370,6 +379,8 @@ protected function initVars() * Regenerates the session ID. * * @param bool $destroy Should old session data be destroyed? + * + * @return void */ public function regenerate(bool $destroy = false) { @@ -401,6 +412,8 @@ private function removeOldSessionCookie(): void /** * Destroys the current session. + * + * @return void */ public function destroy() { @@ -436,6 +449,8 @@ public function close() * * @param array|string $data Property name or associative array of properties * @param array|bool|float|int|object|string|null $value Property value if single key provided + * + * @return void */ public function set($data, $value = null) { @@ -510,6 +525,8 @@ public function has(string $key): bool * * @param string $key Identifier of the session property we are interested in. * @param array $data value to be pushed to existing session key. + * + * @return void */ public function push(string $key, array $data) { @@ -526,6 +543,8 @@ public function push(string $key, array $data) * of a specific session property to remove. * * @param array|string $key Identifier of the session property or properties to remove. + * + * @return void */ public function remove($key) { @@ -598,6 +617,8 @@ public function __isset(string $key): bool * * @param array|string $data Property identifier or associative array of properties * @param array|bool|float|int|object|string|null $value Property value if $data is a scalar + * + * @return void */ public function setFlashdata($data, $value = null) { @@ -638,6 +659,8 @@ public function getFlashdata(?string $key = null) * Keeps a single piece of flash data alive for one more request. * * @param array|string $key Property identifier or array of them + * + * @return void */ public function keepFlashdata($key) { @@ -680,6 +703,8 @@ public function markAsFlashdata($key): bool * Unmark data in the session as flashdata. * * @param array|string $key Property identifier or array of them + * + * @return void */ public function unmarkFlashdata($key) { @@ -731,6 +756,8 @@ public function getFlashKeys(): array * @param array|string $data Session data key or associative array of items * @param array|bool|float|int|object|string|null $value Value to store * @param int $ttl Time-to-live in seconds + * + * @return void */ public function setTempdata($data, $value = null, int $ttl = 300) { @@ -750,7 +777,7 @@ public function getTempdata(?string $key = null) { if (isset($key)) { return (isset($_SESSION['__ci_vars'], $_SESSION['__ci_vars'][$key], $_SESSION[$key]) - && is_int($_SESSION['__ci_vars'][$key])) ? $_SESSION[$key] : null; + && is_int($_SESSION['__ci_vars'][$key])) ? $_SESSION[$key] : null; } $tempdata = []; @@ -770,6 +797,8 @@ public function getTempdata(?string $key = null) * Removes a single piece of temporary data from the session. * * @param string $key Session data key + * + * @return void */ public function removeTempdata(string $key) { @@ -830,6 +859,8 @@ public function markAsTempdata($key, int $ttl = 300): bool * lifespan and allowing it to live as long as the session does. * * @param array|string $key Property identifier or array of them + * + * @return void */ public function unmarkTempdata($key) { @@ -875,6 +906,8 @@ public function getTempKeys(): array /** * Sets the driver as the session handler in PHP. * Extracted for easier testing. + * + * @return void */ protected function setSaveHandler() { @@ -884,6 +917,8 @@ protected function setSaveHandler() /** * Starts the session. * Extracted for testing reasons. + * + * @return void */ protected function startSession() { @@ -900,6 +935,8 @@ protected function startSession() * Takes care of setting the cookie on the client side. * * @codeCoverageIgnore + * + * @return void */ protected function setCookie() { diff --git a/system/Session/SessionInterface.php b/system/Session/SessionInterface.php index 3ed61664a952..4efc6f78bed4 100644 --- a/system/Session/SessionInterface.php +++ b/system/Session/SessionInterface.php @@ -22,11 +22,15 @@ interface SessionInterface * Regenerates the session ID. * * @param bool $destroy Should old session data be destroyed? + * + * @return void */ public function regenerate(bool $destroy = false); /** * Destroys the current session. + * + * @return void */ public function destroy(); @@ -41,6 +45,8 @@ public function destroy(); * * @param array|string $data Property name or associative array of properties * @param array|bool|float|int|object|string|null $value Property value if single key provided + * + * @return void */ public function set($data, $value = null); @@ -74,6 +80,8 @@ public function has(string $key): bool; * of a specific session property to remove. * * @param array|string $key Identifier of the session property or properties to remove. + * + * @return void */ public function remove($key); @@ -88,6 +96,8 @@ public function remove($key); * * @param array|string $data Property identifier or associative array of properties * @param array|string $value Property value if $data is a scalar + * + * @return void */ public function setFlashdata($data, $value = null); @@ -107,6 +117,8 @@ public function getFlashdata(?string $key = null); * Keeps a single piece of flash data alive for one more request. * * @param array|string $key Property identifier or array of them + * + * @return void */ public function keepFlashdata($key); @@ -123,6 +135,8 @@ public function markAsFlashdata($key); * Unmark data in the session as flashdata. * * @param array|string $key Property identifier or array of them + * + * @return void */ public function unmarkFlashdata($key); @@ -140,6 +154,8 @@ public function getFlashKeys(): array; * @param array|string $data Session data key or associative array of items * @param array|bool|float|int|object|string|null $value Value to store * @param int $ttl Time-to-live in seconds + * + * @return void */ public function setTempdata($data, $value = null, int $ttl = 300); @@ -157,6 +173,8 @@ public function getTempdata(?string $key = null); * Removes a single piece of temporary data from the session. * * @param string $key Session data key + * + * @return void */ public function removeTempdata(string $key); @@ -176,6 +194,8 @@ public function markAsTempdata($key, int $ttl = 300); * lifespan and allowing it to live as long as the session does. * * @param array|string $key Property identifier or array of them + * + * @return void */ public function unmarkTempdata($key); diff --git a/system/Test/Mock/MockSession.php b/system/Test/Mock/MockSession.php index 37cdc76111b0..13eca596c9c7 100644 --- a/system/Test/Mock/MockSession.php +++ b/system/Test/Mock/MockSession.php @@ -37,6 +37,8 @@ class MockSession extends Session /** * Sets the driver as the session handler in PHP. * Extracted for easier testing. + * + * @return void */ protected function setSaveHandler() { @@ -46,6 +48,8 @@ protected function setSaveHandler() /** * Starts the session. * Extracted for testing reasons. + * + * @return void */ protected function startSession() { @@ -56,6 +60,8 @@ protected function startSession() /** * Takes care of setting the cookie on the client side. * Extracted for testing reasons. + * + * @return void */ protected function setCookie() { @@ -65,6 +71,11 @@ protected function setCookie() $this->cookies[] = $this->cookie; } + /** + * Regenerates the session ID. + * + * @return void + */ public function regenerate(bool $destroy = false) { $this->didRegenerate = true; diff --git a/utils/phpstan-baseline/loader.neon b/utils/phpstan-baseline/loader.neon index 26b6e972f13e..659f4a2858d1 100644 --- a/utils/phpstan-baseline/loader.neon +++ b/utils/phpstan-baseline/loader.neon @@ -1,4 +1,4 @@ -# total 3573 errors +# total 3541 errors includes: - argument.type.neon - assign.propertyType.neon diff --git a/utils/phpstan-baseline/missingType.return.neon b/utils/phpstan-baseline/missingType.return.neon index 693842b12755..b40d9e062576 100644 --- a/utils/phpstan-baseline/missingType.return.neon +++ b/utils/phpstan-baseline/missingType.return.neon @@ -1,4 +1,4 @@ -# total 150 errors +# total 118 errors parameters: ignoreErrors: @@ -227,146 +227,6 @@ parameters: count: 1 path: ../../system/Session/Handlers/FileHandler.php - - - message: '#^Method CodeIgniter\\Session\\Session\:\:configure\(\) has no return type specified\.$#' - count: 1 - path: ../../system/Session/Session.php - - - - message: '#^Method CodeIgniter\\Session\\Session\:\:configureSidLength\(\) has no return type specified\.$#' - count: 1 - path: ../../system/Session/Session.php - - - - message: '#^Method CodeIgniter\\Session\\Session\:\:destroy\(\) has no return type specified\.$#' - count: 1 - path: ../../system/Session/Session.php - - - - message: '#^Method CodeIgniter\\Session\\Session\:\:initVars\(\) has no return type specified\.$#' - count: 1 - path: ../../system/Session/Session.php - - - - message: '#^Method CodeIgniter\\Session\\Session\:\:keepFlashdata\(\) has no return type specified\.$#' - count: 1 - path: ../../system/Session/Session.php - - - - message: '#^Method CodeIgniter\\Session\\Session\:\:push\(\) has no return type specified\.$#' - count: 1 - path: ../../system/Session/Session.php - - - - message: '#^Method CodeIgniter\\Session\\Session\:\:regenerate\(\) has no return type specified\.$#' - count: 1 - path: ../../system/Session/Session.php - - - - message: '#^Method CodeIgniter\\Session\\Session\:\:remove\(\) has no return type specified\.$#' - count: 1 - path: ../../system/Session/Session.php - - - - message: '#^Method CodeIgniter\\Session\\Session\:\:removeTempdata\(\) has no return type specified\.$#' - count: 1 - path: ../../system/Session/Session.php - - - - message: '#^Method CodeIgniter\\Session\\Session\:\:set\(\) has no return type specified\.$#' - count: 1 - path: ../../system/Session/Session.php - - - - message: '#^Method CodeIgniter\\Session\\Session\:\:setCookie\(\) has no return type specified\.$#' - count: 1 - path: ../../system/Session/Session.php - - - - message: '#^Method CodeIgniter\\Session\\Session\:\:setFlashdata\(\) has no return type specified\.$#' - count: 1 - path: ../../system/Session/Session.php - - - - message: '#^Method CodeIgniter\\Session\\Session\:\:setSaveHandler\(\) has no return type specified\.$#' - count: 1 - path: ../../system/Session/Session.php - - - - message: '#^Method CodeIgniter\\Session\\Session\:\:setTempdata\(\) has no return type specified\.$#' - count: 1 - path: ../../system/Session/Session.php - - - - message: '#^Method CodeIgniter\\Session\\Session\:\:startSession\(\) has no return type specified\.$#' - count: 1 - path: ../../system/Session/Session.php - - - - message: '#^Method CodeIgniter\\Session\\Session\:\:stop\(\) has no return type specified\.$#' - count: 1 - path: ../../system/Session/Session.php - - - - message: '#^Method CodeIgniter\\Session\\Session\:\:unmarkFlashdata\(\) has no return type specified\.$#' - count: 1 - path: ../../system/Session/Session.php - - - - message: '#^Method CodeIgniter\\Session\\Session\:\:unmarkTempdata\(\) has no return type specified\.$#' - count: 1 - path: ../../system/Session/Session.php - - - - message: '#^Method CodeIgniter\\Session\\SessionInterface\:\:destroy\(\) has no return type specified\.$#' - count: 1 - path: ../../system/Session/SessionInterface.php - - - - message: '#^Method CodeIgniter\\Session\\SessionInterface\:\:keepFlashdata\(\) has no return type specified\.$#' - count: 1 - path: ../../system/Session/SessionInterface.php - - - - message: '#^Method CodeIgniter\\Session\\SessionInterface\:\:regenerate\(\) has no return type specified\.$#' - count: 1 - path: ../../system/Session/SessionInterface.php - - - - message: '#^Method CodeIgniter\\Session\\SessionInterface\:\:remove\(\) has no return type specified\.$#' - count: 1 - path: ../../system/Session/SessionInterface.php - - - - message: '#^Method CodeIgniter\\Session\\SessionInterface\:\:removeTempdata\(\) has no return type specified\.$#' - count: 1 - path: ../../system/Session/SessionInterface.php - - - - message: '#^Method CodeIgniter\\Session\\SessionInterface\:\:set\(\) has no return type specified\.$#' - count: 1 - path: ../../system/Session/SessionInterface.php - - - - message: '#^Method CodeIgniter\\Session\\SessionInterface\:\:setFlashdata\(\) has no return type specified\.$#' - count: 1 - path: ../../system/Session/SessionInterface.php - - - - message: '#^Method CodeIgniter\\Session\\SessionInterface\:\:setTempdata\(\) has no return type specified\.$#' - count: 1 - path: ../../system/Session/SessionInterface.php - - - - message: '#^Method CodeIgniter\\Session\\SessionInterface\:\:unmarkFlashdata\(\) has no return type specified\.$#' - count: 1 - path: ../../system/Session/SessionInterface.php - - - - message: '#^Method CodeIgniter\\Session\\SessionInterface\:\:unmarkTempdata\(\) has no return type specified\.$#' - count: 1 - path: ../../system/Session/SessionInterface.php - - message: '#^Method CodeIgniter\\Test\\CIUnitTestCase\:\:assertCloseEnough\(\) has no return type specified\.$#' count: 1 @@ -482,26 +342,6 @@ parameters: count: 1 path: ../../system/Test/Mock/MockResponse.php - - - message: '#^Method CodeIgniter\\Test\\Mock\\MockSession\:\:regenerate\(\) has no return type specified\.$#' - count: 1 - path: ../../system/Test/Mock/MockSession.php - - - - message: '#^Method CodeIgniter\\Test\\Mock\\MockSession\:\:setCookie\(\) has no return type specified\.$#' - count: 1 - path: ../../system/Test/Mock/MockSession.php - - - - message: '#^Method CodeIgniter\\Test\\Mock\\MockSession\:\:setSaveHandler\(\) has no return type specified\.$#' - count: 1 - path: ../../system/Test/Mock/MockSession.php - - - - message: '#^Method CodeIgniter\\Test\\Mock\\MockSession\:\:startSession\(\) has no return type specified\.$#' - count: 1 - path: ../../system/Test/Mock/MockSession.php - - message: '#^Method CodeIgniter\\Test\\Mock\\MockTable\:\:__call\(\) has no return type specified\.$#' count: 1