Completed
Push — master ( a682ba...4851b3 )
by Paweł
40:50
created

MenuFactory::create()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Superdesk Web Publisher Menu Bundle.
7
 *
8
 * Copyright 2016 Sourcefabric z.ú. and contributors.
9
 *
10
 * For the full copyright and license information, please see the
11
 * AUTHORS and LICENSE files distributed with this source code.
12
 *
13
 * @copyright 2016 Sourcefabric z.ú
14
 * @license http://www.superdesk.org/license
15
 */
16
17
namespace SWP\Bundle\MenuBundle\Factory;
18
19
use Knp\Menu\Factory\ExtensionInterface;
20
use SWP\Bundle\MenuBundle\Model\MenuItemInterface;
21
use SWP\Component\Storage\Factory\FactoryInterface;
22
23
final class MenuFactory implements MenuFactoryInterface
24
{
25
    /**
26
     * @var FactoryInterface
27
     */
28
    private $decoratedFactory;
29
30
    /**
31
     * @var ExtensionInterface
32
     */
33
    private $extensionChain;
34
35
    /**
36
     * MenuFactory constructor.
37
     *
38
     * @param FactoryInterface   $decoratedFactory
39
     * @param ExtensionInterface $extensionChain
40
     */
41 12
    public function __construct(FactoryInterface $decoratedFactory, ExtensionInterface $extensionChain)
42
    {
43 12
        $this->decoratedFactory = $decoratedFactory;
44 12
        $this->extensionChain = $extensionChain;
45 12
    }
46
47
    /**
48
     * {@inheritdoc}
49
     */
50 12
    public function create()
51
    {
52 12
        return $this->decoratedFactory->create();
53
    }
54
55
    /**
56
     * {@inheritdoc}
57
     */
58 12
    public function createItem($name, array $options = [])
59
    {
60
        /** @var MenuItemInterface $item */
61 12
        $item = $this->create();
62 12
        $item->setName($name);
63
64 12
        $options = $this->extensionChain->buildOptions($options);
65
66 12
        $this->extensionChain->buildItem($item, $options);
67
68 12
        return $item;
69
    }
70
}
71