Lines
100.00%
11 / 11
Functions and Methods
100.00%
1 / 1
Classes and Traits
100.00%
1 / 1
| Name | Lines | Functions and Methods | CRAP | Classes and Traits | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| ProfileController | 100.00% | 11 / 11 | 100.00% | 1 / 1 | 3 | 100.00% | 1 / 1 | |||
| __invoke | 100.00% | 11 / 11 | 100.00% | 1 / 1 | 3 | |||||
| 1 | <?php | |
| 2 | ||
| 3 | namespace App\Controller; | |
| 4 | ||
| 5 | use App\Enum\UserRole; | |
| 6 | use App\Form\UserParamsType; | |
| 7 | use Doctrine\ORM\EntityManagerInterface; | |
| 8 | use Symfony\Component\HttpFoundation\Request; | |
| 9 | use Symfony\Component\HttpFoundation\Response; | |
| 10 | use Symfony\Component\Routing\Attribute\Route; | |
| 11 | use Symfony\Component\Security\Http\Attribute\IsGranted; | |
| 12 | ||
| 13 | #[Route('/profile', name: 'app_profile', methods: ['GET', 'POST'])] | |
| 14 | #[IsGranted(UserRole::USER->value)] | |
| 15 | class ProfileController extends BaseController | |
| 16 | { | |
| 17 | public function __invoke(Request $request, EntityManagerInterface $entityManager): Response | |
| 18 | { | |
| 19 | $user = $this->getUser(); | |
| 20 | $form = $this->createForm(UserParamsType::class, $user->getParams()); | |
| 21 | $form->handleRequest($request); | |
| 22 | ||
| 23 | if ($form->isSubmitted() && $form->isValid()) { | |
| 24 | $user->setParams($form->getData()); | |
| 25 | ||
| 26 | $entityManager->flush(); | |
| 27 | ||
| 28 | $this->addFlash('success', 'User data have been saved.'); | |
| 29 | ||
| 30 | return $this->redirectToRoute('app_default'); | |
| 31 | } | |
| 32 | ||
| 33 | return $this->render('default/profile.html.twig', [ | |
| 34 | 'form' => $form, | |
| 35 | ]); | |
| 36 | } | |
| 37 | } |