{
"tool_response": {
"filePath": "\/var\/www\/dev.campus.systemische-tools.de\/src\/Domain\/Entity\/Task.php",
"oldString": " \/\/ Setters\n public function setId(int $id): self\n {\n $this->id = $id;\n\n return $this;\n }\n\n public function setUuid(string $uuid): self\n {\n $this->uuid = $uuid;\n\n return $this;\n }\n\n public function setTitle(string $title): self\n {\n $this->title = $title;\n $this->updatedAt = new \\DateTimeImmutable();\n\n return $this;\n }\n\n public function setDescription(?string $description): self\n {\n $this->description = $description;\n $this->updatedAt = new \\DateTimeImmutable();\n\n return $this;\n }\n\n public function setType(string $type): self\n {\n $this->type = $type;\n $this->updatedAt = new \\DateTimeImmutable();\n\n return $this;\n }\n\n public function setStatus(TaskStatus $status): self\n {\n if ($this->status->canTransitionTo($status) || $this->id === null) {\n $this->status = $status;\n $this->updatedAt = new \\DateTimeImmutable();\n\n if ($status->isTerminal()) {\n $this->completedAt = new \\DateTimeImmutable();\n }\n }\n\n return $this;\n }\n\n public function setCreatedBy(string $createdBy): self\n {\n $this->createdBy = $createdBy;\n\n return $this;\n }\n\n public function setCreatedByType(string $createdByType): self\n {\n $this->createdByType = $createdByType;\n\n return $this;\n }\n\n public function setParentTaskId(?int $parentTaskId): self\n {\n $this->parentTaskId = $parentTaskId;\n $this->updatedAt = new \\DateTimeImmutable();\n\n return $this;\n }\n\n public function setDueDate(?\\DateTimeImmutable $dueDate): self\n {\n $this->dueDate = $dueDate;\n $this->updatedAt = new \\DateTimeImmutable();\n\n return $this;\n }\n\n public function setCreatedAt(\\DateTimeImmutable $createdAt): self\n {\n $this->createdAt = $createdAt;\n\n return $this;\n }\n\n public function setUpdatedAt(\\DateTimeImmutable $updatedAt): self\n {\n $this->updatedAt = $updatedAt;\n\n return $this;\n }\n\n public function setCompletedAt(?\\DateTimeImmutable $completedAt): self\n {\n $this->completedAt = $completedAt;\n\n return $this;\n }\n\n public function setMetadata(array $metadata): self\n {\n $this->metadata = $metadata;\n $this->updatedAt = new \\DateTimeImmutable();\n\n return $this;\n }",
"newString": " \/\/ Business Methods\n public function updateDetails(string $title, ?string $description = null): self\n {\n $this->title = $title;\n $this->description = $description;\n $this->touch();\n\n return $this;\n }\n\n public function changeType(TaskType $type): self\n {\n $this->type = $type;\n $this->touch();\n\n return $this;\n }\n\n public function assignParent(int $parentTaskId): self\n {\n $this->parentTaskId = $parentTaskId;\n $this->touch();\n\n return $this;\n }\n\n public function setDueDateTo(\\DateTimeImmutable $dueDate): self\n {\n $this->dueDate = $dueDate;\n $this->touch();\n\n return $this;\n }\n\n public function clearDueDate(): self\n {\n $this->dueDate = null;\n $this->touch();\n\n return $this;\n }\n\n public function updateMetadata(array $metadata): self\n {\n $this->metadata = $metadata;\n $this->touch();\n\n return $this;\n }\n\n public function isOverdue(): bool\n {\n if ($this->dueDate === null || $this->status->isTerminal()) {\n return false;\n }\n\n return $this->dueDate < new \\DateTimeImmutable();\n }\n\n public function isSubtask(): bool\n {\n return $this->parentTaskId !== null;\n }\n\n \/\/ Status Transitions\n public function start(): self\n {\n $this->transitionTo(TaskStatus::IN_PROGRESS);\n\n return $this;\n }\n\n public function complete(): self\n {\n $this->transitionTo(TaskStatus::COMPLETED);\n\n return $this;\n }\n\n public function fail(): self\n {\n $this->transitionTo(TaskStatus::FAILED);\n\n return $this;\n }\n\n public function cancel(): self\n {\n $this->transitionTo(TaskStatus::CANCELLED);\n\n return $this;\n }\n\n public function retry(): self\n {\n if ($this->status !== TaskStatus::FAILED) {\n throw new \\DomainException('Can only retry failed tasks');\n }\n\n $this->transitionTo(TaskStatus::PENDING);\n $this->completedAt = null;\n\n return $this;\n }\n\n private function transitionTo(TaskStatus $newStatus): void\n {\n if (!$this->status->canTransitionTo($newStatus)) {\n throw new \\DomainException(\n sprintf('Cannot transition from %s to %s', $this->status->value, $newStatus->value)\n );\n }\n\n $this->status = $newStatus;\n $this->touch();\n\n if ($newStatus->isTerminal()) {\n $this->completedAt = new \\DateTimeImmutable();\n }\n }\n\n private function touch(): void\n {\n $this->updatedAt = new \\DateTimeImmutable();\n }\n\n \/\/ Internal Setters for Hydration\n public function setId(int $id): self\n {\n $this->id = $id;\n\n return $this;\n }\n\n public function hydrate(array $data): self\n {\n if (isset($data['uuid'])) {\n $this->uuid = $data['uuid'];\n }\n if (isset($data['title'])) {\n $this->title = $data['title'];\n }\n if (isset($data['description'])) {\n $this->description = $data['description'];\n }\n if (isset($data['type'])) {\n $this->type = is_string($data['type']) ? TaskType::from($data['type']) : $data['type'];\n }\n if (isset($data['status'])) {\n $this->status = is_string($data['status']) ? TaskStatus::from($data['status']) : $data['status'];\n }\n if (isset($data['created_by'])) {\n $this->createdBy = $data['created_by'];\n }\n if (isset($data['created_by_type'])) {\n $this->createdByType = $data['created_by_type'];\n }\n if (isset($data['parent_task_id'])) {\n $this->parentTaskId = (int) $data['parent_task_id'];\n }\n if (isset($data['due_date'])) {\n $this->dueDate = $data['due_date'] instanceof \\DateTimeImmutable\n ? $data['due_date']\n : new \\DateTimeImmutable($data['due_date']);\n }\n if (isset($data['created_at'])) {\n $this->createdAt = $data['created_at'] instanceof \\DateTimeImmutable\n ? $data['created_at']\n : new \\DateTimeImmutable($data['created_at']);\n }\n if (isset($data['updated_at'])) {\n $this->updatedAt = $data['updated_at'] instanceof \\DateTimeImmutable\n ? $data['updated_at']\n : new \\DateTimeImmutable($data['updated_at']);\n }\n if (isset($data['completed_at'])) {\n $this->completedAt = $data['completed_at'] instanceof \\DateTimeImmutable\n ? $data['completed_at']\n : new \\DateTimeImmutable($data['completed_at']);\n }\n if (isset($data['metadata'])) {\n $this->metadata = is_string($data['metadata']) ? json_decode($data['metadata'], true) : $data['metadata'];\n }\n\n return $this;\n }",
"originalFile": "<?php\n\ndeclare(strict_types=1);\n\nnamespace Domain\\Entity;\n\n\/\/ @responsibility: Task-Entität - Rich Domain Model mit Business-Logik\n\nuse Domain\\ValueObject\\TaskStatus;\nuse Domain\\ValueObject\\TaskType;\n\nclass Task\n{\n private ?int $id = null;\n private string $uuid;\n private string $title;\n private ?string $description = null;\n private TaskType $type;\n private TaskStatus $status;\n private string $createdBy;\n private string $createdByType = 'human';\n private ?int $parentTaskId = null;\n private ?\\DateTimeImmutable $dueDate = null;\n private \\DateTimeImmutable $createdAt;\n private \\DateTimeImmutable $updatedAt;\n private ?\\DateTimeImmutable $completedAt = null;\n private array $metadata = [];\n\n private function __construct()\n {\n $this->uuid = $this->generateUuid();\n $this->status = TaskStatus::PENDING;\n $this->type = TaskType::HUMAN_TASK;\n $this->createdAt = new \\DateTimeImmutable();\n $this->updatedAt = new \\DateTimeImmutable();\n }\n\n public static function create(\n string $title,\n string $createdBy,\n ?string $description = null,\n ?TaskType $type = null,\n ?int $parentTaskId = null,\n ?\\DateTimeImmutable $dueDate = null\n ): self {\n $task = new self();\n $task->title = $title;\n $task->createdBy = $createdBy;\n $task->description = $description;\n\n if ($type !== null) {\n $task->type = $type;\n }\n\n if ($parentTaskId !== null) {\n $task->parentTaskId = $parentTaskId;\n }\n\n if ($dueDate !== null) {\n $task->dueDate = $dueDate;\n }\n\n return $task;\n }\n\n private function generateUuid(): string\n {\n return sprintf(\n '%04x%04x-%04x-%04x-%04x-%04x%04x%04x',\n mt_rand(0, 0xffff),\n mt_rand(0, 0xffff),\n mt_rand(0, 0xffff),\n mt_rand(0, 0x0fff) | 0x4000,\n mt_rand(0, 0x3fff) | 0x8000,\n mt_rand(0, 0xffff),\n mt_rand(0, 0xffff),\n mt_rand(0, 0xffff)\n );\n }\n\n \/\/ Getters\n public function getId(): ?int\n {\n return $this->id;\n }\n\n public function getUuid(): string\n {\n return $this->uuid;\n }\n\n public function getTitle(): string\n {\n return $this->title;\n }\n\n public function getDescription(): ?string\n {\n return $this->description;\n }\n\n public function getType(): TaskType\n {\n return $this->type;\n }\n\n public function getStatus(): TaskStatus\n {\n return $this->status;\n }\n\n public function getCreatedBy(): string\n {\n return $this->createdBy;\n }\n\n public function getCreatedByType(): string\n {\n return $this->createdByType;\n }\n\n public function getParentTaskId(): ?int\n {\n return $this->parentTaskId;\n }\n\n public function getDueDate(): ?\\DateTimeImmutable\n {\n return $this->dueDate;\n }\n\n public function getCreatedAt(): \\DateTimeImmutable\n {\n return $this->createdAt;\n }\n\n public function getUpdatedAt(): \\DateTimeImmutable\n {\n return $this->updatedAt;\n }\n\n public function getCompletedAt(): ?\\DateTimeImmutable\n {\n return $this->completedAt;\n }\n\n public function getMetadata(): array\n {\n return $this->metadata;\n }\n\n \/\/ Setters\n public function setId(int $id): self\n {\n $this->id = $id;\n\n return $this;\n }\n\n public function setUuid(string $uuid): self\n {\n $this->uuid = $uuid;\n\n return $this;\n }\n\n public function setTitle(string $title): self\n {\n $this->title = $title;\n $this->updatedAt = new \\DateTimeImmutable();\n\n return $this;\n }\n\n public function setDescription(?string $description): self\n {\n $this->description = $description;\n $this->updatedAt = new \\DateTimeImmutable();\n\n return $this;\n }\n\n public function setType(string $type): self\n {\n $this->type = $type;\n $this->updatedAt = new \\DateTimeImmutable();\n\n return $this;\n }\n\n public function setStatus(TaskStatus $status): self\n {\n if ($this->status->canTransitionTo($status) || $this->id === null) {\n $this->status = $status;\n $this->updatedAt = new \\DateTimeImmutable();\n\n if ($status->isTerminal()) {\n $this->completedAt = new \\DateTimeImmutable();\n }\n }\n\n return $this;\n }\n\n public function setCreatedBy(string $createdBy): self\n {\n $this->createdBy = $createdBy;\n\n return $this;\n }\n\n public function setCreatedByType(string $createdByType): self\n {\n $this->createdByType = $createdByType;\n\n return $this;\n }\n\n public function setParentTaskId(?int $parentTaskId): self\n {\n $this->parentTaskId = $parentTaskId;\n $this->updatedAt = new \\DateTimeImmutable();\n\n return $this;\n }\n\n public function setDueDate(?\\DateTimeImmutable $dueDate): self\n {\n $this->dueDate = $dueDate;\n $this->updatedAt = new \\DateTimeImmutable();\n\n return $this;\n }\n\n public function setCreatedAt(\\DateTimeImmutable $createdAt): self\n {\n $this->createdAt = $createdAt;\n\n return $this;\n }\n\n public function setUpdatedAt(\\DateTimeImmutable $updatedAt): self\n {\n $this->updatedAt = $updatedAt;\n\n return $this;\n }\n\n public function setCompletedAt(?\\DateTimeImmutable $completedAt): self\n {\n $this->completedAt = $completedAt;\n\n return $this;\n }\n\n public function setMetadata(array $metadata): self\n {\n $this->metadata = $metadata;\n $this->updatedAt = new \\DateTimeImmutable();\n\n return $this;\n }\n\n public function toArray(): array\n {\n return [\n 'id' => $this->id,\n 'uuid' => $this->uuid,\n 'title' => $this->title,\n 'description' => $this->description,\n 'type' => $this->type,\n 'status' => $this->status->value,\n 'created_by' => $this->createdBy,\n 'created_by_type' => $this->createdByType,\n 'parent_task_id' => $this->parentTaskId,\n 'due_date' => $this->dueDate?->format('Y-m-d H:i:s'),\n 'created_at' => $this->createdAt->format('Y-m-d H:i:s.u'),\n 'updated_at' => $this->updatedAt->format('Y-m-d H:i:s.u'),\n 'completed_at' => $this->completedAt?->format('Y-m-d H:i:s.u'),\n 'metadata' => $this->metadata,\n ];\n }\n\n public static function fromArray(array $data): self\n {\n $task = new self();\n\n if (isset($data['id'])) {\n $task->setId((int) $data['id']);\n }\n if (isset($data['uuid'])) {\n $task->setUuid($data['uuid']);\n }\n if (isset($data['title'])) {\n $task->setTitle($data['title']);\n }\n if (isset($data['description'])) {\n $task->setDescription($data['description']);\n }\n if (isset($data['type'])) {\n $task->setType($data['type']);\n }\n if (isset($data['status'])) {\n $task->status = TaskStatus::from($data['status']);\n }\n if (isset($data['created_by'])) {\n $task->setCreatedBy($data['created_by']);\n }\n if (isset($data['created_by_type'])) {\n $task->setCreatedByType($data['created_by_type']);\n }\n if (isset($data['parent_task_id'])) {\n $task->setParentTaskId((int) $data['parent_task_id']);\n }\n if (isset($data['due_date'])) {\n $task->setDueDate(new \\DateTimeImmutable($data['due_date']));\n }\n if (isset($data['created_at'])) {\n $task->setCreatedAt(new \\DateTimeImmutable($data['created_at']));\n }\n if (isset($data['updated_at'])) {\n $task->setUpdatedAt(new \\DateTimeImmutable($data['updated_at']));\n }\n if (isset($data['completed_at'])) {\n $task->setCompletedAt(new \\DateTimeImmutable($data['completed_at']));\n }\n if (isset($data['metadata'])) {\n $metadata = is_string($data['metadata']) ? json_decode($data['metadata'], true) : $data['metadata'];\n $task->setMetadata($metadata ?? []);\n }\n\n return $task;\n }\n}\n",
"structuredPatch": [
{
"oldStart": 149,
"oldLines": 114,
"newStart": 149,
"newLines": 189,
"lines": [
" return $this->metadata;",
" }",
" ",
"- \/\/ Setters",
"- public function setId(int $id): self",
"+ \/\/ Business Methods",
"+ public function updateDetails(string $title, ?string $description = null): self",
" {",
"- $this->id = $id;",
"+ $this->title = $title;",
"+ $this->description = $description;",
"+ $this->touch();",
" ",
" return $this;",
" }",
" ",
"- public function setUuid(string $uuid): self",
"+ public function changeType(TaskType $type): self",
" {",
"- $this->uuid = $uuid;",
"+ $this->type = $type;",
"+ $this->touch();",
" ",
" return $this;",
" }",
" ",
"- public function setTitle(string $title): self",
"+ public function assignParent(int $parentTaskId): self",
" {",
"- $this->title = $title;",
"- $this->updatedAt = new \\DateTimeImmutable();",
"+ $this->parentTaskId = $parentTaskId;",
"+ $this->touch();",
" ",
" return $this;",
" }",
" ",
"- public function setDescription(?string $description): self",
"+ public function setDueDateTo(\\DateTimeImmutable $dueDate): self",
" {",
"- $this->description = $description;",
"- $this->updatedAt = new \\DateTimeImmutable();",
"+ $this->dueDate = $dueDate;",
"+ $this->touch();",
" ",
" return $this;",
" }",
" ",
"- public function setType(string $type): self",
"+ public function clearDueDate(): self",
" {",
"- $this->type = $type;",
"- $this->updatedAt = new \\DateTimeImmutable();",
"+ $this->dueDate = null;",
"+ $this->touch();",
" ",
" return $this;",
" }",
" ",
"- public function setStatus(TaskStatus $status): self",
"+ public function updateMetadata(array $metadata): self",
" {",
"- if ($this->status->canTransitionTo($status) || $this->id === null) {",
"- $this->status = $status;",
"- $this->updatedAt = new \\DateTimeImmutable();",
"+ $this->metadata = $metadata;",
"+ $this->touch();",
" ",
"- if ($status->isTerminal()) {",
"- $this->completedAt = new \\DateTimeImmutable();",
"- }",
"+ return $this;",
"+ }",
"+",
"+ public function isOverdue(): bool",
"+ {",
"+ if ($this->dueDate === null || $this->status->isTerminal()) {",
"+ return false;",
" }",
" ",
"- return $this;",
"+ return $this->dueDate < new \\DateTimeImmutable();",
" }",
" ",
"- public function setCreatedBy(string $createdBy): self",
"+ public function isSubtask(): bool",
" {",
"- $this->createdBy = $createdBy;",
"+ return $this->parentTaskId !== null;",
"+ }",
" ",
"+ \/\/ Status Transitions",
"+ public function start(): self",
"+ {",
"+ $this->transitionTo(TaskStatus::IN_PROGRESS);",
"+",
" return $this;",
" }",
" ",
"- public function setCreatedByType(string $createdByType): self",
"+ public function complete(): self",
" {",
"- $this->createdByType = $createdByType;",
"+ $this->transitionTo(TaskStatus::COMPLETED);",
" ",
" return $this;",
" }",
" ",
"- public function setParentTaskId(?int $parentTaskId): self",
"+ public function fail(): self",
" {",
"- $this->parentTaskId = $parentTaskId;",
"- $this->updatedAt = new \\DateTimeImmutable();",
"+ $this->transitionTo(TaskStatus::FAILED);",
" ",
" return $this;",
" }",
" ",
"- public function setDueDate(?\\DateTimeImmutable $dueDate): self",
"+ public function cancel(): self",
" {",
"- $this->dueDate = $dueDate;",
"- $this->updatedAt = new \\DateTimeImmutable();",
"+ $this->transitionTo(TaskStatus::CANCELLED);",
" ",
" return $this;",
" }",
" ",
"- public function setCreatedAt(\\DateTimeImmutable $createdAt): self",
"+ public function retry(): self",
" {",
"- $this->createdAt = $createdAt;",
"+ if ($this->status !== TaskStatus::FAILED) {",
"+ throw new \\DomainException('Can only retry failed tasks');",
"+ }",
" ",
"+ $this->transitionTo(TaskStatus::PENDING);",
"+ $this->completedAt = null;",
"+",
" return $this;",
" }",
" ",
"- public function setUpdatedAt(\\DateTimeImmutable $updatedAt): self",
"+ private function transitionTo(TaskStatus $newStatus): void",
" {",
"- $this->updatedAt = $updatedAt;",
"+ if (!$this->status->canTransitionTo($newStatus)) {",
"+ throw new \\DomainException(",
"+ sprintf('Cannot transition from %s to %s', $this->status->value, $newStatus->value)",
"+ );",
"+ }",
" ",
"- return $this;",
"+ $this->status = $newStatus;",
"+ $this->touch();",
"+",
"+ if ($newStatus->isTerminal()) {",
"+ $this->completedAt = new \\DateTimeImmutable();",
"+ }",
" }",
" ",
"- public function setCompletedAt(?\\DateTimeImmutable $completedAt): self",
"+ private function touch(): void",
" {",
"- $this->completedAt = $completedAt;",
"+ $this->updatedAt = new \\DateTimeImmutable();",
"+ }",
" ",
"+ \/\/ Internal Setters for Hydration",
"+ public function setId(int $id): self",
"+ {",
"+ $this->id = $id;",
"+",
" return $this;",
" }",
" ",
"- public function setMetadata(array $metadata): self",
"+ public function hydrate(array $data): self",
" {",
"- $this->metadata = $metadata;",
"- $this->updatedAt = new \\DateTimeImmutable();",
"+ if (isset($data['uuid'])) {",
"+ $this->uuid = $data['uuid'];",
"+ }",
"+ if (isset($data['title'])) {",
"+ $this->title = $data['title'];",
"+ }",
"+ if (isset($data['description'])) {",
"+ $this->description = $data['description'];",
"+ }",
"+ if (isset($data['type'])) {",
"+ $this->type = is_string($data['type']) ? TaskType::from($data['type']) : $data['type'];",
"+ }",
"+ if (isset($data['status'])) {",
"+ $this->status = is_string($data['status']) ? TaskStatus::from($data['status']) : $data['status'];",
"+ }",
"+ if (isset($data['created_by'])) {",
"+ $this->createdBy = $data['created_by'];",
"+ }",
"+ if (isset($data['created_by_type'])) {",
"+ $this->createdByType = $data['created_by_type'];",
"+ }",
"+ if (isset($data['parent_task_id'])) {",
"+ $this->parentTaskId = (int) $data['parent_task_id'];",
"+ }",
"+ if (isset($data['due_date'])) {",
"+ $this->dueDate = $data['due_date'] instanceof \\DateTimeImmutable",
"+ ? $data['due_date']",
"+ : new \\DateTimeImmutable($data['due_date']);",
"+ }",
"+ if (isset($data['created_at'])) {",
"+ $this->createdAt = $data['created_at'] instanceof \\DateTimeImmutable",
"+ ? $data['created_at']",
"+ : new \\DateTimeImmutable($data['created_at']);",
"+ }",
"+ if (isset($data['updated_at'])) {",
"+ $this->updatedAt = $data['updated_at'] instanceof \\DateTimeImmutable",
"+ ? $data['updated_at']",
"+ : new \\DateTimeImmutable($data['updated_at']);",
"+ }",
"+ if (isset($data['completed_at'])) {",
"+ $this->completedAt = $data['completed_at'] instanceof \\DateTimeImmutable",
"+ ? $data['completed_at']",
"+ : new \\DateTimeImmutable($data['completed_at']);",
"+ }",
"+ if (isset($data['metadata'])) {",
"+ $this->metadata = is_string($data['metadata']) ? json_decode($data['metadata'], true) : $data['metadata'];",
"+ }",
" ",
" return $this;",
" }"
]
}
],
"userModified": false,
"replaceAll": false
}
}