DeleteTaskUseCase.php
- Pfad:
src/UseCases/Task/DeleteTaskUseCase.php - Namespace: UseCases\Task
- Zeilen: 55 | Größe: 1,419 Bytes
- Geändert: 2025-12-23 08:49:24 | 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 2
- constructor Domain\Repository\TaskRepositoryInterface
- use Domain\Repository\TaskRepositoryInterface
Klassen 1
-
DeleteTaskUseCaseclass Zeile 11
Funktionen 3
-
__construct()public Zeile 13 -
execute()public Zeile 18 -
executeCascade()Zeile 35
Verwendet von 2
- TaskController.php constructor
- TaskController.php use
Versionen 2
-
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: Löscht Tasks nach Validierung der Subtask-Abhängigkeiten
use Domain\Repository\TaskRepositoryInterface;
class DeleteTaskUseCase
{
public function __construct(
private TaskRepositoryInterface $taskRepository
) {
}
public function execute(int $taskId): bool
{
$task = $this->taskRepository->find($taskId);
if ($task === null) {
throw new \InvalidArgumentException("Task {$taskId} not found");
}
$subtasks = $this->taskRepository->findSubtasks($taskId);
if (count($subtasks) > 0) {
throw new \InvalidArgumentException(
'Cannot delete task with subtasks. Delete subtasks first or use cascade delete.'
);
}
return $this->taskRepository->delete($taskId);
}
public function executeCascade(int $taskId): int
{
$task = $this->taskRepository->find($taskId);
if ($task === null) {
throw new \InvalidArgumentException("Task {$taskId} not found");
}
$deleted = 0;
$subtasks = $this->taskRepository->findSubtasks($taskId);
foreach ($subtasks as $subtask) {
$deleted += $this->executeCascade($subtask->getId());
}
$this->taskRepository->delete($taskId);
$deleted++;
return $deleted;
}
}