{
"event": "PreToolUse",
"tool_name": "Edit",
"tool_input": {
"file_path": "\/var\/www\/dev.campus.systemische-tools.de\/src\/UseCases\/Task\/CreateTaskUseCase.php",
"old_string": "use Domain\\Entity\\Task;\nuse Domain\\Entity\\TaskComment;\nuse Infrastructure\\Persistence\\TaskCommentRepository;\nuse Infrastructure\\Persistence\\TaskRepository;\n\nclass CreateTaskUseCase\n{\n private TaskRepository $taskRepository;\n private TaskCommentRepository $commentRepository;\n\n public function __construct(\n ?TaskRepository $taskRepository = null,\n ?TaskCommentRepository $commentRepository = null\n ) {\n $this->taskRepository = $taskRepository ?? new TaskRepository();\n $this->commentRepository = $commentRepository ?? new TaskCommentRepository();\n }",
"new_string": "use Domain\\Entity\\Task;\nuse Domain\\Entity\\TaskComment;\nuse Domain\\Repository\\TaskRepositoryInterface;\nuse Infrastructure\\Persistence\\TaskCommentRepository;\n\nclass CreateTaskUseCase\n{\n public function __construct(\n private TaskRepositoryInterface $taskRepository,\n private TaskCommentRepository $commentRepository\n ) {}"
}
}
{
"tool_response": {
"filePath": "\/var\/www\/dev.campus.systemische-tools.de\/src\/UseCases\/Task\/CreateTaskUseCase.php",
"oldString": "use Domain\\Entity\\Task;\nuse Domain\\Entity\\TaskComment;\nuse Infrastructure\\Persistence\\TaskCommentRepository;\nuse Infrastructure\\Persistence\\TaskRepository;\n\nclass CreateTaskUseCase\n{\n private TaskRepository $taskRepository;\n private TaskCommentRepository $commentRepository;\n\n public function __construct(\n ?TaskRepository $taskRepository = null,\n ?TaskCommentRepository $commentRepository = null\n ) {\n $this->taskRepository = $taskRepository ?? new TaskRepository();\n $this->commentRepository = $commentRepository ?? new TaskCommentRepository();\n }",
"newString": "use Domain\\Entity\\Task;\nuse Domain\\Entity\\TaskComment;\nuse Domain\\Repository\\TaskRepositoryInterface;\nuse Infrastructure\\Persistence\\TaskCommentRepository;\n\nclass CreateTaskUseCase\n{\n public function __construct(\n private TaskRepositoryInterface $taskRepository,\n private TaskCommentRepository $commentRepository\n ) {}",
"originalFile": "<?php\n\ndeclare(strict_types=1);\n\nnamespace UseCases\\Task;\n\n\/\/ @responsibility: Erstellt neue Tasks mit optionalen Kommentaren und Parent-Verknüpfung\n\nuse Domain\\Entity\\Task;\nuse Domain\\Entity\\TaskComment;\nuse Infrastructure\\Persistence\\TaskCommentRepository;\nuse Infrastructure\\Persistence\\TaskRepository;\n\nclass CreateTaskUseCase\n{\n private TaskRepository $taskRepository;\n private TaskCommentRepository $commentRepository;\n\n public function __construct(\n ?TaskRepository $taskRepository = null,\n ?TaskCommentRepository $commentRepository = null\n ) {\n $this->taskRepository = $taskRepository ?? new TaskRepository();\n $this->commentRepository = $commentRepository ?? new TaskCommentRepository();\n }\n\n public function execute(array $data): Task\n {\n $this->validate($data);\n\n $task = new Task();\n $task->setTitle($data['title']);\n $task->setCreatedBy($data['created_by'] ?? 'system');\n $task->setCreatedByType($data['created_by_type'] ?? 'human');\n\n if (isset($data['description'])) {\n $task->setDescription($data['description']);\n }\n\n if (isset($data['type'])) {\n $task->setType($data['type']);\n }\n\n if (isset($data['parent_task_id'])) {\n $task->setParentTaskId((int) $data['parent_task_id']);\n }\n\n if (isset($data['due_date'])) {\n $task->setDueDate(new \\DateTimeImmutable($data['due_date']));\n }\n\n if (isset($data['metadata'])) {\n $task->setMetadata($data['metadata']);\n }\n\n $id = $this->taskRepository->save($task);\n $task->setId($id);\n\n $comment = new TaskComment();\n $comment->setTaskId($id);\n $comment->setAuthor($task->getCreatedBy());\n $comment->setAuthorType($task->getCreatedByType());\n $comment->setCommentType('note');\n $comment->setContent('Task erstellt');\n $this->commentRepository->save($comment);\n\n return $task;\n }\n\n private function validate(array $data): void\n {\n if (!isset($data['title']) || $data['title'] === '') {\n throw new \\InvalidArgumentException('Title is required');\n }\n\n if (strlen($data['title']) > 255) {\n throw new \\InvalidArgumentException('Title must be 255 characters or less');\n }\n\n if (isset($data['type']) && !in_array($data['type'], ['human_task', 'ai_task', 'mixed'])) {\n throw new \\InvalidArgumentException('Invalid task type');\n }\n }\n}\n",
"structuredPatch": [
{
"oldStart": 8,
"oldLines": 21,
"newStart": 8,
"newLines": 15,
"lines": [
" ",
" use Domain\\Entity\\Task;",
" use Domain\\Entity\\TaskComment;",
"+use Domain\\Repository\\TaskRepositoryInterface;",
" use Infrastructure\\Persistence\\TaskCommentRepository;",
"-use Infrastructure\\Persistence\\TaskRepository;",
" ",
" class CreateTaskUseCase",
" {",
"- private TaskRepository $taskRepository;",
"- private TaskCommentRepository $commentRepository;",
"-",
" public function __construct(",
"- ?TaskRepository $taskRepository = null,",
"- ?TaskCommentRepository $commentRepository = null",
"- ) {",
"- $this->taskRepository = $taskRepository ?? new TaskRepository();",
"- $this->commentRepository = $commentRepository ?? new TaskCommentRepository();",
"- }",
"+ private TaskRepositoryInterface $taskRepository,",
"+ private TaskCommentRepository $commentRepository",
"+ ) {}",
" ",
" public function execute(array $data): Task",
" {"
]
}
],
"userModified": false,
"replaceAll": false
}
}