Completed
Pull Request — master (#79)
by Valery
09:07 queued 09:07
created

ProfileController::profile()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 16
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 11
nc 2
nop 2
dl 0
loc 16
rs 9.9
c 1
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace App\Controller\User;
6
7
use App\Controller\BaseController;
8
use App\Form\Type\ProfileType;
9
use Doctrine\ORM\EntityManagerInterface;
10
use Symfony\Component\HttpFoundation\Request;
11
use Symfony\Component\HttpFoundation\Response;
12
use Symfony\Component\Routing\Annotation\Route;
13
14
final class ProfileController extends BaseController
15
{
16
    #[Route('/user/profile', name: 'user_profile')]
17
    public function profile(Request $request, EntityManagerInterface $entityManager): Response
18
    {
19
        $profile = $this->getUser()->getProfile();
0 ignored issues
show
Bug introduced by
The method getProfile() does not exist on Symfony\Component\Security\Core\User\UserInterface. It seems like you code against a sub-type of Symfony\Component\Security\Core\User\UserInterface such as App\Entity\User. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

19
        $profile = $this->getUser()->/** @scrutinizer ignore-call */ getProfile();
Loading history...
20
        $form = $this->createForm(ProfileType::class, $profile);
21
        $form->handleRequest($request);
22
23
        if ($form->isSubmitted() && $form->isValid()) {
24
            $entityManager->persist($profile);
25
            $entityManager->flush();
26
            $this->addFlash('success', 'message.updated');
27
        }
28
29
        return $this->render('user/profile/profile.html.twig', [
30
            'site' => $this->site($request),
31
            'form' => $form->createView(),
32
        ]);
33
    }
34
}
35