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

WindowFrameFactory::build()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 55
Code Lines 39

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 55
rs 9.7692
c 1
b 0
f 0
ccs 0
cts 34
cp 0
cc 1
eloc 39
nc 1
nop 5
crap 2

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\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 FML\Controls\Frame;
11
use FML\Controls\Label;
12
use FML\Controls\Quad;
13
use FML\ManiaLink;
14
15
/**
16
 * Class WindowFrameFactory
17
 *
18
 * @author    de Cramer Oliver<[email protected]>
19
 * @copyright 2017 Smile
20
 * @package eXpansion\Bundle\ImmersiveWindows\Model\Gui\Factory
21
 */
22
class WindowFrameFactory extends OriginalWindowFrameFactory
23
{
24
    /** @var MenuTabsFactory */
25
    protected $menuTabsFactory;
26
27
    /** @var MenuItemProvider */
28
    protected $menuItemProvider;
29
    /**
30
     * @var ManiaScriptFactory
31
     */
32
    protected $maniaScriptFactory;
33
    /**
34
     * @var ManialinkInterface
35
     */
36
    protected $manialinkInterface;
37
38
    /**
39
     * WindowFrameFactory constructor.
40
     *
41
     * @param ManiaScriptFactory $maniaScriptFactory
42
     * @param MenuTabsFactory $menuTabsFactory
43
     * @param MenuItemProvider $menuItemProvider
44
     * @param ManialinkInterface $manialink
0 ignored issues
show
Bug introduced by
There is no parameter named $manialink. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
45
     */
46
    public function __construct(
47
        ManiaScriptFactory $maniaScriptFactory,
48
        MenuTabsFactory $menuTabsFactory,
49
        MenuItemProvider $menuItemProvider
50
    ) {
51
        parent::__construct($maniaScriptFactory);
52
        $this->maniaScriptFactory = $maniaScriptFactory;
53
        $this->menuTabsFactory = $menuTabsFactory;
54
        $this->menuItemProvider = $menuItemProvider;
55
56
    }
57
58
    /**
59
     * @inheritdoc
60
     */
61
    public function build(
62
        ManiaLink $manialink,
63
        Frame $mainFrame,
64
        $name,
65
        $sizeX,
66
        $sizeY
67
    ) {
68
        // Creating sub frame to keep all the pieces together. Position needs to be top left corner.
69
        $frame = new Frame();
70
71
        $frame->setPosition(-160 - $mainFrame->getX(), 90 - $mainFrame->getY());
72
        $mainFrame->addChild($frame);
73
74
        // Creating the tabs.
75
        $mainFrame->addChild(
76
            $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...
77
                $this->manialinkInterface,
78
                $frame,
79
                $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...
80
                'admin/admin'
81
            )
82
        );
83
84
        $closeButton = new Label('Close');
85
        $closeButton->setSize(6, 6)
86
            ->setPosition(0, 0)
87
            ->setAlign(Label::CENTER, Label::CENTER2)
88
            ->setText("✖")
89
            ->setTextColor('fff')
90
            ->setTextSize(2)
91
            ->setTextFont('OswaldMono')
92
            ->setScriptEvents(true)
93
            ->setAreaColor("FFF")
94
            ->setAreaFocusColor('f22');
95
        $frame->addChild($closeButton);
96
97
        /*
98
         * Adding background frame
99
         */
100
        $bgFrame = Frame::create("background");
101
102
        $quad = new Quad();
103
        $quad->addClass("bg")
104
            ->setId("mainBg")
105
            ->setPosition(0, 0)
106
            ->setSize(322, 182);
107
        $quad->setAlign("left", "top")
108
            ->setStyles("Bgs1", "BgDialogBlur");
109
        $bgFrame->addChild($quad);
110
111
        $frame->addChild($bgFrame);
112
        $manialink->addChild($this->maniaScriptFactory->createScript(['']));
113
114
        return $closeButton;
115
    }
116
117
    /**
118
     * @param ManialinkInterface $manialinkInterface
119
     */
120
    public function setManialinkInterface(ManialinkInterface $manialinkInterface)
121
    {
122
        $this->manialinkInterface = $manialinkInterface;
123
    }
124
125
126
}
127