Skip to content

Commit

Permalink
Fix styling
Browse files Browse the repository at this point in the history
  • Loading branch information
herpaderpaldent authored and github-actions[bot] committed Jan 29, 2024
1 parent daaa26c commit 1d4d3eb
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 30 deletions.
48 changes: 24 additions & 24 deletions src/Countries/Switzerland.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,13 @@

use _PHPStan_3d4486d07\Nette\Neon\Exception;
use Carbon\CarbonImmutable;
use Spatie\Holidays\Concerns\Translatable;
use Spatie\Holidays\Exceptions\InvalidRegion;

class Switzerland extends Country
{


public function __construct(
protected ?string $region = null
)
{
) {
}

public function countryCode(): string
Expand All @@ -25,7 +21,7 @@ public function countryCode(): string
protected function allHolidays(int $year): array
{

$holidays = array_merge([
$holidays = array_merge([
'Swiss National Day' => '08-01',
],
$this->getCatonalHolidays($year),
Expand All @@ -37,6 +33,7 @@ protected function allHolidays(int $year): array
/**
* This defaults to SBB/CFF/FFS holidays or postal holidays
* https://github.com/spatie/holidays/pull/49/files#r1462344840
*
* @return non-empty-array<int|string, array<string, string>|string>
*/
private function getDefaultSwissHolidays(int $year): array
Expand All @@ -54,12 +51,12 @@ private function getDefaultSwissHolidays(int $year): array
}

/** @return non-empty-array<string, string> */
private function getVariableHoliday(int $year, string $holiday) : array
private function getVariableHoliday(int $year, string $holiday): array
{
$easter = $this->easter($year);

$value = match ($holiday) {
'Good Friday' => $easter->subDays(2),
'Good Friday' => $easter->subDays(2),
'Easter Monday' => $easter->addDay(),
'Ascension Day' => $easter->addDays(39),
'Whit Monday' => $easter->addDays(50),
Expand All @@ -72,25 +69,26 @@ private function getVariableHoliday(int $year, string $holiday) : array
}

/**
* @param non-empty-array<int|string, array<string, string>|string> $holidays
* @param non-empty-array<int|string, array<string, string>|string> $holidays
* @return array<string, string>
*/
private function normalizeHolidayArray(array $holidays) : array
private function normalizeHolidayArray(array $holidays): array
{

$normalized_holidays = [];

foreach ($holidays as $key => $value) {
if(is_array($value)) {
if (is_array($value)) {

foreach ($value as $sub_key => $sub_value) {
$normalized_holidays[$sub_key] = $sub_value;

}

continue;
}

if(is_string($key)) {
if (is_string($key)) {
$normalized_holidays[$key] = $value;
}
}
Expand All @@ -104,8 +102,9 @@ private function normalizeHolidayArray(array $holidays) : array
private function getCatonalHolidays(int $year): array

Check failure on line 102 in src/Countries/Switzerland.php

View workflow job for this annotation

GitHub Actions / phpstan

PHPDoc tag @throws with type _PHPStan_3d4486d07\Nette\Neon\Exception is not subtype of Throwable
{

if($this->region === null) {
if ($this->region === null) {
$default_holidays = $this->getDefaultSwissHolidays($year);

return $this->normalizeHolidayArray($default_holidays);
}

Expand Down Expand Up @@ -152,7 +151,7 @@ private function createCarbonImmutable(int $year, int $month, int $day): CarbonI
$carbon_immutable = CarbonImmutable::createFromFormat('Y-m-d', "{$year}-{$month}-{$day}");

// check if the date is valid
if(!$carbon_immutable) {
if (! $carbon_immutable) {
throw new Exception('Invalid date');

Check failure on line 155 in src/Countries/Switzerland.php

View workflow job for this annotation

GitHub Actions / phpstan

Instantiated class _PHPStan_3d4486d07\Nette\Neon\Exception not found.

Check failure on line 155 in src/Countries/Switzerland.php

View workflow job for this annotation

GitHub Actions / phpstan

Throwing object of an unknown class _PHPStan_3d4486d07\Nette\Neon\Exception.
}

Expand Down Expand Up @@ -271,6 +270,7 @@ private function getBEHolidays(int $year): array
/**
* except some municipalities in the "Bezirk See / district du Lac" do not share these holidays.
* These holidays are only valid for the canton however, not for these municipalities.
*
* @return non-empty-array<int|string, array<string, string>|string>
*/
private function getFRHolidays(int $year): array
Expand Down Expand Up @@ -436,7 +436,7 @@ private function getNWHolidays(int $year): array
}

/** @return non-empty-array<int|string, array<string, string>|string > */
private function getOWHolidays(int $year) : array
private function getOWHolidays(int $year): array
{
return array_merge([
'New Year\'s Day' => '01-01',
Expand All @@ -457,7 +457,7 @@ private function getOWHolidays(int $year) : array
}

/** @return non-empty-array<int|string, array<string, string>|string > */
private function getSHHolidays(int $year) : array
private function getSHHolidays(int $year): array
{
return array_merge([
'New Year\'s Day' => '01-01',
Expand All @@ -474,7 +474,7 @@ private function getSHHolidays(int $year) : array
}

/** @return non-empty-array<int|string, array<string, string>|string > */
private function getSZHolidays(int $year) : array
private function getSZHolidays(int $year): array
{
return [
'New Year\'s Day' => '01-01',
Expand All @@ -494,7 +494,7 @@ private function getSZHolidays(int $year) : array
}

/** @return non-empty-array<int|string, array<string, string>|string > */
private function getSOHolidays(int $year) : array
private function getSOHolidays(int $year): array
{
return array_merge([
'New Year\'s Day' => '01-01',
Expand All @@ -513,7 +513,7 @@ private function getSOHolidays(int $year) : array
}

/** @return non-empty-array<int|string, array<string, string>|string > */
private function getSGHolidays(int $year) : array
private function getSGHolidays(int $year): array
{
return array_merge([
'New Year\'s Day' => '01-01',
Expand All @@ -530,7 +530,7 @@ private function getSGHolidays(int $year) : array
}

/** @return non-empty-array<int|string, array<string, string>|string > */
private function getTIHolidays(int $year) : array
private function getTIHolidays(int $year): array
{
return [
'New Year\'s Day' => '01-01',
Expand All @@ -551,7 +551,7 @@ private function getTIHolidays(int $year) : array
}

/** @return non-empty-array<int|string, array<string, string>|string > */
private function getTGHolidays(int $year) : array
private function getTGHolidays(int $year): array
{
return [
'New Year\'s Day' => '01-01',
Expand All @@ -567,7 +567,7 @@ private function getTGHolidays(int $year) : array
}

/** @return non-empty-array<int|string, array<string, string>|string > */
private function getURHolidays(int $year) : array
private function getURHolidays(int $year): array
{
return [
'New Year\'s Day' => '01-01',
Expand All @@ -587,7 +587,7 @@ private function getURHolidays(int $year) : array
}

/** @return non-empty-array<int|string, array<string, string>|string > */
private function getVDHolidays(int $year) : array
private function getVDHolidays(int $year): array
{
return [
'New Year\'s Day' => '01-01',
Expand Down Expand Up @@ -641,7 +641,7 @@ private function getZGHolidays(int $year): array
}

/** @return non-empty-array<int|string, array<string, string>|string > */
private function getZHHolidays(int $year) : array
private function getZHHolidays(int $year): array
{
return [
'New Year\'s Day' => '01-01',
Expand Down
10 changes: 4 additions & 6 deletions tests/Countries/SwitzerlandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@
expect(formatDates($holidays))->toMatchSnapshot();
})->with('cantons');


it('throws an error when an invalid region is given', function () {
$switzerland = new Switzerland('ch-xx');
$holidays = Holidays::for($switzerland)->get();
Expand All @@ -79,7 +78,7 @@
describe('supported languages', function () {
it('shares same translations keys in every language', function () {

$filePaths = __DIR__."/../../lang/switzerland/**/holidays.json";
$filePaths = __DIR__.'/../../lang/switzerland/**/holidays.json';
$filePaths = glob($filePaths);

$keysArray = [];
Expand All @@ -93,7 +92,7 @@
// Compare keys of the first JSON file with the others
for ($i = 1; $i < count($keysArray); $i++) {
$diff = array_diff($keysArray[0], $keysArray[$i]);
if (!empty($diff)) {
if (! empty($diff)) {

dump($filePaths[$i], $diff);
}
Expand Down Expand Up @@ -158,7 +157,7 @@
it('has sets jeune genevois to thursday following the first sunday in september', function (int $year, string $date) {
CarbonImmutable::setTestNowAndTimezone("$year-01-01");

$switzerland = new Switzerland("ch-ge");
$switzerland = new Switzerland('ch-ge');
$holidays = Holidays::for($switzerland);

expect($holidays->isHoliday($date))->toBeTrue();
Expand Down Expand Up @@ -190,6 +189,5 @@
'tg',
'ne',
'ju',
'ti'
'ti',
]);

0 comments on commit 1d4d3eb

Please sign in to comment.