Completed
Push — master ( 62a450...2faef5 )
by
unknown
12s
created

EditController   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 4
dl 0
loc 56
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
B __construct() 0 26 1
A editAction() 0 10 3
1
<?php
2
3
namespace SumoCoders\FrameworkUserBundle\Controller;
4
5
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
6
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
7
use SumoCoders\FrameworkMultiUserBundle\Command\Handler;
8
use SumoCoders\FrameworkMultiUserBundle\Controller\UserController;
9
use SumoCoders\FrameworkMultiUserBundle\User\Interfaces\UserRepository;
10
use Symfony\Bundle\FrameworkBundle\Routing\Router;
11
use Symfony\Component\Form\FormFactoryInterface;
12
use Symfony\Component\HttpFoundation\Request;
13
use Symfony\Component\HttpFoundation\Session\Flash\FlashBagInterface;
14
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
15
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
16
use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
17
use Symfony\Component\Translation\TranslatorInterface;
18
19
/**
20
 * @Route(service="sumo_coders.user.controller.edit_user")
21
 */
22
final class EditController extends UserController
23
{
24
    /** @var AuthorizationCheckerInterface */
25
    private $authorizationChecker;
26
27
    /** @var TokenStorageInterface */
28
    private $tokenStorage;
29
30
    public function __construct(
31
        AuthorizationCheckerInterface $authorizationChecker,
32
        TokenStorageInterface $tokenStorage,
33
        FormFactoryInterface $formFactory,
34
        Router $router,
35
        FlashBagInterface $flashBag,
36
        TranslatorInterface $translator,
37
        string $form,
38
        Handler $handler,
39
        UserRepository $userRepository,
40
        $redirectRoute = null
41
    ) {
42
        $this->authorizationChecker = $authorizationChecker;
43
        $this->tokenStorage = $tokenStorage;
44
45
        parent::__construct(
46
            $formFactory,
47
            $router,
48
            $flashBag,
49
            $translator,
50
            $form,
51
            $handler,
52
            $userRepository,
53
            $redirectRoute
54
        );
55
    }
56
57
    /**
58
     * @Template("SumoCodersFrameworkMultiUserBundle:User:base.html.twig")
59
     *
60
     * @param Request $request
61
     * @param int|null $id
62
     *
63
     * @return array
64
     *
65
     * @throws AccessDeniedHttpException if not allowed to edit user
66
     */
67
    public function editAction(Request $request, ?int $id): array
68
    {
69
        if (!$this->authorizationChecker->isGranted('ROLE_ADMIN')
70
            && $this->tokenStorage->getToken()->getUser()->getId() !== $id
71
        ) {
72
            throw new AccessDeniedHttpException('Access denied.');
73
        }
74
75
        return parent::baseAction($request, $id);
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (baseAction() instead of editAction()). Are you sure this is correct? If so, you might want to change this to $this->baseAction().

This check looks for a call to a parent method whose name is different than the method from which it is called.

Consider the following code:

class Daddy
{
    protected function getFirstName()
    {
        return "Eidur";
    }

    protected function getSurName()
    {
        return "Gudjohnsen";
    }
}

class Son
{
    public function getFirstName()
    {
        return parent::getSurname();
    }
}

The getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
76
    }
77
}
78