Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
13 / 13 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
| UserController | |
100.00% |
13 / 13 |
|
100.00% |
2 / 2 |
4 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| profile | |
100.00% |
12 / 12 |
|
100.00% |
1 / 1 |
3 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace App\Controller; |
| 6 | |
| 7 | use App\Enum\UserRole; |
| 8 | use App\Form\ProfileFormType; |
| 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 | class UserController extends BaseController |
| 16 | { |
| 17 | public function __construct(private readonly EntityManagerInterface $entityManager) |
| 18 | { |
| 19 | } |
| 20 | |
| 21 | #[Route('/profile', name: 'app_profile', methods: ['GET', 'POST'])] |
| 22 | #[IsGranted(UserRole::USER->value)] |
| 23 | public function profile( |
| 24 | Request $request, |
| 25 | ): Response |
| 26 | { |
| 27 | $user = $this->getUser(); |
| 28 | $form = $this->createForm(ProfileFormType::class, $user?->getUserParams()) |
| 29 | ->handleRequest($request); |
| 30 | |
| 31 | if ($form->isSubmitted() && $form->isValid()) { |
| 32 | /** @var array<string> $params */ |
| 33 | $params = (array) $form->getData(); |
| 34 | $user?->setParams($params); |
| 35 | |
| 36 | $this->entityManager->flush(); |
| 37 | |
| 38 | $this->addFlash('success', 'User data have been saved.'); |
| 39 | |
| 40 | return $this->redirectToRoute('default'); |
| 41 | } |
| 42 | |
| 43 | return $this->render('user/profile.html.twig', [ |
| 44 | 'form' => $form, |
| 45 | ]); |
| 46 | } |
| 47 | } |