Skip to content

refactor: fix missingType.return errors #9523

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 39 additions & 2 deletions system/Session/Session.php
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand Down Expand Up @@ -267,6 +268,8 @@ public function start()
* Destroys the current session.
*
* @deprecated Use destroy() instead.
*
* @return void
*/
public function stop()
{
Expand All @@ -277,6 +280,8 @@ public function stop()
* Configuration.
*
* Handle input binds and configuration defaults.
*
* @return void
*/
protected function configure()
{
Expand Down Expand Up @@ -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()
{
Expand All @@ -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()
{
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -401,6 +412,8 @@ private function removeOldSessionCookie(): void

/**
* Destroys the current session.
*
* @return void
*/
public function destroy()
{
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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)
{
Expand All @@ -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)
{
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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)
{
Expand All @@ -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 = [];
Expand All @@ -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)
{
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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()
{
Expand All @@ -884,6 +917,8 @@ protected function setSaveHandler()
/**
* Starts the session.
* Extracted for testing reasons.
*
* @return void
*/
protected function startSession()
{
Expand All @@ -900,6 +935,8 @@ protected function startSession()
* Takes care of setting the cookie on the client side.
*
* @codeCoverageIgnore
*
* @return void
*/
protected function setCookie()
{
Expand Down
20 changes: 20 additions & 0 deletions system/Session/SessionInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -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);

Expand Down Expand Up @@ -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);

Expand All @@ -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);

Expand All @@ -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);

Expand All @@ -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);

Expand All @@ -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);

Expand All @@ -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);

Expand All @@ -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);

Expand Down
11 changes: 11 additions & 0 deletions system/Test/Mock/MockSession.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand All @@ -46,6 +48,8 @@ protected function setSaveHandler()
/**
* Starts the session.
* Extracted for testing reasons.
*
* @return void
*/
protected function startSession()
{
Expand All @@ -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()
{
Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion utils/phpstan-baseline/loader.neon
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# total 3573 errors
# total 3541 errors
includes:
- argument.type.neon
- assign.propertyType.neon
Expand Down
Loading
Loading