From 4531cc9a0c5b8705c25137a632ccd40c9a68d81b Mon Sep 17 00:00:00 2001 From: kenjis Date: Wed, 21 Aug 2024 11:38:02 +0900 Subject: [PATCH 1/5] fix!: TimeTrait::createFromTimestamp() method signature for PHP 8.4 PHP Fatal error: Declaration of CodeIgniter\I18n\TimeTrait::createFromTimestamp(int $timestamp, $timezone = null, ?string $locale = null) must be compatible with DateTimeImmutable::createFromTimestamp(int|float $timestamp): static in /home/runner/work/CodeIgniter4/CodeIgniter4/system/I18n/TimeTrait.php on line 268 --- system/I18n/TimeTrait.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/system/I18n/TimeTrait.php b/system/I18n/TimeTrait.php index fefb2fc544a3..da180df09702 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(); From ecdeb8281ba686de72e06a9279201abaa23674de Mon Sep 17 00:00:00 2001 From: kenjis Date: Wed, 21 Aug 2024 11:57:58 +0900 Subject: [PATCH 2/5] docs: add changelog and upgrade --- user_guide_src/source/changelogs/v4.5.5.rst | 12 ++++++++++++ user_guide_src/source/installation/upgrade_455.rst | 7 +++++++ 2 files changed, 19 insertions(+) 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 ********************* From 1d52190414ab3acb33d1640dce0eb4b004fa459c Mon Sep 17 00:00:00 2001 From: kenjis Date: Wed, 21 Aug 2024 12:01:57 +0900 Subject: [PATCH 3/5] docs: add @phpstan-consistent-constructor to Time --- system/I18n/Time.php | 2 ++ system/I18n/TimeLegacy.php | 2 ++ 2 files changed, 4 insertions(+) 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 */ From 968639dbf237c91a27085c97020fd363984178ea Mon Sep 17 00:00:00 2001 From: kenjis Date: Wed, 21 Aug 2024 12:02:56 +0900 Subject: [PATCH 4/5] fix: change return type for createFromTimestamp() API change --- system/I18n/TimeTrait.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/system/I18n/TimeTrait.php b/system/I18n/TimeTrait.php index da180df09702..0f02ef8820b8 100644 --- a/system/I18n/TimeTrait.php +++ b/system/I18n/TimeTrait.php @@ -275,7 +275,7 @@ public static function createFromTimestamp(float|int $timestamp, $timezone = nul /** * Takes an instance of DateTimeInterface and returns an instance of Time with it's same values. * - * @return self + * @return static * * @throws Exception */ @@ -284,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); } /** @@ -672,7 +672,7 @@ protected function setValue(string $name, $value) * * @param DateTimeZone|string $timezone * - * @return self + * @return static * * @throws Exception */ @@ -681,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); } /** From 21c6eb87b85c6d0d8cde94e69f883de6594edb46 Mon Sep 17 00:00:00 2001 From: kenjis Date: Wed, 21 Aug 2024 12:08:54 +0900 Subject: [PATCH 5/5] chore: update phpstan-baseline.php --- phpstan-baseline.php | 12 ------------ 1 file changed, 12 deletions(-) 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\\.$#',