From a11ebe673ad48202a242382456338f9d934d6058 Mon Sep 17 00:00:00 2001 From: mscherer Date: Fri, 6 Feb 2026 13:23:42 +0100 Subject: [PATCH 1/4] 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/4] 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); } From 957921f3eb054ad7c4b53d3aea1e357bd45206b7 Mon Sep 17 00:00:00 2001 From: mscherer Date: Sat, 14 Mar 2026 17:12:53 +0100 Subject: [PATCH 3/4] Run cs-stan on PHP 8.4 for 4.x branch --- .github/workflows/ci.yml | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b93c1e4..a68bdff 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -6,6 +6,7 @@ on: - 2.x - 2.next - 3.x + - 4.x pull_request: branches: - '*' @@ -19,5 +20,34 @@ jobs: secrets: inherit cs-stan: - uses: cakephp/.github/.github/workflows/cs-stan.yml@5.x - secrets: inherit + name: Coding Standard & Static Analysis + runs-on: ubuntu-24.04 + + steps: + - uses: actions/checkout@v4 + with: + persist-credentials: false + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: '8.4' + extensions: mbstring, intl + coverage: none + tools: phive, cs2pr + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Composer install + uses: ramsey/composer-install@v3 + + - name: Install PHP tools with phive. + run: "phive install --trust-gpg-keys 'CF1A108D0E7AE720,51C67305FFC2E5C0,12CE0F1D262429A5,99BF4D9A33D65E1E'" + + - name: Run phpcs + if: always() + run: tools/phpcs --report=checkstyle | cs2pr + + - name: Run phpstan + if: always() + run: tools/phpstan analyse --error-format=github From 8fbb9cf9d5bfe68f89559d243aef1b2f60fa7fb4 Mon Sep 17 00:00:00 2001 From: mscherer Date: Sat, 14 Mar 2026 17:14:07 +0100 Subject: [PATCH 4/4] Fix phpcs path in CI --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a68bdff..8049626 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -46,7 +46,7 @@ jobs: - name: Run phpcs if: always() - run: tools/phpcs --report=checkstyle | cs2pr + run: vendor/bin/phpcs --report=checkstyle | cs2pr - name: Run phpstan if: always()