Skip to content

Commit 6c09d96

Browse files
committed
Use match() instead of switch/case.
Also improve docblock type
1 parent 7d9af08 commit 6c09d96

File tree

1 file changed

+8
-12
lines changed

1 file changed

+8
-12
lines changed

src/FormattingTrait.php

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ public function toQuarter(bool $range = false): int|array
250250

251251
trigger_error(
252252
'Using toQuarter() with `$range=true` is deprecated. Use `toQuarterRange()` instead.',
253-
E_USER_DEPRECATED
253+
E_USER_DEPRECATED,
254254
);
255255

256256
return $this->toQuarterRange();
@@ -259,23 +259,19 @@ public function toQuarter(bool $range = false): int|array
259259
/**
260260
* Returns the quarter range
261261
*
262-
* @return array<string> Array with start and end date of quarter in Y-m-d format
262+
* @return array{0: string, 1: string} Array with start and end date of quarter in Y-m-d format
263263
*/
264264
public function toQuarterRange(): array
265265
{
266266
$quarter = (int)ceil((int)$this->format('m') / 3);
267267
$year = $this->format('Y');
268268

269-
switch ($quarter) {
270-
case 1:
271-
return [$year . '-01-01', $year . '-03-31'];
272-
case 2:
273-
return [$year . '-04-01', $year . '-06-30'];
274-
case 3:
275-
return [$year . '-07-01', $year . '-09-30'];
276-
default:
277-
return [$year . '-10-01', $year . '-12-31'];
278-
}
269+
return match ($quarter) {
270+
1 => [$year . '-01-01', $year . '-03-31'],
271+
2 => [$year . '-04-01', $year . '-06-30'],
272+
3 => [$year . '-07-01', $year . '-09-30'],
273+
default => [$year . '-10-01', $year . '-12-31'],
274+
};
279275
}
280276

281277
/**

0 commit comments

Comments
 (0)