UpdateTaskStatusUseCase.php
- Pfad:
src/UseCases/Task/UpdateTaskStatusUseCase.php - Namespace: UseCases\Task
- Zeilen: 96 | Größe: 3,073 Bytes
- Geändert: 2025-12-28 23:32:55 | 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 6
- constructor Domain\Repository\TaskRepositoryInterface
- constructor Infrastructure\Persistence\TaskCommentRepository
- use Domain\Entity\Task
- use Domain\Entity\TaskComment
- use Domain\Repository\TaskRepositoryInterface
- use Infrastructure\Persistence\TaskCommentRepository
Klassen 1
-
UpdateTaskStatusUseCaseclass Zeile 14
Funktionen 6
-
__construct()public Zeile 16 -
execute()public Zeile 28 -
startTask()Zeile 64 -
completeTask()Zeile 73 -
failTask()Zeile 82 -
cancelTask()Zeile 91
Verwendet von 3
- ExecuteAITaskUseCase.php constructor
- TaskController.php constructor
- TaskController.php use
Versionen 5
-
v5
2025-12-28 23:32 | claude-code-hook | modified
Claude Code Pre-Hook Backup vor Edit-Operation -
v4
2025-12-28 23:32 | 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:15 | claude-code-hook | modified
Claude Code Pre-Hook Backup vor Edit-Operation -
v1
2025-12-23 07:55 | claude-code-hook | modified
Claude Code Pre-Hook Backup vor Edit-Operation
Code
<?php
declare(strict_types=1);
namespace UseCases\Task;
// @responsibility: Aktualisiert Task-Status mit Workflow-Validierung
use Domain\Entity\Task;
use Domain\Entity\TaskComment;
use Domain\Repository\TaskRepositoryInterface;
use Infrastructure\Persistence\TaskCommentRepository;
class UpdateTaskStatusUseCase
{
public function __construct(
private TaskRepositoryInterface $taskRepository,
private TaskCommentRepository $commentRepository
) {
}
/**
* Update task status with workflow validation.
*
* @throws \InvalidArgumentException When task not found or invalid status
* @throws \RuntimeException When repository operations fail
*/
public function execute(int $taskId, string $newStatus, string $updatedBy, string $updatedByType = 'human'): Task
{
$task = $this->taskRepository->find($taskId);
if ($task === null) {
throw new \InvalidArgumentException("Task {$taskId} not found");
}
$oldStatus = $task->getStatus();
match ($newStatus) {
'in_progress' => $task->start(),
'completed' => $task->complete(),
'failed' => $task->fail(),
'cancelled' => $task->cancel(),
'pending' => $task->retry(),
default => throw new \InvalidArgumentException("Invalid status: {$newStatus}"),
};
$this->taskRepository->update($task);
$comment = TaskComment::createStatusChange(
$taskId,
$updatedBy,
$updatedByType,
$oldStatus->label(),
$task->getStatus()->label()
);
$this->commentRepository->save($comment);
return $task;
}
/**
* @throws \InvalidArgumentException When task not found
* @throws \RuntimeException When repository operations fail
*/
public function startTask(int $taskId, string $updatedBy, string $updatedByType = 'human'): Task
{
return $this->execute($taskId, 'in_progress', $updatedBy, $updatedByType);
}
/**
* @throws \InvalidArgumentException When task not found
* @throws \RuntimeException When repository operations fail
*/
public function completeTask(int $taskId, string $updatedBy, string $updatedByType = 'human'): Task
{
return $this->execute($taskId, 'completed', $updatedBy, $updatedByType);
}
/**
* @throws \InvalidArgumentException When task not found
* @throws \RuntimeException When repository operations fail
*/
public function failTask(int $taskId, string $updatedBy, string $updatedByType = 'human'): Task
{
return $this->execute($taskId, 'failed', $updatedBy, $updatedByType);
}
/**
* @throws \InvalidArgumentException When task not found
* @throws \RuntimeException When repository operations fail
*/
public function cancelTask(int $taskId, string $updatedBy, string $updatedByType = 'human'): Task
{
return $this->execute($taskId, 'cancelled', $updatedBy, $updatedByType);
}
}