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

MenuTabsFactory   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 78
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 7

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
c 1
b 0
f 0
lcom 1
cbo 7
dl 0
loc 78
rs 10

2 Methods

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