Completed
Push — master ( 6877de...e97208 )
by
unknown
17s queued 11s
created

EditController   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 66
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 6
dl 0
loc 66
ccs 0
cts 23
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
B __construct() 0 30 1
B editAction() 0 16 5
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\FrameworkCoreBundle\BreadCrumb\BreadCrumbBuilder;
8
use SumoCoders\FrameworkMultiUserBundle\Command\Handler;
9
use SumoCoders\FrameworkMultiUserBundle\Controller\UserController;
10
use SumoCoders\FrameworkMultiUserBundle\User\Interfaces\UserRepository;
11
use Symfony\Bundle\FrameworkBundle\Routing\Router;
12
use Symfony\Component\Form\FormFactoryInterface;
13
use Symfony\Component\HttpFoundation\RedirectResponse;
14
use Symfony\Component\HttpFoundation\Request;
15
use Symfony\Component\HttpFoundation\Session\Flash\FlashBagInterface;
16
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
17
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
18
use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
19
use Symfony\Component\Translation\TranslatorInterface;
20
21
/**
22
 * @Route(service="sumo_coders.user.controller.edit_user")
23
 */
24
final class EditController extends UserController
25
{
26
    /** @var AuthorizationCheckerInterface */
27
    private $authorizationChecker;
28
29
    /** @var TokenStorageInterface */
30
    private $tokenStorage;
31
32
    public function __construct(
33
        AuthorizationCheckerInterface $authorizationChecker,
34
        TokenStorageInterface $tokenStorage,
35
        FormFactoryInterface $formFactory,
36
        Router $router,
37
        FlashBagInterface $flashBag,
38
        TranslatorInterface $translator,
39
        string $form,
40
        Handler $handler,
41
        UserRepository $userRepository,
42
        BreadCrumbBuilder $breadCrumbBuilder,
43
        array $breadcrumbs,
44
        $redirectRoute = null
45
    ) {
46
        $this->authorizationChecker = $authorizationChecker;
47
        $this->tokenStorage = $tokenStorage;
48
49
        parent::__construct(
50
            $formFactory,
51
            $router,
52
            $flashBag,
53
            $translator,
54
            $form,
55
            $handler,
56
            $userRepository,
57
            $breadCrumbBuilder,
58
            $breadcrumbs,
59
            $redirectRoute
60
        );
61
    }
62
63
    /**
64
     * @Template("SumoCodersFrameworkMultiUserBundle:User:base.html.twig")
65
     *
66
     * @param Request $request
67
     * @param int|null $id
68
     *
69
     * @return array|RedirectResponse
70
     *
71
     * @throws AccessDeniedHttpException if not allowed to edit user
72
     */
73
    public function editAction(Request $request, ?int $id)
74
    {
75
        if (!$this->authorizationChecker->isGranted('ROLE_ADMIN')
76
            && $this->tokenStorage->getToken()->getUser()->getId() !== $id
77
        ) {
78
            throw new AccessDeniedHttpException('Access denied.');
79
        }
80
81
        $response = 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...
82
83
        if ($response instanceof RedirectResponse && !$this->authorizationChecker->isGranted('ROLE_ADMIN')) {
84
            return RedirectResponse::create($request->getPathInfo());
85
        }
86
87
        return $response;
88
    }
89
}
90