diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index 780a74427..80a2047bf 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -12,6 +12,7 @@ jobs: os: [ubuntu-latest] php: [8.3, 8.2, 8.1] stability: [prefer-lowest, prefer-stable] + carbon: [2.72, 3.0] name: P${{ matrix.php }} - ${{ matrix.stability }} - ${{ matrix.os }} @@ -32,7 +33,9 @@ jobs: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json" - name: Install dependencies - run: composer update --${{ matrix.stability }} --prefer-dist --no-interaction + run: | + composer update --${{ matrix.stability }} --prefer-dist --no-interaction + composer require nesbot/carbon:^${{ matrix.carbon }} --${{ matrix.stability }} -W --prefer-dist --no-interaction - name: List Installed Dependencies run: composer show -D diff --git a/composer.json b/composer.json index d51ff2f1e..46ef42ee3 100644 --- a/composer.json +++ b/composer.json @@ -22,7 +22,7 @@ "require": { "php": "^8.1", "ext-intl": "*", - "nesbot/carbon": "^2.72.1" + "nesbot/carbon": "^2.72.1|^3.0" }, "require-dev": { "laravel/pint": "^1.0", diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index b253bace3..dffb82781 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -1,34 +1,14 @@ parameters: ignoreErrors: - - - message: "#^Cannot call method modify\\(\\) on Carbon\\\\CarbonImmutable\\|false\\.$#" - count: 1 - path: src/Countries/Australia.php - - message: "#^Argument of an invalid type array\\\\|false supplied for foreach, only iterables are supported\\.$#" count: 1 path: src/Countries/Country.php - - message: "#^Cannot call method startOfDay\\(\\) on Carbon\\\\CarbonImmutable\\|false\\.$#" - count: 2 - path: src/Countries/Country.php - - - - message: "#^Method Spatie\\\\Holidays\\\\Countries\\\\Country\\:\\:get\\(\\) should return array\\ but returns array\\\\.$#" - count: 1 - path: src/Countries/Country.php - - - - message: "#^Parameter \\#2 \\$callback of function uasort expects callable\\(bool\\|Carbon\\\\CarbonImmutable, bool\\|Carbon\\\\CarbonImmutable\\)\\: int, Closure\\(Carbon\\\\CarbonImmutable, Carbon\\\\CarbonImmutable\\)\\: int\\<\\-1, 1\\> given\\.$#" - count: 1 - path: src/Countries/Country.php - - - - message: "#^Cannot call method startOfDay\\(\\) on Carbon\\\\CarbonImmutable\\|false\\.$#" - count: 2 - path: src/Countries/Sweden.php + message: "#^Ternary operator condition is always true\\.$#" + count: 3 + path: src/Countries/Turkey.php - message: "#^Cannot call method setTimeStamp\\(\\) on DateTime\\|false\\.$#" diff --git a/src/Countries/Australia.php b/src/Countries/Australia.php index 3de478baa..b17c853fa 100644 --- a/src/Countries/Australia.php +++ b/src/Countries/Australia.php @@ -41,7 +41,7 @@ protected function variableHolidays(int $year): array 'Canberra Day' => CarbonImmutable::parse("second monday of march {$year}"), 'Easter Saturday' => $easter->subDay(), 'Easter Sunday' => $easter, - 'Reconciliation Day' => CarbonImmutable::create($year, 5, 27)->modify('monday'), + 'Reconciliation Day' => CarbonImmutable::create($year, 5, 27)?->modify('monday'), $this->sovereignBirthdayKey($year) => CarbonImmutable::parse("second monday of june {$year}"), 'Labour Day' => CarbonImmutable::parse("first monday of october {$year}"), ], diff --git a/src/Countries/Colombia.php b/src/Countries/Colombia.php index f3176f794..999264e9d 100644 --- a/src/Countries/Colombia.php +++ b/src/Countries/Colombia.php @@ -3,6 +3,7 @@ namespace Spatie\Holidays\Countries; use Carbon\CarbonImmutable; +use Carbon\CarbonInterface; class Colombia extends Country { @@ -23,7 +24,7 @@ protected function allHolidays(int $year): array ], $this->variableHolidays($year)); } - /** @return array */ + /** @return array */ protected function variableHolidays(int $year): array { $easter = $this->easter($year); @@ -45,13 +46,14 @@ protected function variableHolidays(int $year): array ]; } - private function emilianiHoliday(int $year, int $month, int $day): CarbonImmutable + private function emilianiHoliday(int $year, int $month, int $day): CarbonInterface { $dateObj = CarbonImmutable::createFromDate($year, $month, $day, 'America/Bogota')->startOfDay(); + if ($dateObj->is('Monday')) { return $dateObj; - } else { - return $dateObj->next('Monday'); } + + return $dateObj->next('Monday'); } } diff --git a/src/Countries/Finland.php b/src/Countries/Finland.php index 69fa1fd39..32e75c649 100644 --- a/src/Countries/Finland.php +++ b/src/Countries/Finland.php @@ -3,6 +3,7 @@ namespace Spatie\Holidays\Countries; use Carbon\CarbonImmutable; +use Carbon\CarbonInterface; class Finland extends Country { @@ -29,7 +30,7 @@ protected function fixedHolidays(int $year): array ]; } - /** @return array */ + /** @return array */ protected function variableHolidays(int $year): array { $easter = $this->easter($year); diff --git a/src/Countries/Jamaica.php b/src/Countries/Jamaica.php index e9b3af3d4..751fb994b 100644 --- a/src/Countries/Jamaica.php +++ b/src/Countries/Jamaica.php @@ -3,6 +3,7 @@ namespace Spatie\Holidays\Countries; use Carbon\CarbonImmutable; +use Carbon\CarbonInterface; class Jamaica extends Country { @@ -52,7 +53,7 @@ protected function variableHolidays(int $year): array ]; } - /** @return array */ + /** @return array */ protected function observedHolidays(int $year): array { diff --git a/src/Countries/NorthernIreland.php b/src/Countries/NorthernIreland.php index 889fa513e..cb424980f 100644 --- a/src/Countries/NorthernIreland.php +++ b/src/Countries/NorthernIreland.php @@ -3,6 +3,7 @@ namespace Spatie\Holidays\Countries; use Carbon\CarbonImmutable; +use Carbon\CarbonInterface; class NorthernIreland extends Wales { @@ -11,7 +12,7 @@ public function countryCode(): string return 'gb-nir'; } - /** @return array */ + /** @return array */ private function stPatricksDay(int $year): array { $stPatricksDay = new CarbonImmutable($year.'-03-17', 'Europe/London'); @@ -25,7 +26,7 @@ private function stPatricksDay(int $year): array return [$key => $stPatricksDay]; } - /** @return array */ + /** @return array */ private function battleOfTheBoyne(int $year): array { $battleOfTheBoyne = new CarbonImmutable($year.'-07-12', 'Europe/London'); @@ -51,7 +52,7 @@ protected function oneOffHolidays(int $year): array }; } - /** @return array */ + /** @return array */ protected function allHolidays(int $year): array { $regularHolidays = array_merge( diff --git a/src/Countries/Scotland.php b/src/Countries/Scotland.php index 09e2ea097..f70145325 100644 --- a/src/Countries/Scotland.php +++ b/src/Countries/Scotland.php @@ -3,6 +3,7 @@ namespace Spatie\Holidays\Countries; use Carbon\CarbonImmutable; +use Carbon\CarbonInterface; class Scotland extends Wales { @@ -11,7 +12,7 @@ public function countryCode(): string return 'gb-sct'; } - /** @return array */ + /** @return array */ protected function secondOfJanuary(int $year): array { $newYearsDay = new CarbonImmutable($year.'-01-01', 'Europe/London'); @@ -31,7 +32,7 @@ protected function secondOfJanuary(int $year): array return [$key => $secondOfJanuary]; } - /** @return array */ + /** @return array */ private function stAndrewsDay(int $year): array { $stAndrewsDay = new CarbonImmutable($year.'-11-30', 'Europe/London'); @@ -45,7 +46,7 @@ private function stAndrewsDay(int $year): array return [$key => $stAndrewsDay]; } - /** @return array */ + /** @return array */ protected function oneOffHolidays(int $year): array { return match ($year) { @@ -57,7 +58,7 @@ protected function oneOffHolidays(int $year): array }; } - /** @return array */ + /** @return array */ protected function allHolidays(int $year): array { $regularHolidays = array_merge( diff --git a/src/Countries/Sweden.php b/src/Countries/Sweden.php index e16eae6eb..fce4f7135 100644 --- a/src/Countries/Sweden.php +++ b/src/Countries/Sweden.php @@ -24,7 +24,7 @@ protected function allHolidays(int $year): array ], $this->variableHolidays($year)); } - /** @return array */ + /** @return array */ protected function variableHolidays(int $year): array { $easter = $this->easter($year); diff --git a/src/Countries/Wales.php b/src/Countries/Wales.php index 7468ba889..33e1ca3b8 100644 --- a/src/Countries/Wales.php +++ b/src/Countries/Wales.php @@ -3,6 +3,7 @@ namespace Spatie\Holidays\Countries; use Carbon\CarbonImmutable; +use Carbon\CarbonInterface; class Wales extends Country { @@ -11,7 +12,7 @@ public function countryCode(): string return 'gb-cym'; } - /** @return array */ + /** @return array */ protected function christmasDay(int $year): array { $christmasDay = new CarbonImmutable($year.'-12-25', 'Europe/London'); @@ -30,7 +31,7 @@ protected function christmasDay(int $year): array return [$key => $christmasDay]; } - /** @return array */ + /** @return array */ protected function boxingDay(int $year): array { $christmasDay = new CarbonImmutable($year.'-12-25', 'Europe/London'); @@ -50,7 +51,7 @@ protected function boxingDay(int $year): array return [$key => $boxingDay]; } - /** @return array */ + /** @return array */ protected function newYearsDay(int $year): array { $newYearsDay = new CarbonImmutable($year.'-01-01', 'Europe/London'); @@ -64,7 +65,7 @@ protected function newYearsDay(int $year): array return [$key => $newYearsDay]; } - /** @return array */ + /** @return array */ protected function earlyMayBankHoliday(int $year): array { if ($year === 2020) { @@ -96,7 +97,7 @@ protected function oneOffHolidays(int $year): array }; } - /** @return array */ + /** @return array */ protected function allHolidays(int $year): array { $regularHolidays = array_merge(