*/ private array $calculators = []; public function __construct(private readonly WorkingTimeService $workingTimeService) { } public function getTests(): array { return [ /* @var array{user: User, date: \DateTimeInterface} $values */ new TwigTest('work_day', function (array $values): bool { // TODO remove me in 3.0, deprecate with 2.55 if (!\array_key_exists('user', $values) || !\array_key_exists('date', $values)) { throw new \Exception('Missing variable "user" or "date" to check for "is work_day'); } return $this->isWorkingDay($values['date'], $values['user']); }), new TwigTest('working_day', function (\DateTimeInterface $date, User $user): bool { return $this->isWorkingDay($date, $user); }), ]; } private function isWorkingDay(\DateTimeInterface $date, User $user): bool { if ($user->getId() === null) { return false; } $id = 'user_' . $user->getId(); if (!\array_key_exists($id, $this->calculators)) { $this->calculators[$id] = $this->workingTimeService->getContractMode($user)->getCalculator($user); } return $this->calculators[$id]->isWorkDay($date); } }