Skip to content

Commit b37a9f4

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

File tree

1 file changed

+7
-11
lines changed

1 file changed

+7
-11
lines changed

src/FormattingTrait.php

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -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)