Completed
Pull Request — master (#130)
by De Cramer
07:55
created

MenuTabsFactory::createTabsMenu()   B

Complexity

Conditions 4
Paths 4

Size

Total Lines 43
Code Lines 32

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 43
rs 8.5806
c 1
b 0
f 0
cc 4
eloc 32
nc 4
nop 4
1
<?php
2
3
namespace eXpansion\Bundle\Menu\Gui;
4
5
use eXpansion\Bundle\Menu\Model\Menu\ParentItem;
6
use eXpansion\Framework\Core\Model\Gui\ManialinkInterface;
7
use eXpansion\Framework\Core\Plugins\Gui\ActionFactory;
8
use eXpansion\Framework\Gui\Ui\Factory;
9
use FML\Types\Container;
10
use FML\Types\Renderable;
11
12
/**
13
 * Class MenuTabsFactory
14
 *
15
 * @author    de Cramer Oliver<[email protected]>
16
 * @copyright 2017 Smile
17
 * @package eXpansion\Bundle\Maps\Gui
18
 */
19
class MenuTabsFactory
20
{
21
    /** @var Factory */
22
    protected $uiFactory;
23
24
    /** @var ActionFactory */
25
    protected $actionFactory;
26
27
    /**
28
     * MenuTabsFactory constructor.
29
     *
30
     * @param Factory $uiFactory
31
     * @param ActionFactory $actionFactory
32
     */
33
    public function __construct(Factory $uiFactory, ActionFactory $actionFactory)
34
    {
35
        $this->uiFactory = $uiFactory;
36
        $this->actionFactory = $actionFactory;
37
    }
38
39
    /**
40
     * @param ManialinkInterface $manialink
41
     * @param Container $tabsFrame
42
     * @param ParentItem $rootItem
43
     * @param $openId
44
     *
45
     * @return Renderable
46
     */
47
    public function createTabsMenu(ManialinkInterface $manialink, Container $tabsFrame, ParentItem $rootItem, $openId)
48
    {
49
        $label = $this->uiFactory->createLabel("expansion_menu.menu");
50
        $label->setPosition(0, 0);
51
        $label->setSize(30, 5);
52
        $label->setTextSize(4);
53
        $label->setTextColor('FFFFFF');
54
        $label->setHorizontalAlign(Label::CENTER);
55
        $label->setTranslate(true);
56
        $tabsFrame->addChild($label);
57
58
        $posX = 28;
59
        foreach ($rootItem->getChilds() as $item) {
60
            if ($rootItem->isVisibleFor($manialink->getUserGroup())) {
0 ignored issues
show
Documentation introduced by
$manialink->getUserGroup() is of type object<eXpansion\Framewo...Model\UserGroups\Group>, but the function expects a string.

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...
61
                $action = $this->actionFactory->createManialinkAction(
62
                    $manialink,
63
                    [$this, 'callbackItemClick'],
64
                    ['item' => $item, 'ml' => $manialink]
65
                );
66
                $label = $this->uiFactory->createLabel($item->getLabelId());
67
68
                $label->setPosition($posX, 0);
69
                $label->setSize(24, 5);
70
                $label->setAction($action);
71
                $label->setTextSize(3);
72
                $label->setTextColor('FFFFFF');
73
                $label->setHorizontalAlign(Label::CENTER);
74
                $label->setTranslate(true);
75
76
                if ($item->getId() == $openId) {
77
                    $underline = $this->uiFactory->createLine($posX - 13, -5);
78
                    $underline->to($posX + 13, -5);
79
                    $underline->setColor('FFFFFF');
80
                    $tabsFrame->addChild($underline);
81
                }
82
83
                $tabsFrame->addChild($label);
84
                $posX += 26;
85
            }
86
        }
87
88
        return $tabsFrame;
89
    }
90
}