UserMenuBuilder::createMenu()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 20
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
cc 1
eloc 14
c 3
b 0
f 0
nc 1
nop 1
dl 0
loc 20
rs 9.7998
1
<?php
2
3
declare(strict_types=1);
4
5
namespace LAG\AdminBundle\Bridge\KnpMenu\Builder;
6
7
use Knp\Menu\FactoryInterface;
8
use Knp\Menu\ItemInterface;
9
use LAG\AdminBundle\Event\Events\MenuCreatedEvent;
10
use LAG\AdminBundle\Event\Events\MenuCreateEvent;
11
use LAG\AdminBundle\Event\MenuEvents;
12
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
13
14
class UserMenuBuilder
15
{
16
    public function __construct(
17
        private FactoryInterface $factory,
18
        private EventDispatcherInterface $eventDispatcher,
19
    ) {
20
    }
21
22
    public function createMenu(array $options = []): ItemInterface
0 ignored issues
show
Unused Code introduced by
The parameter $options is not used and could be removed. ( Ignorable by Annotation )

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

22
    public function createMenu(/** @scrutinizer ignore-unused */ array $options = []): ItemInterface

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
23
    {
24
        $menu = $this->factory->createItem('root');
25
        $this->eventDispatcher->dispatch($event = new MenuCreateEvent($menu), MenuEvents::MENU_CREATE);
26
        $this->eventDispatcher->dispatch($event = new MenuCreateEvent($event->getMenu()), sprintf(
27
            MenuEvents::NAMED_EVENT_PATTERN,
28
            'user',
29
        ));
30
        $menu = $event->getMenu();
31
        $menu->addChild('lag_admin.security.logout', [
32
            'route' => 'lag_admin.logout',
33
            'extras' => ['icon' => 'sign-out-alt'],
34
        ]);
35
        $this->eventDispatcher->dispatch(new MenuCreatedEvent($menu), MenuEvents::MENU_CREATED);
36
        $this->eventDispatcher->dispatch(new MenuCreatedEvent($menu), sprintf(
37
            MenuEvents::NAMED_EVENT_PATTERN,
38
            'user',
39
        ));
40
41
        return $menu;
42
    }
43
}
44