From a11ebe673ad48202a242382456338f9d934d6058 Mon Sep 17 00:00:00 2001 From: mscherer Date: Fri, 6 Feb 2026 13:23:42 +0100 Subject: [PATCH 1/2] Remove deprecated toQuarter() $range parameter - Remove $range parameter from toQuarter() (deprecated in 3.3.0) - Update tests to remove deprecated usage - Remove outdated PHPStan ignore for createFromTimestamp() --- phpstan.neon | 4 ---- src/FormattingTrait.php | 19 +++---------------- tests/TestCase/DateTime/StringsTest.php | 5 +---- 3 files changed, 4 insertions(+), 24 deletions(-) diff --git a/phpstan.neon b/phpstan.neon index d956d48..02711ac 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -9,10 +9,6 @@ parameters: - identifier: missingType.iterableValue - identifier: property.readOnlyByPhpDocDefaultValue - identifier: property.readOnlyByPhpDocAssignNotInConstructor - - - message: "#^Call to an undefined static method DateTimeImmutable\\:\\:createFromTimestamp\\(\\)\\.$#" - count: 1 - path: src/Chronos.php - message: "#with generic class DatePeriod but does not specify its types: TDate, TEnd, TRecurrences$#" count: 1 diff --git a/src/FormattingTrait.php b/src/FormattingTrait.php index 7b4fbae..8d51c0d 100644 --- a/src/FormattingTrait.php +++ b/src/FormattingTrait.php @@ -236,24 +236,11 @@ public function toUnixString(): string /** * Returns the quarter * - * Deprecated 3.3.0: The $range parameter is deprecated. Use toQuarterRange() for quarter ranges. - * - * @param bool $range Range. - * @return array|int 1, 2, 3, or 4 quarter of year or array if $range true + * @return int 1, 2, 3, or 4 quarter of year */ - public function toQuarter(bool $range = false): int|array + public function toQuarter(): int { - $quarter = (int)ceil((int)$this->format('m') / 3); - if ($range === false) { - return $quarter; - } - - trigger_error( - 'Using toQuarter() with `$range=true` is deprecated. Use `toQuarterRange()` instead.', - E_USER_DEPRECATED, - ); - - return $this->toQuarterRange(); + return (int)ceil((int)$this->format('m') / 3); } /** diff --git a/tests/TestCase/DateTime/StringsTest.php b/tests/TestCase/DateTime/StringsTest.php index 9e245fe..a9957d8 100644 --- a/tests/TestCase/DateTime/StringsTest.php +++ b/tests/TestCase/DateTime/StringsTest.php @@ -186,7 +186,7 @@ public static function toQuarterProvider() * @return void */ #[DataProvider('toQuarterProvider')] - public function testToQuarter($date, $expected, $range = false) + public function testToQuarter($date, $expected) { $this->assertSame($expected, (new Chronos($date))->toQuarter()); } @@ -205,9 +205,6 @@ public static function toQuarterRangeProvider() public function testToQuarterRange($date, $expected) { $this->assertSame($expected, (new Chronos($date))->toQuarterRange()); - $this->deprecated(function () use ($date, $expected) { - $this->assertSame($expected, (new Chronos($date))->toQuarter(true)); - }); } /** From 1289ec1b91a14be090e7e4027e9561a1190259b4 Mon Sep 17 00:00:00 2001 From: mscherer Date: Fri, 6 Feb 2026 13:28:00 +0100 Subject: [PATCH 2/2] Widen $toStringFormat type for CakePHP I18n compatibility Allow subclasses to use IntlDateFormatter constants by widening the $toStringFormat property type from string to array|string|int. This enables CakePHP I18n classes to rename $_toStringFormat to $toStringFormat without type conflicts. --- src/Chronos.php | 7 +++++-- src/ChronosDate.php | 7 +++++-- src/ChronosTime.php | 9 +++++++-- src/FormattingTrait.php | 6 +++++- 4 files changed, 22 insertions(+), 7 deletions(-) diff --git a/src/Chronos.php b/src/Chronos.php index a74bfb6..e6906a9 100644 --- a/src/Chronos.php +++ b/src/Chronos.php @@ -163,9 +163,12 @@ class Chronos extends DateTimeImmutable implements Stringable /** * Format to use for __toString method when type juggling occurs. * - * @var string + * The widened type allows subclasses (like CakePHP I18n classes) to use + * IntlDateFormatter constants while maintaining backward compatibility. + * + * @var array|string|int */ - protected static string $toStringFormat = self::DEFAULT_TO_STRING_FORMAT; + protected static array|string|int $toStringFormat = self::DEFAULT_TO_STRING_FORMAT; /** * Days of weekend diff --git a/src/ChronosDate.php b/src/ChronosDate.php index 85bad79..329dd13 100644 --- a/src/ChronosDate.php +++ b/src/ChronosDate.php @@ -58,9 +58,12 @@ class ChronosDate implements Stringable /** * Format to use for __toString method when type juggling occurs. * - * @var string + * The widened type allows subclasses (like CakePHP I18n classes) to use + * IntlDateFormatter constants while maintaining backward compatibility. + * + * @var array|string|int */ - protected static string $toStringFormat = self::DEFAULT_TO_STRING_FORMAT; + protected static array|string|int $toStringFormat = self::DEFAULT_TO_STRING_FORMAT; /** * Names of days of the week. diff --git a/src/ChronosTime.php b/src/ChronosTime.php index 7d65dd2..cc9362b 100644 --- a/src/ChronosTime.php +++ b/src/ChronosTime.php @@ -60,9 +60,12 @@ class ChronosTime implements Stringable /** * Format to use for __toString method. * - * @var string + * The widened type allows subclasses to use IntlDateFormatter constants + * while maintaining backward compatibility. + * + * @var array|string|int */ - protected static string $toStringFormat = self::DEFAULT_TO_STRING_FORMAT; + protected static array|string|int $toStringFormat = self::DEFAULT_TO_STRING_FORMAT; /** * @var int @@ -381,6 +384,8 @@ public static function setToStringFormat(string $format): void */ public function __toString(): string { + assert(is_string(static::$toStringFormat)); + return $this->format(static::$toStringFormat); } diff --git a/src/FormattingTrait.php b/src/FormattingTrait.php index 8d51c0d..8878a37 100644 --- a/src/FormattingTrait.php +++ b/src/FormattingTrait.php @@ -19,7 +19,9 @@ /** * Provides string formatting methods for datetime instances. * - * Expects implementing classes to define static::$toStringFormat + * Expects implementing classes to define static::$toStringFormat as `array|string|int`. + * The widened type allows subclasses (like CakePHP I18n classes) to use + * IntlDateFormatter constants while maintaining backward compatibility. * * @internal */ @@ -54,6 +56,8 @@ public static function setToStringFormat(string $format): void */ public function __toString(): string { + assert(is_string(static::$toStringFormat)); + return $this->format(static::$toStringFormat); }