diff --git a/phpstan-baseline.php b/phpstan-baseline.php index f0a882e68b01..bc4dd8e95716 100644 --- a/phpstan-baseline.php +++ b/phpstan-baseline.php @@ -7555,12 +7555,6 @@ 'count' => 1, 'path' => __DIR__ . '/system/I18n/Time.php', ]; -$ignoreErrors[] = [ - // identifier: method.childReturnType - 'message' => '#^Return type \\(CodeIgniter\\\\I18n\\\\Time\\) of method CodeIgniter\\\\I18n\\\\Time\\:\\:setTimezone\\(\\) should be covariant with return type \\(static\\(DateTimeImmutable\\)\\) of method DateTimeImmutable\\:\\:setTimezone\\(\\)$#', - 'count' => 1, - 'path' => __DIR__ . '/system/I18n/Time.php', -]; $ignoreErrors[] = [ // identifier: ternary.shortNotAllowed 'message' => '#^Short ternary operator is not allowed\\. Use null coalesce operator if applicable or consider using long ternary\\.$#', @@ -7579,12 +7573,6 @@ 'count' => 1, 'path' => __DIR__ . '/system/I18n/TimeLegacy.php', ]; -$ignoreErrors[] = [ - // identifier: method.childReturnType - 'message' => '#^Return type \\(CodeIgniter\\\\I18n\\\\TimeLegacy\\) of method CodeIgniter\\\\I18n\\\\TimeLegacy\\:\\:setTimezone\\(\\) should be covariant with return type \\(static\\(DateTime\\)\\) of method DateTime\\:\\:setTimezone\\(\\)$#', - 'count' => 1, - 'path' => __DIR__ . '/system/I18n/TimeLegacy.php', -]; $ignoreErrors[] = [ // identifier: ternary.shortNotAllowed 'message' => '#^Short ternary operator is not allowed\\. Use null coalesce operator if applicable or consider using long ternary\\.$#', diff --git a/system/I18n/Time.php b/system/I18n/Time.php index 906479470b17..255f879a90ec 100644 --- a/system/I18n/Time.php +++ b/system/I18n/Time.php @@ -39,6 +39,8 @@ * @property-read string $weekOfYear * @property-read string $year * + * @phpstan-consistent-constructor + * * @see \CodeIgniter\I18n\TimeTest */ class Time extends DateTimeImmutable implements Stringable diff --git a/system/I18n/TimeLegacy.php b/system/I18n/TimeLegacy.php index 403fced2108d..b62877ec40d6 100644 --- a/system/I18n/TimeLegacy.php +++ b/system/I18n/TimeLegacy.php @@ -39,6 +39,8 @@ * @property string $weekOfYear read-only * @property string $year read-only * + * @phpstan-consistent-constructor + * * @deprecated Use Time instead. * @see \CodeIgniter\I18n\TimeLegacyTest */ diff --git a/system/I18n/TimeTrait.php b/system/I18n/TimeTrait.php index fefb2fc544a3..0f02ef8820b8 100644 --- a/system/I18n/TimeTrait.php +++ b/system/I18n/TimeTrait.php @@ -261,13 +261,11 @@ public static function createFromFormat($format, $datetime, $timezone = null) * * @param DateTimeZone|string|null $timezone * - * @return self - * * @throws Exception */ - public static function createFromTimestamp(int $timestamp, $timezone = null, ?string $locale = null) + public static function createFromTimestamp(float|int $timestamp, $timezone = null, ?string $locale = null): static { - $time = new self(gmdate('Y-m-d H:i:s', $timestamp), 'UTC', $locale); + $time = new static(gmdate('Y-m-d H:i:s', $timestamp), 'UTC', $locale); $timezone ??= date_default_timezone_get(); @@ -277,7 +275,7 @@ public static function createFromTimestamp(int $timestamp, $timezone = null, ?st /** * Takes an instance of DateTimeInterface and returns an instance of Time with it's same values. * - * @return self + * @return static * * @throws Exception */ @@ -286,7 +284,7 @@ public static function createFromInstance(DateTimeInterface $dateTime, ?string $ $date = $dateTime->format('Y-m-d H:i:s'); $timezone = $dateTime->getTimezone(); - return new self($date, $timezone, $locale); + return new static($date, $timezone, $locale); } /** @@ -674,7 +672,7 @@ protected function setValue(string $name, $value) * * @param DateTimeZone|string $timezone * - * @return self + * @return static * * @throws Exception */ @@ -683,7 +681,7 @@ public function setTimezone($timezone) { $timezone = $timezone instanceof DateTimeZone ? $timezone : new DateTimeZone($timezone); - return self::createFromInstance($this->toDateTime()->setTimezone($timezone), $this->locale); + return static::createFromInstance($this->toDateTime()->setTimezone($timezone), $this->locale); } /** diff --git a/user_guide_src/source/changelogs/v4.5.5.rst b/user_guide_src/source/changelogs/v4.5.5.rst index f6799e484ebf..d3fecbfeb26e 100644 --- a/user_guide_src/source/changelogs/v4.5.5.rst +++ b/user_guide_src/source/changelogs/v4.5.5.rst @@ -14,6 +14,18 @@ Release Date: Unreleased BREAKING ******** +.. _v455-method-signature-changes: + +Method Signature Changes +======================== + +- **Time:** For PHP 8.4 compatibility only, the first parameter type of the + ``createFromTimestamp()`` method has been changed from ``int`` to ``int|float``, + and the return type ``static`` has been added. But **note that the** + ``createFromTimestamp()`` **method still cannot handle a float value, and the + behavior is not yet changed**. That is, the behavior is not the exactly same as + PHP 8.4's ``DateTimeImmutable::createFromTimestamp()`` method. + *************** Message Changes *************** diff --git a/user_guide_src/source/installation/upgrade_455.rst b/user_guide_src/source/installation/upgrade_455.rst index bbff938631c5..3ec6d1443cb4 100644 --- a/user_guide_src/source/installation/upgrade_455.rst +++ b/user_guide_src/source/installation/upgrade_455.rst @@ -20,6 +20,13 @@ Mandatory File Changes Breaking Changes **************** +Method Signature Changes +======================== + +Some method signature changes have been made. Classes that extend them should +update their APIs to reflect the changes. See :ref:`ChangeLog ` +for details. + ********************* Breaking Enhancements *********************