diff --git a/src/FormattingTrait.php b/src/FormattingTrait.php index edb5291..7b4fbae 100644 --- a/src/FormattingTrait.php +++ b/src/FormattingTrait.php @@ -250,7 +250,7 @@ public function toQuarter(bool $range = false): int|array trigger_error( 'Using toQuarter() with `$range=true` is deprecated. Use `toQuarterRange()` instead.', - E_USER_DEPRECATED + E_USER_DEPRECATED, ); return $this->toQuarterRange(); @@ -259,23 +259,20 @@ public function toQuarter(bool $range = false): int|array /** * Returns the quarter range * - * @return array Array with start and end date of quarter in Y-m-d format + * @return array{0: string, 1: string} Array with start and end date of quarter in Y-m-d format */ public function toQuarterRange(): array { + /** @var int<1, 4> $quarter */ $quarter = (int)ceil((int)$this->format('m') / 3); $year = $this->format('Y'); - switch ($quarter) { - case 1: - return [$year . '-01-01', $year . '-03-31']; - case 2: - return [$year . '-04-01', $year . '-06-30']; - case 3: - return [$year . '-07-01', $year . '-09-30']; - default: - return [$year . '-10-01', $year . '-12-31']; - } + return match ($quarter) { + 1 => [$year . '-01-01', $year . '-03-31'], + 2 => [$year . '-04-01', $year . '-06-30'], + 3 => [$year . '-07-01', $year . '-09-30'], + 4 => [$year . '-10-01', $year . '-12-31'], + }; } /** diff --git a/tests/TestCase/DateTime/StringsTest.php b/tests/TestCase/DateTime/StringsTest.php index a4a4850..9e245fe 100644 --- a/tests/TestCase/DateTime/StringsTest.php +++ b/tests/TestCase/DateTime/StringsTest.php @@ -205,7 +205,7 @@ public static function toQuarterRangeProvider() public function testToQuarterRange($date, $expected) { $this->assertSame($expected, (new Chronos($date))->toQuarterRange()); - $this->deprecated(function() use ($date, $expected) { + $this->deprecated(function () use ($date, $expected) { $this->assertSame($expected, (new Chronos($date))->toQuarter(true)); }); }