tenantId); $classId = ClassId::fromString($command->classId); $subjectId = SubjectId::fromString($command->subjectId); $teacherId = UserId::fromString($command->teacherId); $now = $this->clock->now(); if (!$this->affectationChecker->estAffecte($teacherId, $classId, $subjectId, $tenantId)) { throw EnseignantNonAffecteException::pourClasseEtMatiere($teacherId, $classId, $subjectId); } $calendar = $this->calendarProvider->forCurrentYear($tenantId); $dueDate = new DateTimeImmutable($command->dueDate); $this->dueDateValidator->valider($dueDate, $now, $calendar); $rulesResult = $this->rulesChecker->verifier($tenantId, $dueDate, $now); if ($rulesResult->estBloquant()) { throw new ReglesDevoirsNonRespecteesException( $rulesResult->toArray(), bloquant: true, suggestedDates: $rulesResult->suggestedDates, ); } if ($rulesResult->estAvertissement() && !$command->acknowledgeWarning) { throw new ReglesDevoirsNonRespecteesException($rulesResult->toArray()); } $description = $command->description !== null ? $this->htmlSanitizer->sanitize($command->description) : null; $homework = Homework::creer( tenantId: $tenantId, classId: $classId, subjectId: $subjectId, teacherId: $teacherId, title: $command->title, description: $description, dueDate: $dueDate, now: $now, ); if ($command->acknowledgeWarning && $rulesResult->estAvertissement()) { $homework->acknowledgeRuleWarning($rulesResult->ruleTypes(), $now); } $this->homeworkRepository->save($homework); return $homework; } }