CreateTaskUseCase.php
- Pfad:
src/UseCases/Task/CreateTaskUseCase.php - Namespace: UseCases\Task
- Zeilen: 71 | Größe: 2,173 Bytes
- Geändert: 2025-12-25 17:02:47 | Gescannt: 2025-12-31 10:22:15
Code Hygiene Score: 100
- Dependencies: 100 (25%)
- LOC: 100 (20%)
- Methods: 100 (20%)
- Secrets: 100 (15%)
- Classes: 100 (10%)
- Magic Numbers: 100 (10%)
Keine Issues gefunden.
Dependencies 7
- constructor Domain\Repository\TaskRepositoryInterface
- constructor Infrastructure\Persistence\TaskCommentRepository
- use Domain\Entity\Task
- use Domain\Entity\TaskComment
- use Domain\Repository\TaskRepositoryInterface
- use Domain\ValueObject\TaskType
- use Infrastructure\Persistence\TaskCommentRepository
Klassen 1
-
CreateTaskUseCaseclass Zeile 15
Funktionen 3
-
__construct()public Zeile 17 -
execute()public Zeile 24 -
validate()private Zeile 56
Verwendet von 2
- TaskController.php use
- TaskController.php constructor
Versionen 6
-
v6
2025-12-25 17:02 | claude-code-hook | modified
Claude Code Pre-Hook Backup vor Edit-Operation -
v5
2025-12-25 17:02 | claude-code-hook | modified
Claude Code Pre-Hook Backup vor Edit-Operation -
v4
2025-12-25 17:01 | claude-code-hook | modified
Claude Code Pre-Hook Backup vor Edit-Operation -
v3
2025-12-25 17:01 | claude-code-hook | modified
Claude Code Pre-Hook Backup vor Edit-Operation -
v2
2025-12-23 08:14 | claude-code-hook | modified
Claude Code Pre-Hook Backup vor Edit-Operation -
v1
2025-12-23 07:54 | claude-code-hook | modified
Claude Code Pre-Hook Backup vor Edit-Operation
Code
<?php
declare(strict_types=1);
namespace UseCases\Task;
// @responsibility: Erstellt neue Tasks mit optionalen Kommentaren und Parent-Verknüpfung
use Domain\Entity\Task;
use Domain\Entity\TaskComment;
use Domain\Repository\TaskRepositoryInterface;
use Domain\ValueObject\TaskType;
use Infrastructure\Persistence\TaskCommentRepository;
class CreateTaskUseCase
{
public function __construct(
private TaskRepositoryInterface $taskRepository,
private TaskCommentRepository $commentRepository
) {
}
/** @param array<string, mixed> $data */
public function execute(array $data): Task
{
$this->validate($data);
$task = Task::create(
$data['title'],
$data['created_by'] ?? 'system',
$data['description'] ?? null,
isset($data['type']) ? TaskType::from($data['type']) : null,
isset($data['parent_task_id']) ? (int) $data['parent_task_id'] : null,
isset($data['due_date']) ? new \DateTimeImmutable($data['due_date']) : null
);
if (isset($data['metadata'])) {
$task->updateMetadata($data['metadata']);
}
$id = $this->taskRepository->save($task);
$task->setId($id);
$comment = new TaskComment();
$comment->setTaskId($id);
$comment->setAuthor($task->getCreatedBy());
$comment->setAuthorType($task->getCreatedByType());
$comment->setCommentType('note');
$comment->setContent('Task erstellt');
$this->commentRepository->save($comment);
return $task;
}
/** @param array<string, mixed> $data */
private function validate(array $data): void
{
if (!isset($data['title']) || $data['title'] === '') {
throw new \InvalidArgumentException('Title is required');
}
if (strlen($data['title']) > 255) {
throw new \InvalidArgumentException('Title must be 255 characters or less');
}
if (isset($data['type']) && !in_array($data['type'], ['human_task', 'ai_task', 'mixed'])) {
throw new \InvalidArgumentException('Invalid task type');
}
}
}