diff --git a/rector.php b/rector.php index 99a3024c..9108fc75 100644 --- a/rector.php +++ b/rector.php @@ -8,6 +8,7 @@ use Rector\CodingStyle\Rector\Closure\StaticClosureRector; use Rector\CodingStyle\Rector\Encapsed\EncapsedStringsToSprintfRector; use Rector\CodingStyle\Rector\If_\NullableCompareToNullRector; +use Rector\CodingStyle\Rector\PostInc\PostIncDecToPreIncDecRector; use Rector\Config\RectorConfig; use Rector\Php74\Rector\Closure\ClosureToArrowFunctionRector; use Rector\Php81\Rector\FuncCall\NullToStrictStringFuncCallArgRector; @@ -17,7 +18,7 @@ return RectorConfig::configure() ->withPaths(['src']) ->withPhpSets(php81: true) - ->withPreparedSets(deadCode: true, typeDeclarations: true) + ->withPreparedSets(deadCode: true, codingStyle: true, typeDeclarations: true) ->withSkip([ NullToStrictStringFuncCallArgRector::class, ClosureToArrowFunctionRector::class, @@ -29,4 +30,5 @@ NullableCompareToNullRector::class, EncapsedStringsToSprintfRector::class, CatchExceptionNameMatchingTypeRector::class, + PostIncDecToPreIncDecRector::class, ]); diff --git a/src/Countries/Bahrain.php b/src/Countries/Bahrain.php index 6fcf009d..6459a2e8 100644 --- a/src/Countries/Bahrain.php +++ b/src/Countries/Bahrain.php @@ -151,7 +151,7 @@ public function defaultLocale(): string protected function allHolidays(int $year): array { return array_merge([ - 'New Year\'s Day' => '1-1', + "New Year's Day" => '1-1', 'Labour Day' => '5-1', 'National Day' => '12-16', 'National Day 2' => '12-17', diff --git a/src/Countries/Benin.php b/src/Countries/Benin.php index b6a5b9a5..db6f7da3 100644 --- a/src/Countries/Benin.php +++ b/src/Countries/Benin.php @@ -309,7 +309,7 @@ protected function getIslamicHolidays( $currentYearHolidays = is_array($holidays[$year]) ? $holidays[$year] : [$holidays[$year]]; foreach ($currentYearHolidays as $currentYearHoliday) { - $currentYearHoliday = CarbonImmutable::createFromFormat('Y-m-d', "$year-$currentYearHoliday"); + $currentYearHoliday = CarbonImmutable::createFromFormat('Y-m-d', "{$year}-{$currentYearHoliday}"); $islamicHolidays = array_merge($islamicHolidays, $this->prepareHolidays( holiday: $currentYearHoliday, diff --git a/src/Countries/Canada.php b/src/Countries/Canada.php index dd606a43..55236c30 100644 --- a/src/Countries/Canada.php +++ b/src/Countries/Canada.php @@ -15,7 +15,7 @@ public function countryCode(): string protected function allHolidays(int $year): array { return array_merge([ - 'New Year\'s Day' => '01-01', + "New Year's Day" => '01-01', 'Canada Day' => '07-01', 'Civic Holiday' => 'first monday of August', 'Labour Day' => 'first monday of September', diff --git a/src/Countries/Ecuador.php b/src/Countries/Ecuador.php index c3641218..d4a8e956 100644 --- a/src/Countries/Ecuador.php +++ b/src/Countries/Ecuador.php @@ -26,7 +26,7 @@ public function defaultLocale(): string protected function allHolidays(int $year): array { return array_merge([ - 'New Year\'s Day' => '01-01', + "New Year's Day" => '01-01', ], $this->variableHolidays($year)); } @@ -76,7 +76,7 @@ protected function variableHolidays(int $year): array 'Battle of Pichincha' => $this->nearestDay($year, 5, 24), 'Independence Day' => $this->nearestDay($year, 8, 10), 'Independence Of Guayaquil' => $this->nearestDay($year, 10, 9), - 'All Souls\' Day' => $this->nearestDay($year, 11, 2), + "All Souls' Day" => $this->nearestDay($year, 11, 2), 'Independence Of Cuenca' => $this->nearestDay($year, 11, 3), 'Christmas' => $this->getChristmasHoliday($year), ]; diff --git a/src/Countries/Egypt.php b/src/Countries/Egypt.php index bb3e5c74..5b8ceeef 100644 --- a/src/Countries/Egypt.php +++ b/src/Countries/Egypt.php @@ -244,7 +244,7 @@ public function defaultLocale(): string protected function allHolidays(int $year): array { return array_merge([ - 'New Year\'s Day' => '1-1', + "New Year's Day" => '1-1', 'Flooding of the Nile' => '8-15', 'March Equinox' => '3-20', 'June Solstice' => '6-21', diff --git a/src/Countries/France.php b/src/Countries/France.php index 16b61175..f4bf6bf6 100644 --- a/src/Countries/France.php +++ b/src/Countries/France.php @@ -19,7 +19,7 @@ public function countryCode(): string protected function allHolidays(int $year): array { return array_merge([ - 'Jour de l\'An' => '01-01', + "Jour de l'An" => '01-01', 'Fête du Travail' => '05-01', 'Victoire 1945' => '05-08', 'Fête Nationale' => '07-14', @@ -55,12 +55,12 @@ protected function regionHolidays(): array { return match ($this->region) { 'FR-57', 'FR-67', 'FR-68' => ['Saint-Étienne' => '12-26'], - 'FR-971', 'FR-MF' => ['Abolition de l\'esclavage' => '05-27'], - 'FR-972' => ['Abolition de l\'esclavage' => '05-22'], - 'FR-973' => ['Abolition de l\'esclavage' => '06-10'], - 'FR-974' => ['Abolition de l\'esclavage' => '12-20'], - 'FR-976' => ['Abolition de l\'esclavage' => '04-27'], - 'FR-BL' => ['Abolition de l\'esclavage' => '10-09'], + 'FR-971', 'FR-MF' => ["Abolition de l'esclavage" => '05-27'], + 'FR-972' => ["Abolition de l'esclavage" => '05-22'], + 'FR-973' => ["Abolition de l'esclavage" => '06-10'], + 'FR-974' => ["Abolition de l'esclavage" => '12-20'], + 'FR-976' => ["Abolition de l'esclavage" => '04-27'], + 'FR-BL' => ["Abolition de l'esclavage" => '10-09'], default => [], }; } diff --git a/src/Countries/Germany.php b/src/Countries/Germany.php index 04fdda15..f87526c5 100644 --- a/src/Countries/Germany.php +++ b/src/Countries/Germany.php @@ -105,6 +105,7 @@ protected function regionHolidays(int $year): array if ($year >= 2019) { $beHolidays['Internationaler Frauentag'] = '03-08'; } + if ($year === 2020) { $beHolidays['Tag der Befreiung'] = '05-08'; } @@ -171,6 +172,7 @@ protected function regionHolidays(int $year): array $snHolidays['Reformationstag'] = '10-31'; } + if ($year > 1994) { $snHolidays['Buß- und Bettag'] = $this->getRepentanceAndPrayerDay($year); @@ -183,6 +185,7 @@ protected function regionHolidays(int $year): array $stHolidays['Reformationstag'] = '10-31'; } + if ($year >= 1991) { $stHolidays['Heilige Drei Könige'] = '01-06'; } @@ -191,6 +194,7 @@ protected function regionHolidays(int $year): array if ($year >= 1990) { $thHolidays['Reformationstag'] = '10-31'; } + if ($year >= 2019) { $thHolidays['Weltkindertag'] = '09-20'; } diff --git a/src/Countries/Ghana.php b/src/Countries/Ghana.php index 2e9ed2d2..e00a12a4 100644 --- a/src/Countries/Ghana.php +++ b/src/Countries/Ghana.php @@ -27,11 +27,11 @@ protected function allHolidays(int $year): array protected function observedHolidays(int $year): array { $holidays = [ - 'New Year\'s Day' => '01-01', + "New Year's Day" => '01-01', 'Constitution Day' => '01-07', 'Independence Day' => '03-06', 'May Day' => '05-01', - 'Founder\'s Day' => '08-04', + "Founder's Day" => '08-04', 'Kwame Nkrumah Memorial Day' => '09-21', 'Christmas Day' => '12-25', 'Boxing Day' => '12-26', diff --git a/src/Countries/Haiti.php b/src/Countries/Haiti.php index d35ac125..a9ab7f76 100644 --- a/src/Countries/Haiti.php +++ b/src/Countries/Haiti.php @@ -18,7 +18,7 @@ protected function allHolidays(int $year): array 'Jour des Aieux' => '01-2', 'Fête du Travail / Fête des Travailleurs' => '05-01', 'Jour du Drapeau et de l\'Université' => '05-18', - 'L\'Assomption de Marie' => '08-15', + "L'Assomption de Marie" => '08-15', 'Anniversaire de la mort de Dessalines' => '10-17', 'Toussaint' => '11-01', 'Jour des Morts' => '11-02', diff --git a/src/Countries/Ireland.php b/src/Countries/Ireland.php index 092bfdbd..009cee0f 100644 --- a/src/Countries/Ireland.php +++ b/src/Countries/Ireland.php @@ -14,10 +14,10 @@ public function countryCode(): string protected function allHolidays(int $year): array { return array_merge([ - 'New Year\'s Day' => '01-01', - 'Saint Patrick\'s Day' => '03-17', + "New Year's Day" => '01-01', + "Saint Patrick's Day" => '03-17', 'Christmas Day' => '12-25', - 'Saint Stephen\'s Day' => '12-26', + "Saint Stephen's Day" => '12-26', ], $this->variableHolidays($year)); } @@ -33,13 +33,13 @@ protected function variableHolidays(int $year): array ]; if ($year >= 2023) { - $stBrigidsDay = (new CarbonImmutable("$year-02-01"))->startOfDay(); + $stBrigidsDay = (new CarbonImmutable("{$year}-02-01"))->startOfDay(); if (! $stBrigidsDay->isFriday()) { $stBrigidsDay = 'first monday of February'; } - $variableHolidays['St Brigid\'s Day'] = $stBrigidsDay; + $variableHolidays["St Brigid's Day"] = $stBrigidsDay; } return $variableHolidays; diff --git a/src/Countries/Jamaica.php b/src/Countries/Jamaica.php index 96472e60..8963d9d6 100644 --- a/src/Countries/Jamaica.php +++ b/src/Countries/Jamaica.php @@ -27,7 +27,7 @@ protected function allHolidays(int $year): array protected function fixedHolidays(int $year): array { $holidays = [ - 'New Year\'s Day' => '01-01', + "New Year's Day" => '01-01', 'Labour Day' => '05-23', 'Emancipation Day' => '08-01', 'Independence Day' => '08-06', diff --git a/src/Countries/Mexico.php b/src/Countries/Mexico.php index 0ca4e61c..45a1b559 100644 --- a/src/Countries/Mexico.php +++ b/src/Countries/Mexico.php @@ -25,13 +25,13 @@ protected function allHolidays(int $year): array /** @return array */ protected function variableHolidays(int $year): array { - $constitutionDay = (new CarbonImmutable("first monday of february $year")) + $constitutionDay = (new CarbonImmutable("first monday of february {$year}")) ->setTimezone('America/Mexico_City'); - $benitoJuarezBirth = (new CarbonImmutable("third monday of March $year")) + $benitoJuarezBirth = (new CarbonImmutable("third monday of March {$year}")) ->setTimezone('America/Mexico_City'); - $revolutionDay = (new CarbonImmutable("third monday of november $year")) + $revolutionDay = (new CarbonImmutable("third monday of november {$year}")) ->setTimezone('America/Mexico_City'); $holidays = [ diff --git a/src/Countries/Montenegro.php b/src/Countries/Montenegro.php index a8d41397..c75d0747 100644 --- a/src/Countries/Montenegro.php +++ b/src/Countries/Montenegro.php @@ -20,7 +20,7 @@ public function defaultLocale(): string return 'sr'; } - public function allHolidays(int $year): array + protected function allHolidays(int $year): array { // Montenegro has two days off for most holidays return array_merge([ diff --git a/src/Countries/Morocco.php b/src/Countries/Morocco.php index 2b999263..e9c87fcc 100644 --- a/src/Countries/Morocco.php +++ b/src/Countries/Morocco.php @@ -24,7 +24,7 @@ public function defaultLocale(): string protected function allHolidays(int $year): array { return array_merge([ - 'New Year\'s Day' => '01-01', + "New Year's Day" => '01-01', 'Proclamation of Independence Day' => '01-11', 'Amazigh New Year (ⵉⴹ ⵏ ⵢⵉⵏⵏⴰⵢⵔ)' => '01-14', 'Labour Day' => '05-01', @@ -78,6 +78,7 @@ protected function variableHolidays(int $year): array throw InvalidYear::yearTooLow(1976); } } + // Store the Gregorian date of the Islamic holiday $islamicHolidaysOnGregorian[$holidayTitle] = CarbonImmutable::createFromFormat('Y-m-d', sprintf('%s-%s-%s', $GregorianDate['year'], $GregorianDate['month'], $GregorianDate['day'])); } @@ -98,8 +99,7 @@ protected function variableHolidays(int $year): array */ private function islamicToGregorian(int $y, int $m, int $d): array { - $delta = 0; - $jd = $this->intPart((11 * $y + 3) / 30) + 354 * $y + 30 * $m - $this->intPart(($m - 1) / 2) + $d + 1948440 - 385 + $delta; + $jd = $this->intPart((11 * $y + 3) / 30) + 354 * $y + 30 * $m - $this->intPart(($m - 1) / 2) + $d + 1948440 - 385; if ($jd > 2299160) { $l = $jd + 68569; $n = $this->intPart((4 * $l) / 146097); diff --git a/src/Countries/NewZealand.php b/src/Countries/NewZealand.php index 411b9613..b6a66edb 100644 --- a/src/Countries/NewZealand.php +++ b/src/Countries/NewZealand.php @@ -28,8 +28,8 @@ protected function observedHolidays(int $year): array { //https://www.employment.govt.nz/leave-and-holidays/public-holidays/public-holidays-and-anniversary-dates/ $holidays = [ - 'New Year\'s Day' => '01-01', - 'Day after New Year\'s Day' => '01-02', + "New Year's Day" => '01-01', + "Day after New Year's Day" => '01-02', 'Waitangi Day' => '02-06', 'ANZAC Day' => '04-25', 'Christmas Day' => '12-25', @@ -39,7 +39,7 @@ protected function observedHolidays(int $year): array //https://www.employment.govt.nz/leave-and-holidays/public-holidays/public-holidays-falling-on-a-weekend/ foreach ($holidays as $name => $date) { $observedDay = match ($name) { - 'Day after New Year\'s Day' => $this->secondOfJanuary($year), + "Day after New Year's Day" => $this->secondOfJanuary($year), 'Christmas Day' => $this->observedChristmasDay($year), 'Boxing Day' => $this->observedBoxingDay($year), default => $this->weekendToNextMonday($date, $year), diff --git a/src/Countries/Nigeria.php b/src/Countries/Nigeria.php index 7721b0d0..ac3407d3 100644 --- a/src/Countries/Nigeria.php +++ b/src/Countries/Nigeria.php @@ -14,8 +14,8 @@ public function countryCode(): string protected function allHolidays(int $year): array { return array_merge([ - 'New Year\'s Day' => '01-01', - 'Worker\'s Day' => '05-01', + "New Year's Day" => '01-01', + "Worker's Day" => '05-01', 'Democracy Day' => '06-12', 'Independence Day' => '10-01', 'Christmas Day' => '12-25', diff --git a/src/Countries/NorthernIreland.php b/src/Countries/NorthernIreland.php index 0b6a7575..e531b6df 100644 --- a/src/Countries/NorthernIreland.php +++ b/src/Countries/NorthernIreland.php @@ -25,9 +25,9 @@ protected function allHolidays(int $year): array protected function observedHolidays(int $year): array { $holidays = [ - 'New Year\'s Day' => '01-01', - 'St Patrick\'s Day' => '03-17', - 'Battle of the Boyne (Orangemen\'s Day)' => '07-12', + "New Year's Day" => '01-01', + "St Patrick's Day" => '03-17', + "Battle of the Boyne (Orangemen's Day)" => '07-12', 'Christmas Day' => '12-25', 'Boxing Day' => '12-26', ]; diff --git a/src/Countries/Philippines.php b/src/Countries/Philippines.php index c4d193e8..bfbb35ae 100644 --- a/src/Countries/Philippines.php +++ b/src/Countries/Philippines.php @@ -14,7 +14,7 @@ public function countryCode(): string protected function allHolidays(int $year): array { return array_merge([ - 'New Year\'s Day' => '01-01', + "New Year's Day" => '01-01', 'Araw ng Kagitingan' => '04-09', 'Labor Day' => '05-01', 'Independence Day' => '06-12', diff --git a/src/Countries/Scotland.php b/src/Countries/Scotland.php index 662c0ea0..3f4d3a80 100644 --- a/src/Countries/Scotland.php +++ b/src/Countries/Scotland.php @@ -26,9 +26,9 @@ protected function allHolidays(int $year): array protected function observedHolidays(int $year): array { $holidays = [ - 'New Year\'s Day' => '01-01', + "New Year's Day" => '01-01', '2nd January' => '01-02', - 'St Andrew\'s Day' => '11-30', + "St Andrew's Day" => '11-30', 'Christmas Day' => '12-25', 'Boxing Day' => '12-26', ]; diff --git a/src/Countries/SouthAfrica.php b/src/Countries/SouthAfrica.php index 81cf7397..c79b46cb 100644 --- a/src/Countries/SouthAfrica.php +++ b/src/Countries/SouthAfrica.php @@ -19,12 +19,12 @@ protected function allHolidays(int $year): array // https://en.wikipedia.org/wiki/Public_holidays_in_South_Africa // https://www.gov.za/about-sa/public-holidays $holidays = [ - 'New Year\'s Day' => '01-01', + "New Year's Day" => '01-01', 'Human Rights Day' => '03-21', 'Freedom Day' => '04-27', - 'Workers\' Day' => '05-01', + "Workers' Day" => '05-01', 'Youth Day' => '06-16', - 'National Women\'s Day' => '08-09', + "National Women's Day" => '08-09', 'Heritage Day' => '09-24', 'Day of Reconciliation' => '12-16', 'Christmas Day' => '12-25', diff --git a/src/Countries/Tanzania.php b/src/Countries/Tanzania.php index 7b318534..793d12ad 100644 --- a/src/Countries/Tanzania.php +++ b/src/Countries/Tanzania.php @@ -14,7 +14,7 @@ public function countryCode(): string protected function allHolidays(int $year): array { return array_merge([ - 'New Year\'s Day' => '01-01', + "New Year's Day" => '01-01', 'Labor Day' => '05-01', 'Saba Saba Day' => '07-07', 'Farmers Day (Nane Nane Day)' => '08-08', diff --git a/src/Countries/Tunisia.php b/src/Countries/Tunisia.php index 38d9f61e..b2c79a9f 100644 --- a/src/Countries/Tunisia.php +++ b/src/Countries/Tunisia.php @@ -251,12 +251,12 @@ protected function allHolidays(int $year): array } return array_merge([ - 'New Year\'s Day' => '01-01', + "New Year's Day" => '01-01', 'Independence Day' => '03-20', - 'Martyrs\' Day' => '04-09', + "Martyrs' Day" => '04-09', 'Labour Day' => '05-01', 'Republic Day' => '07-25', - 'Women\'s Day' => '08-13', + "Women's Day" => '08-13', 'Evacuation Day' => '10-15', ], $revolutionHoliday, $this->islamicHolidays($year)); } diff --git a/src/Countries/Turkmenistan.php b/src/Countries/Turkmenistan.php index cd207609..f12d6dfa 100644 --- a/src/Countries/Turkmenistan.php +++ b/src/Countries/Turkmenistan.php @@ -66,6 +66,7 @@ protected function getHijriYear(int $year, bool $nextYear = false): int { $formatter = $this->getIslamicFormatter(); $formatter->setPattern('yyyy'); + $dateTime = DateTime::createFromFormat('d/m/Y', '01/01/'.($nextYear ? $year + 1 : $year)); return (int) $formatter->format($dateTime); diff --git a/src/Countries/UnitedStates.php b/src/Countries/UnitedStates.php index 9cccfad7..f4c9dc8d 100644 --- a/src/Countries/UnitedStates.php +++ b/src/Countries/UnitedStates.php @@ -12,7 +12,7 @@ public function countryCode(): string protected function allHolidays(int $year): array { $holidays = array_merge([ - 'New Year\'s Day' => '01-01', + "New Year's Day" => '01-01', 'Independence Day' => '07-04', 'Veterans Day' => '11-11', 'Christmas' => '12-25', @@ -30,7 +30,7 @@ protected function variableHolidays(): array { return [ 'Martin Luther King Day' => 'third monday of January', - 'Presidents\' Day' => 'third monday of February', + "Presidents' Day" => 'third monday of February', 'Memorial Day' => 'last monday of May', 'Labor Day' => 'first monday of September', 'Columbus Day' => 'second monday of October', diff --git a/src/Countries/Uzbekistan.php b/src/Countries/Uzbekistan.php index ceb3cade..05c10044 100644 --- a/src/Countries/Uzbekistan.php +++ b/src/Countries/Uzbekistan.php @@ -143,7 +143,7 @@ protected function allHolidays(int $year): array return array_merge([ 'Yangi yil' => '01-01', 'Xalqaro xotin-qizlar kuni' => '03-08', - 'Navro\'z' => '03-21', + "Navro'z" => '03-21', 'Xotira va qadrlash kuni' => '05-09', 'Mustaqillik kuni' => '09-01', 'Ustoz va murabbiylar kuni' => '10-01', @@ -162,6 +162,7 @@ protected function variableHolidays(int $year): array $holidays['Ramazon Hayiti'.$prefix] = $holiday; } } + if (isset(self::sacrificeHolidays[$year])) { foreach ((array) self::sacrificeHolidays[$year] as $key => $holiday) { $prefix = $key == 0 ? '' : ' '.($key + 1); diff --git a/src/Countries/Vietnam.php b/src/Countries/Vietnam.php index a57ae68a..4e957c2b 100644 --- a/src/Countries/Vietnam.php +++ b/src/Countries/Vietnam.php @@ -88,7 +88,7 @@ protected function getTheExtraDayForIndependenceDay(int $year): array return []; } - $independenceDay = CarbonImmutable::parse("$year-09-02")->startOfDay(); + $independenceDay = CarbonImmutable::parse("{$year}-09-02")->startOfDay(); if ($independenceDay->dayOfWeek === CarbonInterface::MONDAY) { return ['Ngày Sau Quốc Khánh' => $independenceDay->addDay()]; diff --git a/src/Countries/Wales.php b/src/Countries/Wales.php index f2ebc861..6f71942b 100644 --- a/src/Countries/Wales.php +++ b/src/Countries/Wales.php @@ -30,7 +30,7 @@ protected function allHolidays(int $year): array protected function observedHolidays(int $year): array { $holidays = [ - 'New Year\'s Day' => '01-01', + "New Year's Day" => '01-01', 'Christmas Day' => '12-25', 'Boxing Day' => '12-26', ]; diff --git a/src/Exceptions/InvalidRegion.php b/src/Exceptions/InvalidRegion.php index d27ed70d..c9742cce 100644 --- a/src/Exceptions/InvalidRegion.php +++ b/src/Exceptions/InvalidRegion.php @@ -8,6 +8,6 @@ class InvalidRegion extends RuntimeException { public static function notFound(string $region): self { - return new self("Region '$region' is not supported."); + return new self("Region '{$region}' is not supported."); } }