From 1640cb68afad9624d6b27d1ae1a0a708d54a73ea Mon Sep 17 00:00:00 2001 From: warcooft Date: Mon, 14 Apr 2025 15:45:38 +0700 Subject: [PATCH 1/3] update total errors --- system/Session/Session.php | 41 ++++- system/Session/SessionInterface.php | 20 +++ system/Test/Mock/MockSession.php | 11 ++ utils/phpstan-baseline/loader.neon | 2 +- .../phpstan-baseline/missingType.return.neon | 162 +----------------- 5 files changed, 72 insertions(+), 164 deletions(-) diff --git a/system/Session/Session.php b/system/Session/Session.php index 05d0011dabdc..7a5a23bd706e 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..ed52f9079f6a 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..1e6ea40e63ea 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 From b6110c0041f264b388895241d7ceb44cde5e90e9 Mon Sep 17 00:00:00 2001 From: warcooft Date: Mon, 14 Apr 2025 08:03:12 +0700 Subject: [PATCH 2/3] Replacing return type with @return docblock --- system/Session/SessionInterface.php | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/system/Session/SessionInterface.php b/system/Session/SessionInterface.php index ed52f9079f6a..4efc6f78bed4 100644 --- a/system/Session/SessionInterface.php +++ b/system/Session/SessionInterface.php @@ -22,14 +22,14 @@ 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(); @@ -45,7 +45,7 @@ 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); @@ -80,7 +80,7 @@ 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); @@ -96,7 +96,7 @@ 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); @@ -117,7 +117,7 @@ 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); @@ -135,7 +135,7 @@ 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); @@ -154,7 +154,7 @@ 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); @@ -173,7 +173,7 @@ 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); @@ -194,7 +194,7 @@ 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); From f57b12a631ba761da4e9eb18eb2a960cc1a0d016 Mon Sep 17 00:00:00 2001 From: warcooft Date: Mon, 14 Apr 2025 08:10:22 +0700 Subject: [PATCH 3/3] Replacing return type with @return docblock --- system/Session/Session.php | 36 ++++++++++++++++---------------- system/Test/Mock/MockSession.php | 8 +++---- 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/system/Session/Session.php b/system/Session/Session.php index 7a5a23bd706e..0540c1508a9e 100644 --- a/system/Session/Session.php +++ b/system/Session/Session.php @@ -268,7 +268,7 @@ public function start() * Destroys the current session. * * @deprecated Use destroy() instead. - * + * * @return void */ public function stop() @@ -280,7 +280,7 @@ public function stop() * Configuration. * * Handle input binds and configuration defaults. - * + * * @return void */ protected function configure() @@ -323,7 +323,7 @@ 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() @@ -349,7 +349,7 @@ protected function configureSidLength() * * Clears old "flash" data, marks the new one for deletion and handles * "temp" data deletion. - * + * * @return void */ protected function initVars() @@ -379,7 +379,7 @@ protected function initVars() * Regenerates the session ID. * * @param bool $destroy Should old session data be destroyed? - * + * * @return void */ public function regenerate(bool $destroy = false) @@ -412,7 +412,7 @@ private function removeOldSessionCookie(): void /** * Destroys the current session. - * + * * @return void */ public function destroy() @@ -449,7 +449,7 @@ 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) @@ -525,7 +525,7 @@ 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) @@ -543,7 +543,7 @@ 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) @@ -617,7 +617,7 @@ 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) @@ -659,7 +659,7 @@ 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) @@ -703,7 +703,7 @@ 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) @@ -756,7 +756,7 @@ 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) @@ -797,7 +797,7 @@ 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) @@ -859,7 +859,7 @@ 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) @@ -906,7 +906,7 @@ public function getTempKeys(): array /** * Sets the driver as the session handler in PHP. * Extracted for easier testing. - * + * * @return void */ protected function setSaveHandler() @@ -917,7 +917,7 @@ protected function setSaveHandler() /** * Starts the session. * Extracted for testing reasons. - * + * * @return void */ protected function startSession() @@ -935,7 +935,7 @@ protected function startSession() * Takes care of setting the cookie on the client side. * * @codeCoverageIgnore - * + * * @return void */ protected function setCookie() diff --git a/system/Test/Mock/MockSession.php b/system/Test/Mock/MockSession.php index 1e6ea40e63ea..13eca596c9c7 100644 --- a/system/Test/Mock/MockSession.php +++ b/system/Test/Mock/MockSession.php @@ -37,7 +37,7 @@ class MockSession extends Session /** * Sets the driver as the session handler in PHP. * Extracted for easier testing. - * + * * @return void */ protected function setSaveHandler() @@ -48,7 +48,7 @@ protected function setSaveHandler() /** * Starts the session. * Extracted for testing reasons. - * + * * @return void */ protected function startSession() @@ -60,7 +60,7 @@ protected function startSession() /** * Takes care of setting the cookie on the client side. * Extracted for testing reasons. - * + * * @return void */ protected function setCookie() @@ -73,7 +73,7 @@ protected function setCookie() /** * Regenerates the session ID. - * + * * @return void */ public function regenerate(bool $destroy = false)