generated from spatie/package-skeleton-php
-
-
Notifications
You must be signed in to change notification settings - Fork 197
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'spatie:main' into add-us-holidays
- Loading branch information
Showing
90 changed files
with
2,811 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,3 +13,6 @@ trim_trailing_whitespace = false | |
|
||
[*.{yml,yaml}] | ||
indent_size = 2 | ||
|
||
[*.snap] | ||
insert_final_newline = false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# Contributing a new country ? | ||
|
||
* [ ] Have you checked to ensure there aren't other open [Pull Requests](https://github.com/spatie/holidays/pulls) for the same country? | ||
|
||
1. Create a new class in the Countries directory. It should extend the Country class. | ||
2. Add a test for the new country in the tests directory. | ||
3. Run the tests so a snapshot gets created. | ||
4. Verify the result in the newly created snapshot is correct. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,6 @@ | ||
name: Fix PHP code style issues | ||
|
||
on: | ||
push: | ||
paths: | ||
- '**.php' | ||
on: [push] | ||
|
||
permissions: | ||
contents: write | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
name: PHPStan | ||
|
||
on: [push] | ||
on: [push, pull_request] | ||
|
||
jobs: | ||
phpstan: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
.php_cs | ||
.php_cs.cache | ||
.phpunit.cache | ||
.vscode | ||
build | ||
composer.lock | ||
coverage | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,41 @@ | ||
parameters: | ||
ignoreErrors: | ||
- | ||
message: "#^Method Spatie\\\\Holidays\\\\Countries\\\\Belgium\\:\\:allHolidays\\(\\) should return array\\<string, Carbon\\\\CarbonImmutable\\> but returns array\\<string, Carbon\\\\CarbonImmutable\\|string\\>\\.$#" | ||
count: 1 | ||
path: src/Countries/Belgium.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: "#^Method Spatie\\\\Holidays\\\\Countries\\\\Country\\:\\:get\\(\\) should return array\\<string, Carbon\\\\CarbonImmutable\\> but returns array\\<string, Carbon\\\\CarbonImmutable\\|false\\>\\.$#" | ||
message: "#^Cannot call method startOfDay\\(\\) on 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\\.$#" | ||
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: "#^Method Spatie\\\\Holidays\\\\Countries\\\\Hungary\\:\\:allHolidays\\(\\) should return array\\<string, Carbon\\\\CarbonImmutable\\> but returns array\\<string, Carbon\\\\CarbonImmutable\\|string\\>\\.$#" | ||
message: "#^Parameter \\#1 \\$timestamp of static method Carbon\\\\CarbonImmutable\\:\\:createFromTimestamp\\(\\) expects float\\|int\\|string, int\\|false given\\.$#" | ||
count: 1 | ||
path: src/Countries/Hungary.php | ||
path: src/Countries/Country.php | ||
|
||
- | ||
message: "#^Cannot call method isSunday\\(\\) on Carbon\\\\CarbonImmutable\\|false\\.$#" | ||
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/Netherlands.php | ||
path: src/Countries/Country.php | ||
|
||
- | ||
message: "#^Cannot call method subDay\\(\\) on Carbon\\\\CarbonImmutable\\|false\\.$#" | ||
message: "#^Cannot call method setTimezone\\(\\) on Carbon\\\\CarbonImmutable\\|false\\.$#" | ||
count: 1 | ||
path: src/Countries/Netherlands.php | ||
path: src/Countries/Mexico.php | ||
|
||
- | ||
message: "#^Method Spatie\\\\Holidays\\\\Countries\\\\Netherlands\\:\\:variableHolidays\\(\\) should return array\\<string, Carbon\\\\CarbonImmutable\\> but returns array\\<string, Carbon\\\\CarbonImmutable\\|false\\>\\.$#" | ||
message: "#^Parameter \\#1 \\$callback of function array_map expects \\(callable\\(Carbon\\\\CarbonImmutable\\)\\: mixed\\)\\|null, Closure\\(string\\)\\: non\\-falsy\\-string given\\.$#" | ||
count: 1 | ||
path: src/Countries/Netherlands.php | ||
path: src/Holidays.php | ||
|
||
- | ||
message: "#^Parameter \\#1 \\$callback of function array_map expects \\(callable\\(Carbon\\\\CarbonImmutable\\)\\: mixed\\)\\|null, Closure\\(string\\)\\: non\\-falsy\\-string given\\.$#" | ||
message: "#^Property Spatie\\\\Holidays\\\\Holidays\\:\\:\\$holidays \\(array\\<string, Carbon\\\\CarbonImmutable\\>\\) does not accept array\\<string, Carbon\\\\CarbonImmutable\\|string\\>\\.$#" | ||
count: 1 | ||
path: src/Holidays.php |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
use Spatie\Holidays\Countries\Country; | ||
use Spatie\Holidays\Holidays; | ||
|
||
use function Laravel\Prompts\select; | ||
|
||
require __DIR__.'/vendor/autoload.php'; | ||
|
||
$countries = []; | ||
|
||
foreach (glob(__DIR__.'/src/Countries/*.php') as $filename) { // @phpstan-ignore-line | ||
$countryClass = '\\Spatie\\Holidays\\Countries\\'.basename($filename, '.php'); | ||
|
||
if (basename($filename) === 'Country.php') { | ||
continue; | ||
} | ||
|
||
$countries[$countryClass] = str_replace('\\Spatie\\Holidays\\Countries\\', '', $countryClass); | ||
} | ||
|
||
/** @var Country $class */ | ||
$class = select('Select a country', $countries); | ||
|
||
$result = collect(Holidays::for($class::make())->get()) | ||
->map(fn (array $holiday) => [ | ||
'name' => $holiday['name'], | ||
'date' => $holiday['date']->format('Y-m-d'), // @phpstan-ignore-line | ||
])->toArray(); | ||
|
||
dd($result); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
|
||
namespace Spatie\Holidays\Countries; | ||
|
||
use Carbon\CarbonImmutable; | ||
|
||
class Andorra extends Country | ||
{ | ||
public function countryCode(): string | ||
{ | ||
return 'ad'; | ||
} | ||
|
||
protected function allHolidays(int $year): array | ||
{ | ||
return array_merge([ | ||
'Any nou' => '01-01', | ||
'Reis' => '01-06', | ||
'Dia de la Constitució' => '03-14', | ||
'Festa del Treball' => '05-01', | ||
'Assumpció' => '08-15', | ||
'Mare de Déu de Meritxell' => '09-08', | ||
'Tots Sants' => '11-01', | ||
'Immaculada Concepció' => '11-08', | ||
'Nadal' => '12-25', | ||
'Sant Esteve' => '12-26', | ||
], $this->variableHolidays($year)); | ||
} | ||
|
||
/** @return array<string, CarbonImmutable> */ | ||
protected function variableHolidays(int $year): array | ||
{ | ||
$easter = $this->easter($year); | ||
|
||
return [ | ||
'Divendres Sant' => $easter->subDays(2), | ||
'Dilluns de Pasqua' => $easter->addDay(), | ||
'Dilluns de Pentecosta' => $easter->addDays(50), | ||
]; | ||
} | ||
} |
Oops, something went wrong.