security->isGranted('ROLE_USER')) { throw new AccessDeniedException('Access denied: ROLE_USER required.'); } $task = $this->taskRepository->find($id); if (null === $task) { throw new InvalidArgumentException(sprintf('Task with ID %d not found.', $id)); } $taskCode = $task->getProject()->getCode().'-'.$task->getNumber(); $this->entityManager->remove($task); $this->entityManager->flush(); return json_encode([ 'success' => true, 'message' => sprintf('Task %s deleted.', $taskCode), ]); } }