Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Carbon v3 #204

Merged
merged 4 commits into from
Feb 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}

Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
26 changes: 3 additions & 23 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
@@ -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\\<int, string\\>\\|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\\<string, Carbon\\\\CarbonImmutable\\|string\\> but returns array\\<string, Carbon\\\\CarbonImmutable\\|false\\>\\.$#"
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\\.$#"
Expand Down
2 changes: 1 addition & 1 deletion src/Countries/Australia.php
Original file line number Diff line number Diff line change
Expand Up @@ -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}"),
],
Expand Down
10 changes: 6 additions & 4 deletions src/Countries/Colombia.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Spatie\Holidays\Countries;

use Carbon\CarbonImmutable;
use Carbon\CarbonInterface;

class Colombia extends Country
{
Expand All @@ -23,7 +24,7 @@ protected function allHolidays(int $year): array
], $this->variableHolidays($year));
}

/** @return array<string, CarbonImmutable> */
/** @return array<string, CarbonInterface> */
protected function variableHolidays(int $year): array
{
$easter = $this->easter($year);
Expand All @@ -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');
}
}
3 changes: 2 additions & 1 deletion src/Countries/Finland.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Spatie\Holidays\Countries;

use Carbon\CarbonImmutable;
use Carbon\CarbonInterface;

class Finland extends Country
{
Expand All @@ -29,7 +30,7 @@ protected function fixedHolidays(int $year): array
];
}

/** @return array<string, CarbonImmutable> */
/** @return array<string, CarbonInterface> */
protected function variableHolidays(int $year): array
{
$easter = $this->easter($year);
Expand Down
3 changes: 2 additions & 1 deletion src/Countries/Jamaica.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Spatie\Holidays\Countries;

use Carbon\CarbonImmutable;
use Carbon\CarbonInterface;

class Jamaica extends Country
{
Expand Down Expand Up @@ -52,7 +53,7 @@ protected function variableHolidays(int $year): array
];
}

/** @return array<string, CarbonImmutable> */
/** @return array<string, CarbonInterface> */
protected function observedHolidays(int $year): array
{

Expand Down
7 changes: 4 additions & 3 deletions src/Countries/NorthernIreland.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Spatie\Holidays\Countries;

use Carbon\CarbonImmutable;
use Carbon\CarbonInterface;

class NorthernIreland extends Wales
{
Expand All @@ -11,7 +12,7 @@ public function countryCode(): string
return 'gb-nir';
}

/** @return array<string, CarbonImmutable> */
/** @return array<string, CarbonInterface> */
private function stPatricksDay(int $year): array
{
$stPatricksDay = new CarbonImmutable($year.'-03-17', 'Europe/London');
Expand All @@ -25,7 +26,7 @@ private function stPatricksDay(int $year): array
return [$key => $stPatricksDay];
}

/** @return array<string, CarbonImmutable> */
/** @return array<string, CarbonInterface> */
private function battleOfTheBoyne(int $year): array
{
$battleOfTheBoyne = new CarbonImmutable($year.'-07-12', 'Europe/London');
Expand All @@ -51,7 +52,7 @@ protected function oneOffHolidays(int $year): array
};
}

/** @return array<string, CarbonImmutable> */
/** @return array<string, CarbonInterface> */
protected function allHolidays(int $year): array
{
$regularHolidays = array_merge(
Expand Down
9 changes: 5 additions & 4 deletions src/Countries/Scotland.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Spatie\Holidays\Countries;

use Carbon\CarbonImmutable;
use Carbon\CarbonInterface;

class Scotland extends Wales
{
Expand All @@ -11,7 +12,7 @@ public function countryCode(): string
return 'gb-sct';
}

/** @return array<string, CarbonImmutable> */
/** @return array<string, CarbonInterface> */
protected function secondOfJanuary(int $year): array
{
$newYearsDay = new CarbonImmutable($year.'-01-01', 'Europe/London');
Expand All @@ -31,7 +32,7 @@ protected function secondOfJanuary(int $year): array
return [$key => $secondOfJanuary];
}

/** @return array<string, CarbonImmutable> */
/** @return array<string, CarbonInterface> */
private function stAndrewsDay(int $year): array
{
$stAndrewsDay = new CarbonImmutable($year.'-11-30', 'Europe/London');
Expand All @@ -45,7 +46,7 @@ private function stAndrewsDay(int $year): array
return [$key => $stAndrewsDay];
}

/** @return array<string, CarbonImmutable> */
/** @return array<string, CarbonInterface> */
protected function oneOffHolidays(int $year): array
{
return match ($year) {
Expand All @@ -57,7 +58,7 @@ protected function oneOffHolidays(int $year): array
};
}

/** @return array<string, CarbonImmutable> */
/** @return array<string, CarbonInterface> */
protected function allHolidays(int $year): array
{
$regularHolidays = array_merge(
Expand Down
2 changes: 1 addition & 1 deletion src/Countries/Sweden.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ protected function allHolidays(int $year): array
], $this->variableHolidays($year));
}

/** @return array<string, CarbonImmutable> */
/** @return array<string, CarbonInterface> */
protected function variableHolidays(int $year): array
{
$easter = $this->easter($year);
Expand Down
11 changes: 6 additions & 5 deletions src/Countries/Wales.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Spatie\Holidays\Countries;

use Carbon\CarbonImmutable;
use Carbon\CarbonInterface;

class Wales extends Country
{
Expand All @@ -11,7 +12,7 @@ public function countryCode(): string
return 'gb-cym';
}

/** @return array<string, CarbonImmutable> */
/** @return array<string, CarbonInterface> */
protected function christmasDay(int $year): array
{
$christmasDay = new CarbonImmutable($year.'-12-25', 'Europe/London');
Expand All @@ -30,7 +31,7 @@ protected function christmasDay(int $year): array
return [$key => $christmasDay];
}

/** @return array<string, CarbonImmutable> */
/** @return array<string, CarbonInterface> */
protected function boxingDay(int $year): array
{
$christmasDay = new CarbonImmutable($year.'-12-25', 'Europe/London');
Expand All @@ -50,7 +51,7 @@ protected function boxingDay(int $year): array
return [$key => $boxingDay];
}

/** @return array<string, CarbonImmutable> */
/** @return array<string, CarbonInterface> */
protected function newYearsDay(int $year): array
{
$newYearsDay = new CarbonImmutable($year.'-01-01', 'Europe/London');
Expand All @@ -64,7 +65,7 @@ protected function newYearsDay(int $year): array
return [$key => $newYearsDay];
}

/** @return array<string, CarbonImmutable> */
/** @return array<string, CarbonInterface> */
protected function earlyMayBankHoliday(int $year): array
{
if ($year === 2020) {
Expand Down Expand Up @@ -96,7 +97,7 @@ protected function oneOffHolidays(int $year): array
};
}

/** @return array<string, CarbonImmutable> */
/** @return array<string, CarbonInterface> */
protected function allHolidays(int $year): array
{
$regularHolidays = array_merge(
Expand Down