createdAt = new DateTimeImmutable(); $this->fromData($entity); } public static function isValid(InputEntity $entity): bool { return true; } public function __toArray(): array { return [ 'description' => $this->description, 'type' => $this->type->value, 'priority' => $this->priority->value, 'serviceDate' => $this->serviceDate?->format('Y-m-d') ?? '', 'status' => $this->status->value, 'serviceNotes' => $this->serviceNotes, 'contactPhone' => $this->contactPhone ?? '', 'createdAt' => $this->createdAt->format('Y-m-d') ]; } private function fromData(InputEntity $entity): void { $this->description = $entity->description; $this->serviceDate = $entity->date; $this->contactPhone = $entity->phone; $this->checkPriority($entity->description); $this->status = $this->serviceDate ? Status::DEADLINE : Status::NEW; } private function checkPriority(string $description): void { $map = [ '/bardzo pilne/im' => Priority::CRITICAL, '/pilne/im' => Priority::HIGH, ]; foreach ($map as $pattern => $priority) { if (preg_match($pattern, $description)) { $this->priority = $priority; break; } } } }