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

MenuTabsFactory   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 72
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 7

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
B createTabsMenu() 0 43 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
        $label = $this->uiFactory->createLabel("expansion_menu.menu");
51
        $label->setPosition(0, 0);
52
        $label->setSize(30, 5);
53
        $label->setTextSize(4);
54
        $label->setTextColor('FFFFFF');
55
        $label->setHorizontalAlign("center");
56
        $label->setTranslate(true);
57
        $tabsFrame->addChild($label);
58
59
        $posX = 28;
60
        foreach ($rootItem->getChilds() as $item) {
61
            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...
62
                $action = $this->actionFactory->createManialinkAction(
63
                    $manialink,
64
                    [$this, 'callbackItemClick'],
65
                    ['item' => $item, 'ml' => $manialink]
66
                );
67
                $label = $this->uiFactory->createLabel($item->getLabelId());
68
69
                $label->setPosition($posX, 0);
70
                $label->setSize(24, 5);
71
                $label->setAction($action);
72
                $label->setTextSize(3);
73
                $label->setTextColor('FFFFFF');
74
                $label->setHorizontalAlign(Label::CENTER);
75
                $label->setTranslate(true);
76
77
                if ($item->getId() == $openId) {
78
                    $underline = $this->uiFactory->createLine($posX - 13, -5);
79
                    $underline->to($posX + 13, -5);
80
                    $underline->setColor('FFFFFF');
81
                    $tabsFrame->addChild($underline);
82
                }
83
84
                $tabsFrame->addChild($label);
85
                $posX += 26;
86
            }
87
        }
88
89
        return $tabsFrame;
90
    }
91
}
92