AbstractMenuBuilder::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 5
ccs 4
cts 4
cp 1
rs 9.4285
cc 1
eloc 3
nc 1
nop 2
crap 1
1
<?php
2
3
/*
4
 * This file is part of the Lug package.
5
 *
6
 * (c) Eric GELOEN <[email protected]>
7
 *
8
 * For the full copyright and license information, please read the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Lug\Bundle\UiBundle\Menu;
13
14
use Knp\Menu\FactoryInterface;
15
use Knp\Menu\ItemInterface;
16
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
17
18
/**
19
 * @author GeLo <[email protected]>
20
 */
21
abstract class AbstractMenuBuilder implements MenuBuilderInterface
22
{
23
    /**
24
     * @var FactoryInterface
25
     */
26
    private $factory;
27
28
    /**
29
     * @var EventDispatcherInterface
30
     */
31
    private $eventDispatcher;
32
33
    /**
34
     * @param FactoryInterface         $factory
35
     * @param EventDispatcherInterface $eventDispatcher
36
     */
37 2
    public function __construct(FactoryInterface $factory, EventDispatcherInterface $eventDispatcher)
38
    {
39 2
        $this->factory = $factory;
40 2
        $this->eventDispatcher = $eventDispatcher;
41 2
    }
42
43
    /**
44
     * @return ItemInterface
45
     */
46 1
    public function create()
47
    {
48 1
        $this->eventDispatcher->dispatch(MenuBuilderEvents::BUILD, $event = new MenuBuilderEvent(
49 1
            $this->factory,
50 1
            $this->factory->createItem($this->getName())
51 1
        ));
52
53 1
        return $event->getItem();
54
    }
55
}
56