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
3declare(strict_types=1);
4
5namespace App\Controller\TimelineEvent;
6
7use App\Controller\BaseController;
8use App\Entity\TimelineEvent;
9use App\Form\TimelineEventType;
10use App\Security\Voter\TimelineEventVoter;
11use Doctrine\ORM\EntityManagerInterface;
12use Symfony\Component\HttpFoundation\Request;
13use Symfony\Component\HttpFoundation\Response;
14use Symfony\Component\Routing\Attribute\Route;
15use 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')]
22final 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}