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 | namespace App\Controller\User; | |
| 4 | ||
| 5 | use App\Controller\BaseController; | |
| 6 | use App\Entity\User; | |
| 7 | use App\Enum\UserRole; | |
| 8 | use App\Form\UserType; | |
| 9 | use Doctrine\ORM\EntityManagerInterface; | |
| 10 | use Symfony\Component\HttpFoundation\Request; | |
| 11 | use Symfony\Component\HttpFoundation\Response; | |
| 12 | use Symfony\Component\Routing\Attribute\Route; | |
| 13 | use Symfony\Component\Security\Http\Attribute\IsGranted; | |
| 14 | ||
| 15 | #[Route('/user/{id}/edit', name: 'app_user_edit', methods: ['GET', 'POST'])] | |
| 16 | #[IsGranted(UserRole::ADMIN->value)] | |
| 17 | final class Update extends BaseController | |
| 18 | { | |
| 19 | public function __invoke(Request $request, User $user, EntityManagerInterface $entityManager): Response | |
| 20 | { | |
| 21 | $form = $this->createForm(UserType::class, $user); | |
| 22 | $form->handleRequest($request); | |
| 23 | ||
| 24 | if ($form->isSubmitted() && $form->isValid()) { | |
| 25 | $entityManager->flush(); | |
| 26 | ||
| 27 | $this->addFlash('success', 'User has been updated.'); | |
| 28 | ||
| 29 | return $this->redirectToRoute('app_user_index', [], Response::HTTP_SEE_OTHER); | |
| 30 | } | |
| 31 | ||
| 32 | return $this->render('user/edit.html.twig', [ | |
| 33 | 'user' => $user, | |
| 34 | 'form' => $form, | |
| 35 | ]); | |
| 36 | } | |
| 37 | } |