Skip to content

Commit

Permalink
Fix code style
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeremy Nikolic committed Dec 2, 2021
1 parent c7caff9 commit 61bae63
Show file tree
Hide file tree
Showing 6 changed files with 125 additions and 124 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@
"phpcbf": "vendor/bin/phpcbf",
"rector-ci": "vendor/bin/rector process --dry-run --ansi",
"rector": "vendor/bin/rector process --ansi",
"pest:test": "pest --colors=always --stop-on-failure"
"pest:test": "pest --colors=always"
}
}
10 changes: 5 additions & 5 deletions src/Calendars/YasumiUkCalendar.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,21 @@ class YasumiUkCalendar implements UkCalendar
public function isWeekendDay(Carbon $date): bool
{
return $this->getCalendar($date)
->isWeekendDay($date);
->isWeekendDay($date);
}

public function isHoliday(Carbon $date): bool
{
return $this->getCalendar($date)
->isHoliday($date);
->isHoliday($date);
}

public function isWorkingDay(Carbon $date): bool
{
$ukCalendar = $this->getCalendar($date);

return ! $ukCalendar->isWeekendDay($date)
&& ! $ukCalendar->isHoliday($date);
return !$ukCalendar->isWeekendDay($date)
&& !$ukCalendar->isHoliday($date);
}

public function closestFuturWorkingDay(Carbon $date): Carbon
Expand All @@ -47,7 +47,7 @@ protected function closestWorkingDay(Carbon $date, int $direction): Carbon
{
$workingDay = $date->copy();

while (! $this->isWorkingDay($workingDay)) {
while (!$this->isWorkingDay($workingDay)) {
$workingDay->addDays($direction);
}

Expand Down
22 changes: 11 additions & 11 deletions src/UkTaxAllowanceCalculator.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ public function weeklyEndDatesBetween(Carbon $start, Carbon $end): Collection
{
$insideDates = collect(
CarbonInterval::week()
->toPeriod($start, $end)
->toPeriod($start, $end)
)
->map(fn(Carbon $date) => $date->endOfWeek())
->reject(fn(Carbon $date) => $date->isAfter($end));

$sundaysHovered = CarbonInterval::day()
->toPeriod($start, $end, CarbonPeriod::EXCLUDE_END_DATE)
->filter(fn(Carbon $carbon) => $carbon->isSunday());
->toPeriod($start, $end, CarbonPeriod::EXCLUDE_END_DATE)
->filter(fn(Carbon $carbon) => $carbon->isSunday());

if ($sundaysHovered->count() >= $insideDates->count()) {
$insideDates->push($end->copy());
Expand All @@ -51,15 +51,15 @@ public function monthlyEndDatesBetween(Carbon $start, Carbon $end): Collection
$dateEnd = $this->calendar->closestPastWorkingDay($end);

if ($dateStart->isSameMonth($dateEnd)) {
return collect([ $dateEnd->copy() ]);
return collect([$dateEnd->copy()]);
}

$months = collect(
CarbonInterval::day()
->toPeriod($dateStart, $dateEnd)
->filter(
fn(Carbon $day) => $day->isSameDay($this->lastWorkingDayOfTheMonth($day))
)
->toPeriod($dateStart, $dateEnd)
->filter(
fn(Carbon $day) => $day->isSameDay($this->lastWorkingDayOfTheMonth($day))
)
);

if ($dateEnd->isBefore($this->lastWorkingDayOfTheMonth($dateEnd))) {
Expand All @@ -78,7 +78,7 @@ public function monthly(Carbon $start, Carbon $end): int
{
// This counts the last months working days included in the period
return $this->monthlyEndDatesBetween($start, $end)
->count();
->count();
}

public function lastWorkingDayOfTheMonth(Carbon $day): Carbon
Expand All @@ -91,7 +91,7 @@ public function lastWorkingDayOfTheMonth(Carbon $day): Carbon

protected function isWorkingDay(Carbon $carbon): bool
{
return ! $this->calendar->isWeekendDay($carbon)
&& ! $this->calendar->isHoliday($carbon);
return !$this->calendar->isWeekendDay($carbon)
&& !$this->calendar->isHoliday($carbon);
}
}
12 changes: 6 additions & 6 deletions tests/Calendars/YasumiUkCalendarTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@

expect($closestPastWorkingDay->toDateString())->toEqual($expectedClosestPastWorkingDay);
})->with([
[ '2021-04-02', '2021-04-01' ],
[ '2021-05-29', '2021-05-28' ],
]);
['2021-04-02', '2021-04-01'],
['2021-05-29', '2021-05-28'],
]);

it('returns correct closest future working day', function ($day, $expectedClosestFutureWorkingDay) {
$day = Carbon::createFromFormat('Y-m-d', $day);
$closestFutureWorkingDay = $this->calendar->closestFuturWorkingDay($day);

expect($closestFutureWorkingDay->toDateString())->toEqual($expectedClosestFutureWorkingDay);
})->with([
[ '2021-04-02', '2021-04-06' ],
[ '2021-05-29', '2021-06-01' ],
]);
['2021-04-02', '2021-04-06'],
['2021-05-29', '2021-06-01'],
]);
3 changes: 2 additions & 1 deletion tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@

class TestCase extends OrchestraTestCase
{
protected function getPackageProviders($app): array {
protected function getPackageProviders($app): array
{
return [UkTaxAllowanceServiceProvider::class];
}
}
200 changes: 100 additions & 100 deletions tests/UkTaxAllowanceCalculatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,133 +10,133 @@

it('returns valid week end dates', function ($start, $end, $endDates) {
$start = Carbon::createFromFormat('Y-m-d', $start)
->startOfDay();
->startOfDay();
$end = Carbon::createFromFormat('Y-m-d', $end)
->startOfDay();
->startOfDay();

$weeklyEndDates = collect($this->taxAllowanceCalculator->weeklyEndDatesBetween($start, $end))
->map(fn(Carbon $carbon) => $carbon->toDateString())
->all();

expect($weeklyEndDates)->toEqual($endDates);
})->with([
// Start | End | Expected list of end dates
[ '2021-04-01', '2021-04-03', [ '2021-04-03' ] ],
// less than a week
[ '2021-04-03', '2021-04-06', [ '2021-04-04', '2021-04-06' ] ],
// less than a week over two weeks
[ '2021-04-05', '2021-04-05', [ '2021-04-05' ] ],
// one monday
[ '2021-04-04', '2021-04-04', [ '2021-04-04' ] ],
// one sunday
[ '2021-04-01', '2021-04-04', [ '2021-04-04' ] ],
// less than a week ending on a sunday
[ '2021-04-05', '2021-04-10', [ '2021-04-10' ] ],
// one perfect week
[ '2021-04-01', '2021-04-07', [ '2021-04-04', '2021-04-07' ] ],
// 7 days over two weeks
[ '2021-04-05', '2021-04-25', [ '2021-04-11', '2021-04-18', '2021-04-25' ] ],
// 3 perfect weeks
[ '2021-04-06', '2021-04-27', [ '2021-04-11', '2021-04-18', '2021-04-25', '2021-04-27' ] ],
// 21 days over 4 weeks
[ '2021-04-04', '2021-04-27', [ '2021-04-04', '2021-04-11', '2021-04-18', '2021-04-25', '2021-04-27' ] ],
// 23 days over 5 weeks and starting on a sunday (why not ?)
[
'2021-04-01',
'2021-05-31',
[
'2021-04-04',
'2021-04-11',
'2021-04-18',
'2021-04-25',
'2021-05-02',
'2021-05-09',
'2021-05-16',
'2021-05-23',
'2021-05-30',
'2021-05-31',
],
],
// Full April to May
]);
// Start | End | Expected list of end dates
['2021-04-01', '2021-04-03', ['2021-04-03']],
// less than a week
['2021-04-03', '2021-04-06', ['2021-04-04', '2021-04-06']],
// less than a week over two weeks
['2021-04-05', '2021-04-05', ['2021-04-05']],
// one monday
['2021-04-04', '2021-04-04', ['2021-04-04']],
// one sunday
['2021-04-01', '2021-04-04', ['2021-04-04']],
// less than a week ending on a sunday
['2021-04-05', '2021-04-10', ['2021-04-10']],
// one perfect week
['2021-04-01', '2021-04-07', ['2021-04-04', '2021-04-07']],
// 7 days over two weeks
['2021-04-05', '2021-04-25', ['2021-04-11', '2021-04-18', '2021-04-25']],
// 3 perfect weeks
['2021-04-06', '2021-04-27', ['2021-04-11', '2021-04-18', '2021-04-25', '2021-04-27']],
// 21 days over 4 weeks
['2021-04-04', '2021-04-27', ['2021-04-04', '2021-04-11', '2021-04-18', '2021-04-25', '2021-04-27']],
// 23 days over 5 weeks and starting on a sunday (why not ?)
[
'2021-04-01',
'2021-05-31',
[
'2021-04-04',
'2021-04-11',
'2021-04-18',
'2021-04-25',
'2021-05-02',
'2021-05-09',
'2021-05-16',
'2021-05-23',
'2021-05-30',
'2021-05-31',
],
],
// Full April to May
]);

it('returns valid weekly allowance intervals', function ($start, $end, $allowance) {
$start = Carbon::createFromFormat('Y-m-d', $start)
->startOfDay();
->startOfDay();
$end = Carbon::createFromFormat('Y-m-d', $end)
->startOfDay();
->startOfDay();

expect($this->taxAllowanceCalculator->weekly($start, $end))->toEqual($allowance);
})->with([
// Start date | End date | Expected allowance count
[ '2021-04-01', '2021-04-03', 1 ], // less than a week
[ '2021-04-03', '2021-04-06', 2 ], // less than a week over two weeks
[ '2021-04-05', '2021-04-05', 1 ], // one monday
[ '2021-04-04', '2021-04-04', 1 ], // one sunday
[ '2021-04-01', '2021-04-04', 1 ], // less than a week ending on a sunday
[ '2021-04-05', '2021-04-10', 1 ], // one perfect week
[ '2021-04-01', '2021-04-07', 2 ], // 7 days over two weeks
[ '2021-04-05', '2021-04-25', 3 ], // 3 perfect weeks
[ '2021-04-06', '2021-04-27', 4 ], // 21 days over 4 weeks
[ '2021-04-04', '2021-04-27', 5 ], // 23 days over 5 weeks and starting on a sunday (why not ?)
[ '2021-04-01', '2021-05-31', 10 ], // Full April to May
]);
// Start date | End date | Expected allowance count
['2021-04-01', '2021-04-03', 1], // less than a week
['2021-04-03', '2021-04-06', 2], // less than a week over two weeks
['2021-04-05', '2021-04-05', 1], // one monday
['2021-04-04', '2021-04-04', 1], // one sunday
['2021-04-01', '2021-04-04', 1], // less than a week ending on a sunday
['2021-04-05', '2021-04-10', 1], // one perfect week
['2021-04-01', '2021-04-07', 2], // 7 days over two weeks
['2021-04-05', '2021-04-25', 3], // 3 perfect weeks
['2021-04-06', '2021-04-27', 4], // 21 days over 4 weeks
['2021-04-04', '2021-04-27', 5], // 23 days over 5 weeks and starting on a sunday (why not ?)
['2021-04-01', '2021-05-31', 10], // Full April to May
]);

it('returns valid month end dates', function ($start, $end, $endDates) {
$start = Carbon::createFromFormat('Y-m-d', $start)
->startOfDay();
->startOfDay();
$end = Carbon::createFromFormat('Y-m-d', $end)
->startOfDay();
->startOfDay();
$monthEndDates = $this->taxAllowanceCalculator->monthlyEndDatesBetween($start, $end)
->map(fn(Carbon $carbon) => $carbon->toDateString())
->all();
->map(fn(Carbon $carbon) => $carbon->toDateString())
->all();

expect($monthEndDates)->toEqual($endDates);
})->with([
// Start | End | Expected list of end dates
[ '2021-04-01', '2021-04-03', [ '2021-04-01' ] ],
[ '2021-04-01', '2021-04-30', [ '2021-04-30' ] ],
[ '2021-04-01', '2021-05-10', [ '2021-04-30', '2021-05-10' ] ],
[
'2021-04-01',
'2021-09-02',
[ '2021-04-30', '2021-05-28', '2021-06-30', '2021-07-30', '2021-08-31', '2021-09-02' ],
],
[ '2021-04-30', '2021-06-02', [ '2021-04-30', '2021-05-28', '2021-06-02' ] ],
[ '2021-04-25', '2021-05-05', [ '2021-04-30', '2021-05-05' ] ],
[ '2021-04-05', '2021-05-02', [ '2021-04-30' ] ],
[ '2021-04-01', '2021-08-01', [ '2021-04-30', '2021-05-28', '2021-06-30', '2021-07-30' ] ],
[ '2021-07-31', '2021-08-01', [] ],
[ '2021-05-31', '2021-06-10', [ '2021-06-10' ] ],
]);
// Start | End | Expected list of end dates
['2021-04-01', '2021-04-03', ['2021-04-01']],
['2021-04-01', '2021-04-30', ['2021-04-30']],
['2021-04-01', '2021-05-10', ['2021-04-30', '2021-05-10']],
[
'2021-04-01',
'2021-09-02',
['2021-04-30', '2021-05-28', '2021-06-30', '2021-07-30', '2021-08-31', '2021-09-02'],
],
['2021-04-30', '2021-06-02', ['2021-04-30', '2021-05-28', '2021-06-02']],
['2021-04-25', '2021-05-05', ['2021-04-30', '2021-05-05']],
['2021-04-05', '2021-05-02', ['2021-04-30']],
['2021-04-01', '2021-08-01', ['2021-04-30', '2021-05-28', '2021-06-30', '2021-07-30']],
['2021-07-31', '2021-08-01', []],
['2021-05-31', '2021-06-10', ['2021-06-10']],
]);

it('returns valid monthly allowance intervals', function ($start, $end, $allowance) {
$start = Carbon::createFromFormat('Y-m-d', $start)
->startOfDay();
->startOfDay();
$end = Carbon::createFromFormat('Y-m-d', $end)
->startOfDay();
->startOfDay();

expect($this->taxAllowanceCalculator->monthly($start, $end))->toEqual($allowance);
})->with([
// Start date | End date | Expected allowance count
[ '2021-04-01', '2021-04-03', 1 ],
// less than a month
[ '2021-04-01', '2021-04-30', 1 ],
// one perfect month
[ '2021-04-01', '2021-05-10', 2 ],
// over two month, start on first and ending fine
[ '2021-04-01', '2021-09-02', 6 ],
// over 6 months
[ '2021-04-30', '2021-06-02', 3 ],
// over 6 months
[ '2021-04-25', '2021-05-05', 2 ],
// less than a month length over two months
[ '2021-04-05', '2021-05-02', 1 ],
// over two months, starting fine but ending on the first days of next month which are weekends
[ '2021-04-01', '2021-08-01', 4 ],
// over 5 month but ending on first day being a non-working day, so 4 allowance
[ '2021-07-31', '2021-08-01', 0 ],
// over 2 month but starting and ending on the same weekend..., so 0 allowance
[ '2021-05-31', '2021-06-10', 1 ],
// over 2 month but starting on last day being a non-working day, so 1 allowance
]);
// Start date | End date | Expected allowance count
['2021-04-01', '2021-04-03', 1],
// less than a month
['2021-04-01', '2021-04-30', 1],
// one perfect month
['2021-04-01', '2021-05-10', 2],
// over two month, start on first and ending fine
['2021-04-01', '2021-09-02', 6],
// over 6 months
['2021-04-30', '2021-06-02', 3],
// over 6 months
['2021-04-25', '2021-05-05', 2],
// less than a month length over two months
['2021-04-05', '2021-05-02', 1],
// over two months, starting fine but ending on the first days of next month which are weekends
['2021-04-01', '2021-08-01', 4],
// over 5 month but ending on first day being a non-working day, so 4 allowance
['2021-07-31', '2021-08-01', 0],
// over 2 month but starting and ending on the same weekend..., so 0 allowance
['2021-05-31', '2021-06-10', 1],
// over 2 month but starting on last day being a non-working day, so 1 allowance
]);

0 comments on commit 61bae63

Please sign in to comment.