Skip to content

Commit 686f893

Browse files
authored
Merge pull request #204 from spatie/carbon-3
Add support for Carbon v3
2 parents fc6c650 + 34d6ccd commit 686f893

11 files changed

+35
-45
lines changed

.github/workflows/run-tests.yml

+4-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ jobs:
1212
os: [ubuntu-latest]
1313
php: [8.3, 8.2, 8.1]
1414
stability: [prefer-lowest, prefer-stable]
15+
carbon: [2.72, 3.0]
1516

1617
name: P${{ matrix.php }} - ${{ matrix.stability }} - ${{ matrix.os }}
1718

@@ -32,7 +33,9 @@ jobs:
3233
echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"
3334
3435
- name: Install dependencies
35-
run: composer update --${{ matrix.stability }} --prefer-dist --no-interaction
36+
run: |
37+
composer update --${{ matrix.stability }} --prefer-dist --no-interaction
38+
composer require nesbot/carbon:^${{ matrix.carbon }} --${{ matrix.stability }} -W --prefer-dist --no-interaction
3639
3740
- name: List Installed Dependencies
3841
run: composer show -D

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"require": {
2323
"php": "^8.1",
2424
"ext-intl": "*",
25-
"nesbot/carbon": "^2.72.1"
25+
"nesbot/carbon": "^2.72.1|^3.0"
2626
},
2727
"require-dev": {
2828
"laravel/pint": "^1.0",

phpstan-baseline.neon

+3-23
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,14 @@
11
parameters:
22
ignoreErrors:
3-
-
4-
message: "#^Cannot call method modify\\(\\) on Carbon\\\\CarbonImmutable\\|false\\.$#"
5-
count: 1
6-
path: src/Countries/Australia.php
7-
83
-
94
message: "#^Argument of an invalid type array\\<int, string\\>\\|false supplied for foreach, only iterables are supported\\.$#"
105
count: 1
116
path: src/Countries/Country.php
127

138
-
14-
message: "#^Cannot call method startOfDay\\(\\) on Carbon\\\\CarbonImmutable\\|false\\.$#"
15-
count: 2
16-
path: src/Countries/Country.php
17-
18-
-
19-
message: "#^Method Spatie\\\\Holidays\\\\Countries\\\\Country\\:\\:get\\(\\) should return array\\<string, Carbon\\\\CarbonImmutable\\|string\\> but returns array\\<string, Carbon\\\\CarbonImmutable\\|false\\>\\.$#"
20-
count: 1
21-
path: src/Countries/Country.php
22-
23-
-
24-
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\\.$#"
25-
count: 1
26-
path: src/Countries/Country.php
27-
28-
-
29-
message: "#^Cannot call method startOfDay\\(\\) on Carbon\\\\CarbonImmutable\\|false\\.$#"
30-
count: 2
31-
path: src/Countries/Sweden.php
9+
message: "#^Ternary operator condition is always true\\.$#"
10+
count: 3
11+
path: src/Countries/Turkey.php
3212

3313
-
3414
message: "#^Cannot call method setTimeStamp\\(\\) on DateTime\\|false\\.$#"

src/Countries/Australia.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ protected function variableHolidays(int $year): array
4141
'Canberra Day' => CarbonImmutable::parse("second monday of march {$year}"),
4242
'Easter Saturday' => $easter->subDay(),
4343
'Easter Sunday' => $easter,
44-
'Reconciliation Day' => CarbonImmutable::create($year, 5, 27)->modify('monday'),
44+
'Reconciliation Day' => CarbonImmutable::create($year, 5, 27)?->modify('monday'),
4545
$this->sovereignBirthdayKey($year) => CarbonImmutable::parse("second monday of june {$year}"),
4646
'Labour Day' => CarbonImmutable::parse("first monday of october {$year}"),
4747
],

src/Countries/Colombia.php

+6-4
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Spatie\Holidays\Countries;
44

55
use Carbon\CarbonImmutable;
6+
use Carbon\CarbonInterface;
67

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

26-
/** @return array<string, CarbonImmutable> */
27+
/** @return array<string, CarbonInterface> */
2728
protected function variableHolidays(int $year): array
2829
{
2930
$easter = $this->easter($year);
@@ -45,13 +46,14 @@ protected function variableHolidays(int $year): array
4546
];
4647
}
4748

48-
private function emilianiHoliday(int $year, int $month, int $day): CarbonImmutable
49+
private function emilianiHoliday(int $year, int $month, int $day): CarbonInterface
4950
{
5051
$dateObj = CarbonImmutable::createFromDate($year, $month, $day, 'America/Bogota')->startOfDay();
52+
5153
if ($dateObj->is('Monday')) {
5254
return $dateObj;
53-
} else {
54-
return $dateObj->next('Monday');
5555
}
56+
57+
return $dateObj->next('Monday');
5658
}
5759
}

src/Countries/Finland.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Spatie\Holidays\Countries;
44

55
use Carbon\CarbonImmutable;
6+
use Carbon\CarbonInterface;
67

78
class Finland extends Country
89
{
@@ -29,7 +30,7 @@ protected function fixedHolidays(int $year): array
2930
];
3031
}
3132

32-
/** @return array<string, CarbonImmutable> */
33+
/** @return array<string, CarbonInterface> */
3334
protected function variableHolidays(int $year): array
3435
{
3536
$easter = $this->easter($year);

src/Countries/Jamaica.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Spatie\Holidays\Countries;
44

55
use Carbon\CarbonImmutable;
6+
use Carbon\CarbonInterface;
67

78
class Jamaica extends Country
89
{
@@ -52,7 +53,7 @@ protected function variableHolidays(int $year): array
5253
];
5354
}
5455

55-
/** @return array<string, CarbonImmutable> */
56+
/** @return array<string, CarbonInterface> */
5657
protected function observedHolidays(int $year): array
5758
{
5859

src/Countries/NorthernIreland.php

+4-3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Spatie\Holidays\Countries;
44

55
use Carbon\CarbonImmutable;
6+
use Carbon\CarbonInterface;
67

78
class NorthernIreland extends Wales
89
{
@@ -11,7 +12,7 @@ public function countryCode(): string
1112
return 'gb-nir';
1213
}
1314

14-
/** @return array<string, CarbonImmutable> */
15+
/** @return array<string, CarbonInterface> */
1516
private function stPatricksDay(int $year): array
1617
{
1718
$stPatricksDay = new CarbonImmutable($year.'-03-17', 'Europe/London');
@@ -25,7 +26,7 @@ private function stPatricksDay(int $year): array
2526
return [$key => $stPatricksDay];
2627
}
2728

28-
/** @return array<string, CarbonImmutable> */
29+
/** @return array<string, CarbonInterface> */
2930
private function battleOfTheBoyne(int $year): array
3031
{
3132
$battleOfTheBoyne = new CarbonImmutable($year.'-07-12', 'Europe/London');
@@ -51,7 +52,7 @@ protected function oneOffHolidays(int $year): array
5152
};
5253
}
5354

54-
/** @return array<string, CarbonImmutable> */
55+
/** @return array<string, CarbonInterface> */
5556
protected function allHolidays(int $year): array
5657
{
5758
$regularHolidays = array_merge(

src/Countries/Scotland.php

+5-4
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Spatie\Holidays\Countries;
44

55
use Carbon\CarbonImmutable;
6+
use Carbon\CarbonInterface;
67

78
class Scotland extends Wales
89
{
@@ -11,7 +12,7 @@ public function countryCode(): string
1112
return 'gb-sct';
1213
}
1314

14-
/** @return array<string, CarbonImmutable> */
15+
/** @return array<string, CarbonInterface> */
1516
protected function secondOfJanuary(int $year): array
1617
{
1718
$newYearsDay = new CarbonImmutable($year.'-01-01', 'Europe/London');
@@ -31,7 +32,7 @@ protected function secondOfJanuary(int $year): array
3132
return [$key => $secondOfJanuary];
3233
}
3334

34-
/** @return array<string, CarbonImmutable> */
35+
/** @return array<string, CarbonInterface> */
3536
private function stAndrewsDay(int $year): array
3637
{
3738
$stAndrewsDay = new CarbonImmutable($year.'-11-30', 'Europe/London');
@@ -45,7 +46,7 @@ private function stAndrewsDay(int $year): array
4546
return [$key => $stAndrewsDay];
4647
}
4748

48-
/** @return array<string, CarbonImmutable> */
49+
/** @return array<string, CarbonInterface> */
4950
protected function oneOffHolidays(int $year): array
5051
{
5152
return match ($year) {
@@ -57,7 +58,7 @@ protected function oneOffHolidays(int $year): array
5758
};
5859
}
5960

60-
/** @return array<string, CarbonImmutable> */
61+
/** @return array<string, CarbonInterface> */
6162
protected function allHolidays(int $year): array
6263
{
6364
$regularHolidays = array_merge(

src/Countries/Sweden.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ protected function allHolidays(int $year): array
2424
], $this->variableHolidays($year));
2525
}
2626

27-
/** @return array<string, CarbonImmutable> */
27+
/** @return array<string, CarbonInterface> */
2828
protected function variableHolidays(int $year): array
2929
{
3030
$easter = $this->easter($year);

src/Countries/Wales.php

+6-5
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Spatie\Holidays\Countries;
44

55
use Carbon\CarbonImmutable;
6+
use Carbon\CarbonInterface;
67

78
class Wales extends Country
89
{
@@ -11,7 +12,7 @@ public function countryCode(): string
1112
return 'gb-cym';
1213
}
1314

14-
/** @return array<string, CarbonImmutable> */
15+
/** @return array<string, CarbonInterface> */
1516
protected function christmasDay(int $year): array
1617
{
1718
$christmasDay = new CarbonImmutable($year.'-12-25', 'Europe/London');
@@ -30,7 +31,7 @@ protected function christmasDay(int $year): array
3031
return [$key => $christmasDay];
3132
}
3233

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

53-
/** @return array<string, CarbonImmutable> */
54+
/** @return array<string, CarbonInterface> */
5455
protected function newYearsDay(int $year): array
5556
{
5657
$newYearsDay = new CarbonImmutable($year.'-01-01', 'Europe/London');
@@ -64,7 +65,7 @@ protected function newYearsDay(int $year): array
6465
return [$key => $newYearsDay];
6566
}
6667

67-
/** @return array<string, CarbonImmutable> */
68+
/** @return array<string, CarbonInterface> */
6869
protected function earlyMayBankHoliday(int $year): array
6970
{
7071
if ($year === 2020) {
@@ -96,7 +97,7 @@ protected function oneOffHolidays(int $year): array
9697
};
9798
}
9899

99-
/** @return array<string, CarbonImmutable> */
100+
/** @return array<string, CarbonInterface> */
100101
protected function allHolidays(int $year): array
101102
{
102103
$regularHolidays = array_merge(

0 commit comments

Comments
 (0)