Completed
Push — master ( 9de44c...cc28ed )
by Paweł
21:07 queued 20:52
created

ProductVariantFormMenuBuilder::createMenu()   B

Complexity

Conditions 3
Paths 2

Size

Total Lines 28
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 28
rs 8.8571
c 0
b 0
f 0
cc 3
eloc 17
nc 2
nop 1
1
<?php
2
3
/*
4
 * This file is part of the Sylius package.
5
 *
6
 * (c) Paweł Jędrzejewski
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Sylius\Bundle\AdminBundle\Menu;
13
14
use Knp\Menu\FactoryInterface;
15
use Knp\Menu\ItemInterface;
16
use Sylius\Bundle\AdminBundle\Event\ProductVariantMenuBuilderEvent;
17
use Sylius\Component\Product\Model\ProductVariantInterface;
18
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
19
20
/**
21
 * @author Jan Góralski <[email protected]>
22
 */
23
final class ProductVariantFormMenuBuilder
24
{
25
    const EVENT_NAME = 'sylius.menu.admin.product_variant.form';
26
27
    /**
28
     * @var FactoryInterface
29
     */
30
    private $factory;
31
32
    /**
33
     * @var EventDispatcherInterface
34
     */
35
    private $eventDispatcher;
36
37
    /**
38
     * @param FactoryInterface $factory
39
     * @param EventDispatcherInterface $eventDispatcher
40
     */
41
    public function __construct(FactoryInterface $factory, EventDispatcherInterface $eventDispatcher)
42
    {
43
        $this->factory = $factory;
44
        $this->eventDispatcher = $eventDispatcher;
45
    }
46
47
    /**
48
     * @param array $options
49
     *
50
     * @return ItemInterface
51
     */
52
    public function createMenu(array $options = [])
53
    {
54
        $menu = $this->factory->createItem('root');
55
56
        if (!array_key_exists('product_variant', $options) || !$options['product_variant'] instanceof ProductVariantInterface) {
57
            return $menu;
58
        }
59
60
        $menu
61
            ->addChild('details')
62
            ->setAttribute('template', '@SyliusAdmin/ProductVariant/Tab/_details.html.twig')
63
            ->setLabel('sylius.ui.details')
64
            ->setCurrent(true)
65
        ;
66
67
        $menu
68
            ->addChild('taxes')
69
            ->setAttribute('template', '@SyliusAdmin/ProductVariant/Tab/_taxes.html.twig')
70
            ->setLabel('sylius.ui.taxes')
71
        ;
72
73
        $this->eventDispatcher->dispatch(
74
            self::EVENT_NAME,
75
            new ProductVariantMenuBuilderEvent($this->factory, $menu, $options['product_variant'])
0 ignored issues
show
Compatibility introduced by
$options['product_variant'] of type object<Sylius\Component\...roductVariantInterface> is not a sub-type of object<Sylius\Component\...roductVariantInterface>. It seems like you assume a child interface of the interface Sylius\Component\Product...ProductVariantInterface to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
76
        );
77
78
        return $menu;
79
    }
80
}
81