refactor(exercise) : extract ExerciseYearResolver to dedup year formula
Pull the "date -> leave/RTT exercise year" formula out of EmployeeRttPaymentProcessor, EmployeeRttSummaryProvider and EmployeeLeaveSummaryProvider into a single App\Service\Exercise\ExerciseYearResolver. Forfait flag is parameterised so the leave (calendar year) and RTT (Juin N-1 -> Mai N) variants share the same implementation. Pure refactor, no behavioural change.
This commit is contained in:
27
src/Service/Exercise/ExerciseYearResolver.php
Normal file
27
src/Service/Exercise/ExerciseYearResolver.php
Normal file
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Service\Exercise;
|
||||
|
||||
use DateTimeImmutable;
|
||||
|
||||
final readonly class ExerciseYearResolver
|
||||
{
|
||||
/**
|
||||
* Convert a date to its leave/RTT exercise year.
|
||||
*
|
||||
* - Forfait: calendar year (Jan→Dec) — returns $date.Y.
|
||||
* - Non-forfait: leave year (Juin N-1 → Mai N) — returns $date.Y+1 if month >= 6, else $date.Y.
|
||||
*/
|
||||
public function forDate(DateTimeImmutable $date, bool $isForfait = false): int
|
||||
{
|
||||
if ($isForfait) {
|
||||
return (int) $date->format('Y');
|
||||
}
|
||||
|
||||
return (int) $date->format('n') >= 6
|
||||
? (int) $date->format('Y') + 1
|
||||
: (int) $date->format('Y');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user