Skip to content
Merged
1 change: 1 addition & 0 deletions UPGRADING.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,3 +101,4 @@ These are internal changes that don't require any action on your part.
- **`HasRegions` interface** standardizes how countries declare and validate regional holiday support.
- **`Holiday` value object and `HolidayType` enum** provide structured, JSON-serializable return data instead of plain arrays.
- **`region` parameter on `Holidays::for()`** allows passing a region code directly without constructing a country instance.
- **Islamic calendar methods are stricter** — `arafat()`, `islamicNewYear()`, and `prophetMuhammadBirthday()` now throw `InvalidYear` instead of returning `null` when a year is not found in the lookup table.
195 changes: 0 additions & 195 deletions phpstan-baseline.neon

This file was deleted.

5 changes: 1 addition & 4 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
includes:
- phpstan-baseline.neon

parameters:
level: 8
level: max
paths:
- src
ignoreErrors:
Expand Down
42 changes: 36 additions & 6 deletions src/Calendars/IslamicCalendar.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,37 +17,67 @@ trait IslamicCalendar

protected string $islamicCalendarTimezone = 'UTC';

/** @return array<int, string|array<string>> */
abstract protected function eidAlFitrDates(): array;

/** @return array<int, string|array<string>> */
abstract protected function eidAlAdhaDates(): array;

/** @return array<int, string> */
protected function ashuraDates(): array
{
return [];
}

/** @return array<int, string> */
protected function arafatDates(): array
{
return [];
}

/** @return array<int, string> */
protected function islamicNewYearDates(): array
{
return [];
}

/** @return array<int, string> */
protected function prophetMuhammadBirthdayDates(): array
{
return [];
}

/** @return array<CarbonPeriod> */
public function eidAlFitr(int $year, int $totalDays = 3): array
{
return $this->getMultiDayHoliday(self::eidAlFitr, $year, $totalDays);
return $this->getMultiDayHoliday($this->eidAlFitrDates(), $year, $totalDays);
}

/** @return array<CarbonPeriod> */
public function eidAlAdha(int $year, int $totalDays = 4): array
{
return $this->getMultiDayHoliday(self::eidAlAdha, $year, $totalDays);
return $this->getMultiDayHoliday($this->eidAlAdhaDates(), $year, $totalDays);
}

/** @return array<CarbonPeriod> */
protected function ashura(int $year, int $totalDays = 2): array
{
return $this->getMultiDayHoliday(self::ashura, $year, $totalDays);
return $this->getMultiDayHoliday($this->ashuraDates(), $year, $totalDays);
}

protected function arafat(int $year): CarbonImmutable
{
return $this->getSingleDayHoliday(self::arafat, $year);
return $this->getSingleDayHoliday($this->arafatDates(), $year);
}

protected function islamicNewYear(int $year): CarbonImmutable
{
return $this->getSingleDayHoliday(self::islamicNewYear, $year);
return $this->getSingleDayHoliday($this->islamicNewYearDates(), $year);
}

protected function prophetMuhammadBirthday(int $year): CarbonImmutable
{
return $this->getSingleDayHoliday(self::prophetMuhammadBirthday, $year);
return $this->getSingleDayHoliday($this->prophetMuhammadBirthdayDates(), $year);
}

public function setIslamicCalendarTimezone(string $islamicCalendarTimezone): static
Expand Down
8 changes: 5 additions & 3 deletions src/Calendars/ResolvesCalendarDates.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ protected function getMultiDayHoliday(array $collection, int $year, int $totalDa
$date = $collection[$year] ?? null;

if ($date === null) {
$this->throwUnsupportedYear($collection);
return [];
}

$overlap = $this->getOverlapping($collection, $year, $totalDays);
Expand Down Expand Up @@ -109,11 +109,13 @@ protected function getOverlapping(array $collection, int $year, int $totalDays):
return ($end?->year !== $year) ? (string) $date : null;
}

/** @param non-empty-array<int, mixed> $collection */
/** @param array<int, mixed> $collection */
private function throwUnsupportedYear(array $collection): never
{
$keys = array_keys($collection);
$min = $keys ? min($keys) : 0;
$max = $keys ? max($keys) : 0;

throw InvalidYear::range($this->countryCode(), min($keys), max($keys));
throw InvalidYear::range($this->countryCode(), $min, $max);
}
}
Loading