Skip to content
Open
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
5 changes: 2 additions & 3 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<files psalm-version="6.13.0@70cdf647255a1362b426bb0f522a85817b8c791c">
<files psalm-version="6.14.3@d0b040a91f280f071c1abcb1b77ce3822058725a">
<file src="app/Config/View.php">
<UndefinedDocblockClass>
<code><![CDATA[array<string, list<parser_callable_string>|parser_callable_string|parser_callable>]]></code>
Expand Down Expand Up @@ -64,8 +64,7 @@
</file>
<file src="system/I18n/TimeTrait.php">
<MissingImmutableAnnotation>
<code><![CDATA[#[ReturnTypeWillChange]]]></code>
<code><![CDATA[#[ReturnTypeWillChange]]]></code>
<code><![CDATA[public function setTimezone($timezone): static]]></code>
</MissingImmutableAnnotation>
</file>
<file src="system/Language/Language.php">
Expand Down
6 changes: 1 addition & 5 deletions system/Cookie/Cookie.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
use CodeIgniter\I18n\Time;
use Config\Cookie as CookieConfig;
use DateTimeInterface;
use ReturnTypeWillChange;

/**
* A `Cookie` class represents an immutable HTTP cookie value object.
Expand Down Expand Up @@ -606,12 +605,9 @@ public function offsetExists($offset): bool
*
* @param string $offset
*
* @return bool|int|string
*
* @throws InvalidArgumentException
*/
#[ReturnTypeWillChange]
public function offsetGet($offset)
public function offsetGet($offset): bool|int|string
{
if (! $this->offsetExists($offset)) {
throw new InvalidArgumentException(sprintf('Undefined offset "%s".', $offset));
Expand Down
4 changes: 1 addition & 3 deletions system/Entity/Entity.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
use DateTimeInterface;
use Exception;
use JsonSerializable;
use ReturnTypeWillChange;
use Traversable;
use UnitEnum;

Expand Down Expand Up @@ -602,8 +601,7 @@ protected function dataCaster(): ?DataCaster
*
* @return array<string, mixed>
*/
#[ReturnTypeWillChange]
public function jsonSerialize()
public function jsonSerialize(): array
{
return $this->toArray();
}
Expand Down
10 changes: 4 additions & 6 deletions system/Files/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
use CodeIgniter\Files\Exceptions\FileNotFoundException;
use CodeIgniter\I18n\Time;
use Config\Mimes;
use ReturnTypeWillChange;
use RuntimeException;
use SplFileInfo;

/**
Expand Down Expand Up @@ -59,13 +59,11 @@ public function __construct(string $path, bool $checkFile = false)
*
* Implementations SHOULD return the value stored in the "size" key of
* the file in the $_FILES array if available, as PHP calculates this based
* on the actual size transmitted. A RuntimeException will be thrown if the file
* does not exist or an error occurs.
* on the actual size transmitted.
*
* @return false|int The file size in bytes, or false on failure
* @throws RuntimeException if the file does not exist or an error occurs
*/
#[ReturnTypeWillChange]
public function getSize()
public function getSize(): false|int
{
return $this->size ?? ($this->size = parent::getSize());
}
Expand Down
6 changes: 1 addition & 5 deletions system/I18n/TimeLegacy.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

use DateTime;
use Exception;
use ReturnTypeWillChange;

/**
* Legacy Time class.
Expand Down Expand Up @@ -55,12 +54,9 @@ class TimeLegacy extends DateTime
*
* @param int $timestamp
*
* @return static
*
* @throws Exception
*/
#[ReturnTypeWillChange]
public function setTimestamp($timestamp)
public function setTimestamp($timestamp): static
{
$time = date('Y-m-d H:i:s', $timestamp);

Expand Down
16 changes: 6 additions & 10 deletions system/I18n/TimeTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
use IntlCalendar;
use IntlDateFormatter;
use Locale;
use ReturnTypeWillChange;

/**
* This trait has properties and methods for Time and TimeLegacy.
Expand Down Expand Up @@ -238,16 +237,15 @@ public static function create(
* Provides a replacement for DateTime's own createFromFormat function, that provides
* more flexible timeZone handling
*
* @psalm-external-mutation-free
*
* @param string $format
* @param string $datetime
* @param DateTimeZone|string|null $timezone
*
* @return static
*
* @throws Exception
*/
#[ReturnTypeWillChange]
public static function createFromFormat($format, $datetime, $timezone = null)
public static function createFromFormat($format, $datetime, $timezone = null): static
{
if (! $date = parent::createFromFormat($format, $datetime)) {
throw I18nException::forInvalidFormat($format);
Expand Down Expand Up @@ -673,16 +671,14 @@ protected function setValue(string $name, $value)
*
* @param DateTimeZone|string $timezone
*
* @return static
*
* @throws Exception
*/
#[ReturnTypeWillChange]
public function setTimezone($timezone)
public function setTimezone($timezone): static
{
$timezone = $timezone instanceof DateTimeZone ? $timezone : new DateTimeZone($timezone);
$dateTime = $this->toDateTime()->setTimezone($timezone);

return static::createFromInstance($this->toDateTime()->setTimezone($timezone), $this->locale);
return static::createFromInstance($dateTime, $this->locale);
}

// --------------------------------------------------------------------
Expand Down
13 changes: 2 additions & 11 deletions system/Session/Handlers/ArrayHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@

namespace CodeIgniter\Session\Handlers;

use ReturnTypeWillChange;

/**
* Session handler using static array for storage.
* Intended only for use during testing.
Expand All @@ -41,12 +39,8 @@ public function open($path, $name): bool
* Reads the session data from the session storage, and returns the results.
*
* @param string $id The session ID.
*
* @return false|string Returns an encoded string of the read data.
* If nothing was read, it must return false.
*/
#[ReturnTypeWillChange]
public function read($id)
public function read($id): string
{
return '';
}
Expand Down Expand Up @@ -85,11 +79,8 @@ public function destroy($id): bool
*
* @param int $max_lifetime Sessions that have not updated
* for the last max_lifetime seconds will be removed.
*
* @return false|int Returns the number of deleted sessions on success, or false on failure.
*/
#[ReturnTypeWillChange]
public function gc($max_lifetime)
public function gc($max_lifetime): int
{
return 1;
}
Expand Down
6 changes: 1 addition & 5 deletions system/Session/Handlers/Database/PostgreHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

use CodeIgniter\Database\BaseBuilder;
use CodeIgniter\Session\Handlers\DatabaseHandler;
use ReturnTypeWillChange;

/**
* Session handler for Postgre
Expand Down Expand Up @@ -59,11 +58,8 @@ protected function prepareData(string $data): string
*
* @param int $max_lifetime Sessions that have not updated
* for the last max_lifetime seconds will be removed.
*
* @return false|int Returns the number of deleted sessions on success, or false on failure.
*/
#[ReturnTypeWillChange]
public function gc($max_lifetime)
public function gc($max_lifetime): false|int
{
$separator = '\'';
$interval = implode($separator, ['', "{$max_lifetime} second", '']);
Expand Down
10 changes: 2 additions & 8 deletions system/Session/Handlers/DatabaseHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
use CodeIgniter\Session\Exceptions\SessionException;
use Config\Database;
use Config\Session as SessionConfig;
use ReturnTypeWillChange;

/**
* Base database session handler.
Expand Down Expand Up @@ -107,12 +106,8 @@ public function open($path, $name): bool
* Reads the session data from the session storage, and returns the results.
*
* @param string $id The session ID
*
* @return false|string Returns an encoded string of the read data.
* If nothing was read, it must return false.
*/
#[ReturnTypeWillChange]
public function read($id)
public function read($id): false|string
{
if ($this->lockSession($id) === false) {
$this->fingerprint = md5('');
Expand Down Expand Up @@ -281,8 +276,7 @@ public function destroy($id): bool
*
* @return false|int Returns the number of deleted sessions on success, or false on failure.
*/
#[ReturnTypeWillChange]
public function gc($max_lifetime)
public function gc($max_lifetime): false|int
{
return $this->db->table($this->table)->where(
'timestamp <',
Expand Down
12 changes: 2 additions & 10 deletions system/Session/Handlers/FileHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
use CodeIgniter\I18n\Time;
use CodeIgniter\Session\Exceptions\SessionException;
use Config\Session as SessionConfig;
use ReturnTypeWillChange;

/**
* Session handler using file system for storage.
Expand Down Expand Up @@ -115,12 +114,8 @@ public function open($path, $name): bool
* Reads the session data from the session storage, and returns the results.
*
* @param string $id The session ID.
*
* @return false|string Returns an encoded string of the read data.
* If nothing was read, it must return false.
*/
#[ReturnTypeWillChange]
public function read($id)
public function read($id): false|string
{
// This might seem weird, but PHP 5.6 introduced session_reset(),
// which re-reads session data
Expand Down Expand Up @@ -267,11 +262,8 @@ public function destroy($id): bool
*
* @param int $max_lifetime Sessions that have not updated
* for the last max_lifetime seconds will be removed.
*
* @return false|int Returns the number of deleted sessions on success, or false on failure.
*/
#[ReturnTypeWillChange]
public function gc($max_lifetime)
public function gc($max_lifetime): false|int
{
if (! is_dir($this->savePath) || ($directory = opendir($this->savePath)) === false) {
$this->logger->debug("Session: Garbage collector couldn't list files under directory '" . $this->savePath . "'.");
Expand Down
12 changes: 2 additions & 10 deletions system/Session/Handlers/MemcachedHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
use CodeIgniter\Session\Exceptions\SessionException;
use Config\Session as SessionConfig;
use Memcached;
use ReturnTypeWillChange;

/**
* Session handler using Memcached for persistence.
Expand Down Expand Up @@ -138,12 +137,8 @@ public function open($path, $name): bool
* Reads the session data from the session storage, and returns the results.
*
* @param string $id The session ID.
*
* @return false|string Returns an encoded string of the read data.
* If nothing was read, it must return false.
*/
#[ReturnTypeWillChange]
public function read($id)
public function read($id): false|string
{
if (isset($this->memcached) && $this->lockSession($id)) {
if (! isset($this->sessionID)) {
Expand Down Expand Up @@ -243,11 +238,8 @@ public function destroy($id): bool
*
* @param int $max_lifetime Sessions that have not updated
* for the last max_lifetime seconds will be removed.
*
* @return false|int Returns the number of deleted sessions on success, or false on failure.
*/
#[ReturnTypeWillChange]
public function gc($max_lifetime)
public function gc($max_lifetime): int
{
return 1;
}
Expand Down
12 changes: 2 additions & 10 deletions system/Session/Handlers/RedisHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
use Config\Session as SessionConfig;
use Redis;
use RedisException;
use ReturnTypeWillChange;

/**
* Session handler using Redis for persistence.
Expand Down Expand Up @@ -204,13 +203,9 @@ public function open($path, $name): bool
*
* @param string $id The session ID.
*
* @return false|string Returns an encoded string of the read data.
* If nothing was read, it must return false.
*
* @throws RedisException
*/
#[ReturnTypeWillChange]
public function read($id)
public function read($id): false|string
{
if (isset($this->redis) && $this->lockSession($id)) {
if (! isset($this->sessionID)) {
Expand Down Expand Up @@ -333,11 +328,8 @@ public function destroy($id): bool
*
* @param int $max_lifetime Sessions that have not updated
* for the last max_lifetime seconds will be removed.
*
* @return false|int Returns the number of deleted sessions on success, or false on failure.
*/
#[ReturnTypeWillChange]
public function gc($max_lifetime)
public function gc($max_lifetime): int
{
return 1;
}
Expand Down
18 changes: 18 additions & 0 deletions user_guide_src/source/changelogs/v4.7.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,24 @@ Method Signature Changes
- Added native return types to ``CodeIgniter\Debug\Toolbar`` methods:
- ``prepare(): void``
- ``respond(): void``
- Methods previously having ``#[ReturnTypeWillChange]`` attribute have been updated to include the native return types:
- ``CodeIgniter\Cookie\Cookie::offsetGet($offset): bool|int|string``
- ``CodeIgniter\Entity\Entity::jsonSerialize(): array``
- ``CodeIgniter\Files\File::getSize(): false|int``
- ``CodeIgniter\I18n\TimeLegacy::setTimestamp($timestamp): static``
- ``CodeIgniter\I18n\TimeTrait::createFromFormat($format, $time, $timezone = null): static``
- ``CodeIgniter\I18n\TimeTrait::setTimezone($timezone): static``
- ``CodeIgniter\Session\Handlers\Database\PostgreHandler::gc($max_lifetime): false|int``
- ``CodeIgniter\Session\Handlers\ArrayHandler::read($id): string``
- ``CodeIgniter\Session\Handlers\ArrayHandler::gc($max_lifetime): int``
- ``CodeIgniter\Session\Handlers\DatabaseHandler::read($id): false|string``
- ``CodeIgniter\Session\Handlers\DatabaseHandler::gc($max_lifetime): false|int``
- ``CodeIgniter\Session\Handlers\FileHandler::read($id): false|string``
- ``CodeIgniter\Session\Handlers\FileHandler::gc($max_lifetime): false|int``
- ``CodeIgniter\Session\Handlers\MemcachedHandler::read($id): false|string``
- ``CodeIgniter\Session\Handlers\MemcachedHandler::gc($max_lifetime): int``
- ``CodeIgniter\Session\Handlers\RedisHandler::read($id): false|string``
- ``CodeIgniter\Session\Handlers\RedisHandler::gc($max_lifetime): int``

Property Signature Changes
==========================
Expand Down
Loading