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

WindowFrameFactory   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 114
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 8

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
c 1
b 0
f 0
lcom 1
cbo 8
dl 0
loc 114
ccs 0
cts 40
cp 0
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 12 1
A build() 0 52 1
A setManialinkInterface() 0 4 1
A setCloseAction() 0 4 1
1
<?php
2
3
namespace eXpansion\Bundle\ImmersiveWindows\Model\Gui\Factory;
4
5
use eXpansion\Bundle\Menu\DataProviders\MenuItemProvider;
6
use eXpansion\Bundle\Menu\Gui\MenuTabsFactory;
7
use eXpansion\Framework\Core\Model\Gui\Factory\WindowFrameFactory as OriginalWindowFrameFactory;
8
use eXpansion\Framework\Core\Model\Gui\ManialinkInterface;
9
use eXpansion\Framework\Core\Model\Gui\ManiaScriptFactory;
10
use eXpansion\Framework\Core\Model\Gui\WindowFrameFactoryInterface;
11
use eXpansion\Framework\Gui\Components\uiButton;
12
use eXpansion\Framework\Gui\Ui\Factory;
13
use FML\Controls\Frame;
14
use FML\Controls\Label;
15
use FML\Controls\Quad;
16
use FML\ManiaLink;
17
18
/**
19
 * Class WindowFrameFactory
20
 *
21
 * @author    de Cramer Oliver<[email protected]>
22
 * @copyright 2017 Smile
23
 * @package eXpansion\Bundle\ImmersiveWindows\Model\Gui\Factory
24
 */
25
class WindowFrameFactory extends OriginalWindowFrameFactory implements WindowFrameFactoryInterface
26
{
27
    /** @var MenuTabsFactory */
28
    protected $menuTabsFactory;
29
30
    /** @var MenuItemProvider */
31
    protected $menuItemProvider;
32
    /**
33
     * @var ManiaScriptFactory
34
     */
35
    protected $maniaScriptFactory;
36
    /**
37
     * @var ManialinkInterface
38
     */
39
    protected $manialinkInterface;
40
    /**
41
     * @var Factory
42
     */
43
    protected $uiFactory;
44
45
    /** @var  uiButton */
46
    private $closeButton;
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
47
48
    /**
49
     * WindowFrameFactory constructor.
50
     *
51
     * @param ManiaScriptFactory $maniaScriptFactory
52
     * @param MenuTabsFactory $menuTabsFactory
53
     * @param MenuItemProvider $menuItemProvider
54
     * @param Factory $uiFactory
55
     */
56
    public function __construct(
57
        ManiaScriptFactory $maniaScriptFactory,
58
        MenuTabsFactory $menuTabsFactory,
59
        MenuItemProvider $menuItemProvider,
60
        Factory $uiFactory
61
    ) {
62
        parent::__construct($maniaScriptFactory);
63
        $this->maniaScriptFactory = $maniaScriptFactory;
64
        $this->menuTabsFactory = $menuTabsFactory;
65
        $this->menuItemProvider = $menuItemProvider;
66
        $this->uiFactory = $uiFactory;
67
    }
68
69
    /**
70
     * @inheritdoc
71
     */
72
    public function build(
73
        ManiaLink $manialink,
74
        Frame $mainFrame,
75
        $name,
76
        $sizeX,
77
        $sizeY
78
    ) {
79
        // Creating sub frame to keep all the pieces together. Position needs to be top left corner.
80
        $frame = new Frame();
81
        $frame->setPosition(-160 - $mainFrame->getX(), 90 - $mainFrame->getY());
82
83
84
        // Creating the tabs.
85
        $mainFrame->addChild(
86
            $this->menuTabsFactory->createTabsMenu(
0 ignored issues
show
Documentation introduced by
$this->menuTabsFactory->...tItem(), 'admin/admin') is of type object<FML\Types\Container>, but the function expects a object<FML\Types\Renderable>.

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...
87
                $this->manialinkInterface,
88
                $frame,
89
                $this->menuItemProvider->getRootItem(),
0 ignored issues
show
Documentation introduced by
$this->menuItemProvider->getRootItem() is of type object<eXpansion\Bundle\...enu\ItemInterface>|null, but the function expects a object<eXpansion\Bundle\...\Model\Menu\ParentItem>.

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...
90
                'admin/admin'
91
            )
92
        );
93
        $mainFrame->addChild($frame);
94
95
        $closeButton = $this->uiFactory->createButton('Close', uiButton::TYPE_DECORATED);
96
        $closeButton->setBorderColor(uiButton::COLOR_WARNING)->setFocusColor(uiButton::COLOR_WARNING);
97
        $closeButton->setPosition(300, -20);
98
        $this->closeButton = $closeButton;
99
        $frame->addChild($closeButton);
100
101
102
        /*
103
         * Adding background frame
104
         */
105
        $bgFrame = Frame::create("background");
106
        $quad = new Quad();
107
        $quad->addClass("bg")
108
            ->setId("mainBg")
109
            ->setPosition(0, 0)
110
            ->setSize(322, 182);
111
        $quad->setAlign("left", "top")
112
            ->setStyles("Bgs1", "BgDialogBlur");
113
        $bgFrame->addChild($quad);
114
115
        $frame->addChild($bgFrame);
116
117
118
119
120
121
        $manialink->addChild($this->maniaScriptFactory->createScript(['']));
122
123
    }
124
125
    /**
126
     * @param ManialinkInterface $manialinkInterface
127
     */
128
    public function setManialinkInterface(ManialinkInterface $manialinkInterface)
129
    {
130
        $this->manialinkInterface = $manialinkInterface;
131
    }
132
133
    public function setCloseAction($action)
134
    {
135
        $this->closeButton->setAction($action);
136
    }
137
138
}
139