Completed
Pull Request — master (#100)
by
unknown
02:35
created

WindowFactory::createContent()   B

Complexity

Conditions 2
Paths 2

Size

Total Lines 77
Code Lines 52

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 77
rs 8.9342
cc 2
eloc 52
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\uiInput;
11
use eXpansion\Framework\Gui\Components\uiLabel;
12
use eXpansion\Framework\Gui\Components\uiTextbox;
13
use eXpansion\Framework\Gui\Components\uiTooltip;
14
use eXpansion\Framework\Gui\Layouts\layoutLine;
15
use eXpansion\Framework\Gui\Layouts\layoutRow;
16
use eXpansion\Framework\Gui\Layouts\layoutScrollable;
17
use FML\Controls\Quad;
18
19
class WindowFactory extends BaseWindowFactory
20
{
21
22
    protected function createContent(ManialinkInterface $manialink)
23
    {
24
        parent::createContent($manialink);
25
26
        $tooltip = new uiTooltip();
27
        $manialink->addChild($tooltip);
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);
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);
49
50
        $line3 = new layoutRow(55, 0, [], 1);
51
52
        for ($x = 0; $x < 10; $x++) {
53
            $btn = new uiCheckbox('box'.$x, 'cb_'.$x);
54
            $btn->setPosition(0, 0);
55
            $tooltip->addTooltip($btn, "long description that should go over the bounding box".$x);
56
            $line3->addChild($btn);
57
        }
58
        $btn = new uiCheckbox('box11', 'cb_11');
59
        $btn->setPosition(20, 0);
60
        $line3->addChild($btn);
61
62
        $btn = new uiCheckbox('box11', 'cb_11');
63
        $btn->setPosition(50, 0);
64
        $line3->addChild($btn);
65
66
        $scrollable = new layoutScrollable($line3, 55, 30);
67
        $scrollable->setAxis(true, true);
68
        $manialink->addChild($scrollable);
69
70
71
        $row = new layoutRow(0, -10, [$line1, $line2], 0);
72
73
        $scrollable = new layoutScrollable($row, 40, 30);
74
        $scrollable->setAxis(true, true);
75
        $manialink->addChild($scrollable);
76
77
78
        $dropdown = new uiDropdown("dropdown", ["option1" => 1, "option2" => 2]);
79
        $dropdown->setPosition(97, 0);
80
        $tooltip->addTooltip($dropdown, "test");
81
        $manialink->addChild($dropdown);
82
83
        $dropdown = new uiDropdown("style", ["tech" => "tech", "fullspeed" => "fullspeed", "speedtech" => "speedtech"]);
84
        $dropdown->setPosition(130, 0);
85
        $manialink->addChild($dropdown);
86
87
88
        $input = new uiInput("input1", "test text", 30, "Password");
89
        $input->setPosition(130, -20);
90
        $tooltip->addTooltip($input, "test");
91
        $manialink->addChild($input);
92
93
        $input = new uiTextbox("input2", "test\ntest2\ntest3\nest4\ntest5", 5, 30);
94
        $input->setPosition(130, -30);
95
        $tooltip->addTooltip($input, "test2");
96
        $manialink->addChild($input);
97
98
    }
99
100
101
    public function ok($login, $params, $args)
0 ignored issues
show
Unused Code introduced by
The parameter $login is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $params is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $args is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
102
    {
103
        // do nothing at the moment
104
    }
105
106
}
107