Lines
100.00%
10 / 10
Functions and Methods
100.00%
1 / 1
Classes and Traits
100.00%
1 / 1
| Name | Lines | Functions and Methods | CRAP | Classes and Traits | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Update | 100.00% | 10 / 10 | 100.00% | 1 / 1 | 3 | 100.00% | 1 / 1 | |||
| __invoke | 100.00% | 10 / 10 | 100.00% | 1 / 1 | 3 | |||||
| 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\Form\TimelineEventType; | |
| 10 | use App\Security\Voter\TimelineEventVoter; | |
| 11 | use Doctrine\ORM\EntityManagerInterface; | |
| 12 | use Symfony\Component\HttpFoundation\Request; | |
| 13 | use Symfony\Component\HttpFoundation\Response; | |
| 14 | use Symfony\Component\Routing\Attribute\Route; | |
| 15 | use Symfony\Component\Security\Http\Attribute\IsGranted; | |
| 16 | ||
| 17 | /** | |
| 18 | * Changes one of the user's timeline events. | |
| 19 | */ | |
| 20 | #[Route('/timeline-events/{id}/edit', name: 'app_timeline_event_edit', requirements: ['id' => '\d+'], methods: ['GET', 'POST'])] | |
| 21 | #[IsGranted(TimelineEventVoter::EDIT, subject: 'event')] | |
| 22 | final class Update extends BaseController | |
| 23 | { | |
| 24 | public function __invoke(Request $request, TimelineEvent $event, EntityManagerInterface $entityManager): Response | |
| 25 | { | |
| 26 | $form = $this->createForm(TimelineEventType::class, $event); | |
| 27 | $form->handleRequest($request); | |
| 28 | ||
| 29 | if ($form->isSubmitted() && $form->isValid()) { | |
| 30 | $entityManager->flush(); | |
| 31 | ||
| 32 | $this->addFlash('success', 'timeline.event.updated'); | |
| 33 | ||
| 34 | return $this->redirectToRoute('app_agent_stat_timeline', [], Response::HTTP_SEE_OTHER); | |
| 35 | } | |
| 36 | ||
| 37 | return $this->render('timeline_event/edit.html.twig', [ | |
| 38 | 'event' => $event, | |
| 39 | 'form' => $form, | |
| 40 | ]); | |
| 41 | } | |
| 42 | } |