Completed
Pull Request — development (#813)
by
unknown
04:11
created

MenuSubscriber::onSetupMenu()   A

Complexity

Conditions 4
Paths 8

Size

Total Lines 33

Duplication

Lines 21
Ratio 63.64 %

Importance

Changes 0
Metric Value
cc 4
nc 8
nop 1
dl 21
loc 33
rs 9.392
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Oc\Components\Subscriber;
6
7
use KevinPapst\AdminLTEBundle\Event\KnpMenuEvent;
8
use Oc\Entity\UserEntity;
9
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
10
use Symfony\Component\Security\Core\Security;
11
12
class MenuSubscriber implements EventSubscriberInterface
13
{
14
    /**
15
     * @var Security
16
     */
17
    private $security;
18
19
    public function __construct(Security $security)
20
    {
21
        $this->security = $security;
22
    }
23
24
    public static function getSubscribedEvents(): array
25
    {
26
        return [
27
            KnpMenuEvent::class => ['onSetupMenu', 100],
28
        ];
29
    }
30
31
    public function onSetupMenu(KnpMenuEvent $event)
32
    {
33
        $menu = $event->getMenu();
34
35
        $menu->addChild('MainNavigationMenuItem', [
36
            'label' => 'MAIN NAVIGATION',
37
            'childOptions' => $event->getChildOptions()
38
        ])->setAttribute('class', 'header');
39
40 View Code Duplication
        if ($this->security->isGranted("CAN_VIEW", UserEntity::class)) {
41
            $userMenu = $menu->addChild('cache', [
0 ignored issues
show
Unused Code introduced by
$userMenu is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
42
                'label' => 'Caches',
43
                'route' => 'backend_caches_index',
44
                'childOptions' => $event->getChildOptions(),
45
            ])->setLabelAttribute('icon', 'fas fa-map-marker-alt');
46
        }
47
48 View Code Duplication
        if ($this->security->isGranted("CAN_VIEW", UserEntity::class)) {
49
            $userMenu = $menu->addChild('user', [
0 ignored issues
show
Unused Code introduced by
$userMenu is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
50
                'label' => 'Users',
51
                'route' => 'backend_user_index',
52
                'childOptions' => $event->getChildOptions(),
53
            ])->setLabelAttribute('icon', 'fas fa-users');
54
        }
55
56 View Code Duplication
        if ($this->security->isGranted("CAN_VIEW", UserEntity::class)) {
57
            $userMenu = $menu->addChild('kitchensink', [
0 ignored issues
show
Unused Code introduced by
$userMenu is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
58
                'label' => 'Kitchensink',
59
                'route' => 'app_kitchensink_index',
60
                'childOptions' => $event->getChildOptions(),
61
            ])->setLabelAttribute('icon', 'fab fa-css3');
62
        }
63
    }
64
}
65