createdAt = new DateTimeImmutable(); $this->fromData($entity); } public static function isValid(InputEntity $entity): bool { return preg_match('/przeglÄ…d/mi', $entity->description); } public function __toArray(): array { return [ 'description' => $this->description, 'type' => $this->type->value, 'inspectionDate' => $this->serviceDate?->format('Y-m-d') ?? '', 'weekOfInspection' => $this->serviceWeek ?? '', 'status' => $this->status->value, 'recommendations' => $this->serviceNotes ?? '', 'contactPhone' => $this->contactPhone ?? '', 'createdAt' => $this->createdAt->format('Y-m-d') ]; } private function fromData(InputEntity $entity): void { $this->description = $entity->description; $this->contactPhone = $entity->phone; $this->serviceDate = $entity->date; $this->checkWeek(); $this->status = $this->serviceDate ? Status::PLANED : Status::NEW; } private function checkWeek(): void { if($this->serviceDate) { $this->serviceWeek = $this->serviceDate->isoWeek(); } } }