Lines
100.00%
5 / 5
Functions and Methods
100.00%
1 / 1
Classes and Traits
100.00%
1 / 1
| Name | Lines | Functions and Methods | CRAP | Classes and Traits | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Delete | 100.00% | 5 / 5 | 100.00% | 1 / 1 | 2 | 100.00% | 1 / 1 | |||
| __invoke | 100.00% | 5 / 5 | 100.00% | 1 / 1 | 2 | |||||
| 1 | <?php | |
| 2 | ||
| 3 | declare(strict_types=1); | |
| 4 | ||
| 5 | namespace App\Controller\TimelineEvent; | |
| 6 | ||
| 7 | use App\Controller\BaseController; | |
| 8 | use App\Entity\TimelineEvent; | |
| 9 | use App\Security\Voter\TimelineEventVoter; | |
| 10 | use Doctrine\ORM\EntityManagerInterface; | |
| 11 | use Symfony\Component\HttpFoundation\Request; | |
| 12 | use Symfony\Component\HttpFoundation\Response; | |
| 13 | use Symfony\Component\Routing\Attribute\Route; | |
| 14 | use Symfony\Component\Security\Http\Attribute\IsGranted; | |
| 15 | ||
| 16 | /** | |
| 17 | * Deletes one of the user's timeline events. | |
| 18 | */ | |
| 19 | #[Route('/timeline-events/{id}/delete', name: 'app_timeline_event_delete', requirements: ['id' => '\d+'], methods: ['POST'])] | |
| 20 | #[IsGranted(TimelineEventVoter::EDIT, subject: 'event')] | |
| 21 | final class Delete extends BaseController | |
| 22 | { | |
| 23 | public function __invoke(Request $request, TimelineEvent $event, EntityManagerInterface $entityManager): Response | |
| 24 | { | |
| 25 | if ($this->isCsrfTokenValid('delete-event'.$event->id, $request->getPayload()->getString('_token'))) { | |
| 26 | $entityManager->remove($event); | |
| 27 | $entityManager->flush(); | |
| 28 | ||
| 29 | $this->addFlash('success', 'timeline.event.deleted'); | |
| 30 | } | |
| 31 | ||
| 32 | return $this->redirectToRoute('app_agent_stat_timeline', [], Response::HTTP_SEE_OTHER); | |
| 33 | } | |
| 34 | } |