From 241f85f142e8133fe6fdcd2d3423fd1dca19d8a7 Mon Sep 17 00:00:00 2001 From: "John Paul E. Balandan, CPA" Date: Fri, 28 Aug 2026 12:40:30 +0800 Subject: [PATCH] refactor: fix phpstan errors in `I18n` --- system/I18n/Time.php | 1 + system/I18n/TimeLegacy.php | 33 ++++++++++--------- tests/system/I18n/TimeLegacyTest.php | 7 ++-- tests/system/I18n/TimeTest.php | 7 ++-- utils/phpstan-baseline/loader.neon | 3 +- .../missingType.iterableValue.neon | 12 +------ utils/phpstan-baseline/property.notFound.neon | 33 ------------------- 7 files changed, 30 insertions(+), 66 deletions(-) delete mode 100644 utils/phpstan-baseline/property.notFound.neon diff --git a/system/I18n/Time.php b/system/I18n/Time.php index 255f879a90ec..cc254dba03ea 100644 --- a/system/I18n/Time.php +++ b/system/I18n/Time.php @@ -34,6 +34,7 @@ * @property-read string $quarter * @property-read string $second * @property-read int $timestamp + * @property-read string $timezoneName * @property-read bool $utc * @property-read string $weekOfMonth * @property-read string $weekOfYear diff --git a/system/I18n/TimeLegacy.php b/system/I18n/TimeLegacy.php index 034cab0dadcf..119fc3f5d050 100644 --- a/system/I18n/TimeLegacy.php +++ b/system/I18n/TimeLegacy.php @@ -23,22 +23,23 @@ * This is not immutable! Some methods are immutable, * but some methods can alter the state. * - * @property int $age read-only - * @property string $day read-only - * @property string $dayOfWeek read-only - * @property string $dayOfYear read-only - * @property bool $dst read-only - * @property string $hour read-only - * @property bool $local read-only - * @property string $minute read-only - * @property string $month read-only - * @property string $quarter read-only - * @property string $second read-only - * @property int $timestamp read-only - * @property bool $utc read-only - * @property string $weekOfMonth read-only - * @property string $weekOfYear read-only - * @property string $year read-only + * @property int $age read-only + * @property string $day read-only + * @property string $dayOfWeek read-only + * @property string $dayOfYear read-only + * @property bool $dst read-only + * @property string $hour read-only + * @property bool $local read-only + * @property string $minute read-only + * @property string $month read-only + * @property string $quarter read-only + * @property string $second read-only + * @property int $timestamp read-only + * @property string $timezoneName read-only + * @property bool $utc read-only + * @property string $weekOfMonth read-only + * @property string $weekOfYear read-only + * @property string $year read-only * * @phpstan-consistent-constructor * diff --git a/tests/system/I18n/TimeLegacyTest.php b/tests/system/I18n/TimeLegacyTest.php index 8fbd359fbfd5..6cdcdb45ff74 100644 --- a/tests/system/I18n/TimeLegacyTest.php +++ b/tests/system/I18n/TimeLegacyTest.php @@ -317,7 +317,7 @@ public function testMagicIssetFalse(): void { $time = TimeLegacy::parse('January 1, 2016'); - $this->assertFalse(isset($time->foobar)); + $this->assertFalse(isset($time->foobar)); // @phpstan-ignore property.notFound } public function testGetYear(): void @@ -1128,7 +1128,7 @@ public function testGetter(): void { $time = TimeLegacy::parse('August 12, 2016 4:15:23pm'); - $this->assertNull($time->weekOfWeek); + $this->assertNull($time->weekOfWeek); // @phpstan-ignore property.notFound } public function testUnserializeTimeObject(): void @@ -1163,6 +1163,9 @@ public function testToStringDoesNotDependOnLocale(string $locale): void $this->assertSame('2017-03-10 12:00:00', (string) $time); } + /** + * @return iterable + */ public static function provideToStringDoesNotDependOnLocale(): iterable { yield from [ diff --git a/tests/system/I18n/TimeTest.php b/tests/system/I18n/TimeTest.php index a7346c181b93..0d08af39f3f2 100644 --- a/tests/system/I18n/TimeTest.php +++ b/tests/system/I18n/TimeTest.php @@ -346,7 +346,7 @@ public function testMagicIssetFalse(): void { $time = Time::parse('January 1, 2016'); - $this->assertFalse(isset($time->foobar)); + $this->assertFalse(isset($time->foobar)); // @phpstan-ignore property.notFound } public function testGetYear(): void @@ -1280,7 +1280,7 @@ public function testGetter(): void { $time = Time::parse('August 12, 2016 4:15:23pm'); - $this->assertNull($time->weekOfWeek); + $this->assertNull($time->weekOfWeek); // @phpstan-ignore property.notFound } public function testUnserializeTimeObject(): void @@ -1324,6 +1324,9 @@ public function testToStringDoesNotDependOnLocale(string $locale): void $this->assertSame('2017-03-10 12:00:00', (string) $time); } + /** + * @return iterable + */ public static function provideToStringDoesNotDependOnLocale(): iterable { yield from [ diff --git a/utils/phpstan-baseline/loader.neon b/utils/phpstan-baseline/loader.neon index 37af12f96222..d9cf5a7deb6d 100644 --- a/utils/phpstan-baseline/loader.neon +++ b/utils/phpstan-baseline/loader.neon @@ -1,4 +1,4 @@ -# total 132 errors +# total 124 errors includes: - argument.type.neon @@ -12,5 +12,4 @@ includes: - missingType.iterableValue.neon - missingType.parameter.neon - property.defaultValue.neon - - property.notFound.neon - property.phpDocType.neon diff --git a/utils/phpstan-baseline/missingType.iterableValue.neon b/utils/phpstan-baseline/missingType.iterableValue.neon index e3ce34dc009d..ff0cd8e18d33 100644 --- a/utils/phpstan-baseline/missingType.iterableValue.neon +++ b/utils/phpstan-baseline/missingType.iterableValue.neon @@ -1,4 +1,4 @@ -# total 82 errors +# total 80 errors parameters: ignoreErrors: @@ -357,16 +357,6 @@ parameters: count: 1 path: ../../tests/system/DataConverter/DataConverterTest.php - - - message: '#^Method CodeIgniter\\I18n\\TimeLegacyTest\:\:provideToStringDoesNotDependOnLocale\(\) return type has no value type specified in iterable type iterable\.$#' - count: 1 - path: ../../tests/system/I18n/TimeLegacyTest.php - - - - message: '#^Method CodeIgniter\\I18n\\TimeTest\:\:provideToStringDoesNotDependOnLocale\(\) return type has no value type specified in iterable type iterable\.$#' - count: 1 - path: ../../tests/system/I18n/TimeTest.php - - message: '#^Method CodeIgniter\\Models\\FindModelTest\:\:provideAggregateAndGroupBy\(\) return type has no value type specified in iterable type iterable\.$#' count: 1 diff --git a/utils/phpstan-baseline/property.notFound.neon b/utils/phpstan-baseline/property.notFound.neon deleted file mode 100644 index 1a8daae7b918..000000000000 --- a/utils/phpstan-baseline/property.notFound.neon +++ /dev/null @@ -1,33 +0,0 @@ -# total 6 errors - -parameters: - ignoreErrors: - - - message: '#^Access to an undefined property CodeIgniter\\I18n\\TimeLegacy\:\:\$foobar\.$#' - count: 1 - path: ../../tests/system/I18n/TimeLegacyTest.php - - - - message: '#^Access to an undefined property CodeIgniter\\I18n\\TimeLegacy\:\:\$timezoneName\.$#' - count: 1 - path: ../../tests/system/I18n/TimeLegacyTest.php - - - - message: '#^Access to an undefined property CodeIgniter\\I18n\\TimeLegacy\:\:\$weekOfWeek\.$#' - count: 1 - path: ../../tests/system/I18n/TimeLegacyTest.php - - - - message: '#^Access to an undefined property CodeIgniter\\I18n\\Time\:\:\$foobar\.$#' - count: 1 - path: ../../tests/system/I18n/TimeTest.php - - - - message: '#^Access to an undefined property CodeIgniter\\I18n\\Time\:\:\$timezoneName\.$#' - count: 1 - path: ../../tests/system/I18n/TimeTest.php - - - - message: '#^Access to an undefined property CodeIgniter\\I18n\\Time\:\:\$weekOfWeek\.$#' - count: 1 - path: ../../tests/system/I18n/TimeTest.php