Completed
Pull Request — master (#95)
by
unknown
03:41
created

WindowFactory::createContent()   B

Complexity

Conditions 2
Paths 2

Size

Total Lines 76
Code Lines 49

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 76
rs 8.9667
cc 2
eloc 49
nc 2
nop 1

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
namespace eXpansion\Bundle\Acme\Plugins\Gui;
4
5
use eXpansion\Framework\Core\Model\Gui\ManialinkInterface;
6
use eXpansion\Framework\Core\Plugins\Gui\WindowFactory as BaseWindowFactory;
7
use eXpansion\Framework\Gui\Components\uiButton;
8
use eXpansion\Framework\Gui\Components\uiCheckbox;
9
use eXpansion\Framework\Gui\Components\uiDropdown;
10
use eXpansion\Framework\Gui\Components\uiLabel;
11
use eXpansion\Framework\Gui\Components\uiLine;
12
use eXpansion\Framework\Gui\Components\uiTooltip;
13
use eXpansion\Framework\Gui\Layouts\layoutLine;
14
use eXpansion\Framework\Gui\Layouts\layoutRow;
15
use FML\Controls\Quad;
16
use FML\Script\Features\Tooltip;
17
18
class WindowFactory extends BaseWindowFactory
19
{
20
21
    protected function createContent(ManialinkInterface $manialink)
22
    {
23
        parent::createContent($manialink);
24
25
        $tooltip = new uiTooltip();
26
        $manialink->addChild($tooltip);
27
28
29
        $label = new uiLabel("Test", uiLabel::TYPE_NORMAL);
30
        $tooltip->addTooltip($label, "tooltip test");
31
32
        $manialink->addChild($label);
33
34
        $checkbox = new uiCheckbox("test checkbox 1", "checkbox1");
35
        $tooltip->addTooltip($checkbox, "testing 123");
36
37
        $checkbox2 = new uiCheckbox("test checkbox 2", "checkbox2");
38
        $tooltip->addTooltip($checkbox2, "testing");
39
        $line1 = new layoutRow(0, 0, [$checkbox, $checkbox2], 0);
0 ignored issues
show
Documentation introduced by
array($checkbox, $checkbox2) is of type array<integer,object<eXp...ponents\\uiCheckbox>"}>, but the function expects a array<integer,object<FML\Controls\Control>>.

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...
40
41
        $ok = new uiButton("Apply", uiButton::TYPE_DECORATED);
42
        $tooltip->addTooltip($ok, "ridicolously long description text is here!");
43
        $ok->setAction($this->actionFactory->createManialinkAction($manialink, [$this, 'ok'], ["ok" => "ok"]));
44
45
        $cancel = new uiButton("Cancel");
46
        $cancel->setAction($this->actionFactory->createManialinkAction($manialink, [$this, 'ok'], ["ok" => "cancel"]));
47
48
        $line2 = new layoutLine(0, 0, [$ok, $cancel], 1);
0 ignored issues
show
Documentation introduced by
array($ok, $cancel) is of type array<integer,object<eXp...omponents\\uiButton>"}>, but the function expects a array<integer,object<FML\Controls\Control>>.

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...
49
50
51
        $line3 = new layoutRow(55, 0, [], 1);
52
53
        for ($x = 0; $x < 10; $x++) {
54
            $btn = new uiCheckbox('box'.$x, 'cb_'.$x);
55
            $line3->addChild($btn);
56
        }
57
58
        $manialink->addChild($line3);
59
60
        $row = new layoutRow(0, -10, [$line1, $line2], 0);
0 ignored issues
show
Documentation introduced by
array($line1, $line2) is of type array<integer,object<eXp...Layouts\\layoutLine>"}>, but the function expects a array<integer,object<FML\Controls\Control>>.

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
        $manialink->addChild($row);
62
63
64
        $dropdown = new uiDropdown("dropdown", ["option1" => 1, "option2" => 2]);
65
        $dropdown->setPosition(0, -30);
66
        $manialink->addChild($dropdown);
67
68
        $dropdown = new uiDropdown("style", ["tech" => "tech", "fullspeed" => "fullspeed", "speedtech" => "speedtech"]);
69
        $dropdown->setPosition(40, -30);
70
        $manialink->addChild($dropdown);
71
72
73
        $quad = new Quad();
74
        $quad->setPosition(20, -40)
75
            ->setAlign("center", "center")
76
            ->setSize(2,2)
77
            ->setBackgroundColor("0f0");
78
        $manialink->addChild($quad);
79
80
        $quad = new Quad();
81
        $quad->setPosition(40, -20)
82
            ->setAlign("center", "center")
83
            ->setSize(2,2)
84
            ->setBackgroundColor("0ff");
85
        $manialink->addChild($quad);
86
87
        $line = new uiLine(20.1, -40);
88
        $line->to(20.1, 0);
89
        $manialink->addChild($line);
90
91
        $line = new uiLine(20, -40);
92
        $line->to(40, -20);
93
94
        $manialink->addChild($line);
95
96
    }
97
98
99
    public function ok($login, $params, $args)
100
    {
101
        var_dump($login);
0 ignored issues
show
Security Debugging Code introduced by
var_dump($login); looks like debug code. Are you sure you do not want to remove it? This might expose sensitive data.
Loading history...
102
        print_r($params);
103
        print_r($args);
104
105
106
    }
107
108
109
}
110