Completed
Pull Request — master (#120)
by De Cramer
02:35
created

MenuItemProvider::registerPlugin()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 2
1
<?php
2
3
namespace eXpansion\Bundle\Menu\DataProviders;
4
5
use eXpansion\Bundle\Menu\Model\Menu\ItemInterface;
6
use eXpansion\Bundle\Menu\Model\Menu\ParentItem;
7
use eXpansion\Bundle\Menu\Services\ItemBuilder;
8
use eXpansion\Framework\Core\DataProviders\AbstractDataProvider;
9
use FML\Controls\Quad;
10
11
/**
12
 * Class MenuItemProvider
13
 *
14
 * @author    de Cramer Oliver<[email protected]>
15
 * @copyright 2017 Smile
16
 * @package eXpansion\Bundle\Menu\DataProviders
17
 */
18
class MenuItemProvider extends AbstractDataProvider
19
{
20
    /** @var ItemBuilder */
21
    protected $itemBuilder;
22
23
    /** @var ItemInterface|null */
24
    protected $rootItem = null;
25
26
    /**
27
     * MenuItemProvider constructor.
28
     *
29
     * @param ItemBuilder $itemBuilder
30
     */
31
    public function __construct(ItemBuilder $itemBuilder)
32
    {
33
        $this->itemBuilder = $itemBuilder;
34
    }
35
36
37
    public function registerPlugin($pluginId, $pluginService)
38
    {
39
        $this->rootItem = null;
40
        parent::registerPlugin($pluginId, $pluginService);
41
    }
42
43
    public function deletePlugin($pluginId)
44
    {
45
        $this->rootItem = null;
46
        parent::deletePlugin($pluginId);
47
    }
48
49
    /**
50
     * @return ParentItem|null
51
     */
52
    public function getRootItem()
53
    {
54
        if (is_null($this->rootItem)) {
55
            $this->rootItem = $this->itemBuilder->create(
56
                ParentItem::class, "root", "", "root", Quad::create(), null
0 ignored issues
show
Documentation introduced by
null is of type null, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
57
            );
58
            foreach ($this->plugins as $plugin) {
59
                $plugin->registerMenuItems($this->rootItem);
60
            }
61
        }
62
63
        return $this->rootItem;
64
    }
65
}