Skip to content

Commit 3b0da70

Browse files
committed
refactor: change nested ifs to early return as it is best to exit early. Change to array spread instead of array_merge for simplicity.
Signed-off-by: Sacha Telgenhof <me@sachatelgenhof.com>
1 parent c7087f3 commit 3b0da70

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

src/Yasumi/Provider/Denmark.php

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ public function initialize(): void
5858
$this->addHoliday($this->secondChristmasDay($this->year, $this->timezone, $this->locale));
5959
$this->calculateGreatPrayerDay();
6060

61+
// Add other holidays
6162
$this->addHoliday($this->internationalWorkersDay($this->year, $this->timezone, $this->locale, Holiday::TYPE_OBSERVANCE));
6263
$this->addHoliday($this->christmasEve($this->year, $this->timezone, $this->locale));
6364
$this->addHoliday($this->newYearsEve($this->year, $this->timezone, $this->locale, Holiday::TYPE_OBSERVANCE));
@@ -67,6 +68,7 @@ public function initialize(): void
6768
if ($summerTime instanceof Holiday) {
6869
$this->addHoliday($summerTime);
6970
}
71+
7072
$winterTime = $this->winterTime($this->year, $this->timezone, $this->locale);
7173
if ($winterTime instanceof Holiday) {
7274
$this->addHoliday($winterTime);
@@ -99,14 +101,20 @@ private function calculateGreatPrayerDay(): void
99101
{
100102
$easter = $this->calculateEaster($this->year, $this->timezone)->format('Y-m-d');
101103

102-
if ($this->year >= 1686 && $this->year < 2024) {
103-
$this->addHoliday(new Holiday(
104-
'greatPrayerDay',
105-
['da' => 'store bededag'],
106-
new \DateTime("fourth friday {$easter}", DateTimeZoneFactory::getDateTimeZone($this->timezone)),
107-
$this->locale
108-
));
104+
if ($this->year < 1686) {
105+
return;
109106
}
107+
108+
if ($this->year >= 2024) {
109+
return;
110+
}
111+
112+
$this->addHoliday(new Holiday(
113+
'greatPrayerDay',
114+
['da' => 'store bededag'],
115+
new \DateTime("fourth friday {$easter}", DateTimeZoneFactory::getDateTimeZone($this->timezone)),
116+
$this->locale
117+
));
110118
}
111119

112120
/**

tests/Denmark/DaylightSavingTime.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ abstract class DaylightSavingTime extends DenmarkBaseTestCase implements Holiday
2828
public function __construct()
2929
{
3030
$observedYears = [1916, 1940];
31-
$observedYears = array_merge($observedYears, range(1942, 1948));
31+
$observedYears = [...$observedYears, ...range(1942, 1948)];
3232
$observedYears = array_merge($observedYears, range(1980, 2037)); // PHP caps future DST transitions
3333

3434
$this->observedYears = $observedYears;

0 commit comments

Comments
 (0)