Completed
Pull Request — master (#130)
by
unknown
02:47
created

MenuTabsFactory::createTabsMenu()   B

Complexity

Conditions 4
Paths 4

Size

Total Lines 44
Code Lines 32

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 44
rs 8.5806
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\Controls\Label;
10
use FML\Types\Container;
11
use FML\Types\Renderable;
12
13
/**
14
 * Class MenuTabsFactory
15
 *
16
 * @author    de Cramer Oliver<[email protected]>
17
 * @copyright 2017 Smile
18
 * @package eXpansion\Bundle\Maps\Gui
19
 */
20
class MenuTabsFactory
21
{
22
    /** @var Factory */
23
    protected $uiFactory;
24
25
    /** @var ActionFactory */
26
    protected $actionFactory;
27
28
    /**
29
     * MenuTabsFactory constructor.
30
     *
31
     * @param Factory $uiFactory
32
     * @param ActionFactory $actionFactory
33
     */
34
    public function __construct(Factory $uiFactory, ActionFactory $actionFactory)
35
    {
36
        $this->uiFactory = $uiFactory;
37
        $this->actionFactory = $actionFactory;
38
    }
39
40
    /**
41
     * @param ManialinkInterface $manialink
42
     * @param Container $tabsFrame
43
     * @param ParentItem $rootItem
44
     * @param $openId
45
     *
46
     * @return Renderable
47
     */
48
    public function createTabsMenu(ManialinkInterface $manialink, Container $tabsFrame, ParentItem $rootItem, $openId)
49
    {
50
51
        $label = $this->uiFactory->createLabel("expansion_menu.menu");
52
        $label->setPosition(0, 0);
53
        $label->setSize(30, 5);
54
        $label->setTextSize(4);
55
        $label->setTextColor('FFFFFF');
56
        $label->setHorizontalAlign("center");
57
        $label->setTranslate(true);
58
        $tabsFrame->addChild($label);
59
60
        $posX = 28;
61
        foreach ($rootItem->getChilds() as $item) {
62
            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...
63
                $action = $this->actionFactory->createManialinkAction(
64
                    $manialink,
65
                    [$this, 'callbackItemClick'],
66
                    ['item' => $item, 'ml' => $manialink]
67
                );
68
                $label = $this->uiFactory->createLabel($item->getLabelId());
69
70
                $label->setPosition($posX, 0);
71
                $label->setSize(24, 5);
72
                $label->setAction($action);
73
                $label->setTextSize(3);
74
                $label->setTextColor('FFFFFF');
75
                $label->setHorizontalAlign(Label::CENTER);
76
                $label->setTranslate(true);
77
78
                if ($item->getId() == $openId) {
79
                    $underline = $this->uiFactory->createLine($posX - 13, -5);
80
                    $underline->to($posX + 13, -5);
81
                    $underline->setColor('FFFFFF');
82
                    $tabsFrame->addChild($underline);
83
                }
84
85
                $tabsFrame->addChild($label);
86
                $posX += 26;
87
            }
88
        }
89
90
        return $tabsFrame;
91
    }
92
}
93