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
|
|
|
|
41
|
|
|
|
42
|
|
View Code Duplication |
if ($this->security->isGranted("CAN_VIEW", UserEntity::class)) { |
43
|
|
|
$cacheMenu = $menu->addChild('cache', [ |
|
|
|
|
44
|
|
|
'label' => 'Caches', |
45
|
|
|
'route' => 'backend_user_index', |
46
|
|
|
'childOptions' => $event->getChildOptions(), |
47
|
|
|
])->setLabelAttribute('icon', 'fas fa-map-marker-alt'); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
View Code Duplication |
if ($this->security->isGranted("CAN_VIEW", UserEntity::class)) { |
51
|
|
|
$userMenu = $menu->addChild('user', [ |
|
|
|
|
52
|
|
|
'label' => 'Benutzer', |
53
|
|
|
'route' => 'backend_user_index', |
54
|
|
|
'childOptions' => $event->getChildOptions(), |
55
|
|
|
])->setLabelAttribute('icon', 'fas fa-users'); |
56
|
|
|
} |
57
|
|
|
} |
58
|
|
|
} |
59
|
|
|
|
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
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.