Passed
Pull Request — master (#374)
by Arnaud
32:43 queued 25:11
created

AbstractMenuBuilder   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 9
c 1
b 0
f 0
dl 0
loc 24
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A build() 0 14 1
A __construct() 0 4 1
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\MenuEvent;
0 ignored issues
show
Bug introduced by
The type LAG\AdminBundle\Event\Events\MenuEvent was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
10
use LAG\AdminBundle\Event\MenuEvents;
11
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
12
13
abstract class AbstractMenuBuilder implements MenuBuilderInterface
14
{
15
    public function __construct(
16
        private FactoryInterface $factory,
17
        private EventDispatcherInterface $eventDispatcher,
18
    ) {
19
    }
20
21
    abstract protected function buildMenu(ItemInterface $menu): void;
22
23
    public function build(array $options = []): ItemInterface
24
    {
25
        $menu = $this->factory->createItem('root', $options);
26
        $event = new MenuEvent($menu);
27
28
        $this->eventDispatcher->dispatch($event, MenuEvents::MENU_CREATE);
29
        $this->eventDispatcher->dispatch($event, sprintf(MenuEvents::PRE_EVENT_PATTERN, $this->getName()));
0 ignored issues
show
Bug introduced by
The constant LAG\AdminBundle\Event\Me...ents::PRE_EVENT_PATTERN was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
30
31
        $this->buildMenu($menu);
32
33
        $this->eventDispatcher->dispatch($event, MenuEvents::MENU_CREATED);
34
        $this->eventDispatcher->dispatch($event, sprintf(MenuEvents::POST_EVENT_PATTERN, $this->getName()));
0 ignored issues
show
Bug introduced by
The constant LAG\AdminBundle\Event\Me...nts::POST_EVENT_PATTERN was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
35
36
        return $menu;
37
    }
38
}
39