Completed
Pull Request — master (#130)
by De Cramer
07:55
created

Window::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 15
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 15
ccs 4
cts 4
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 12
nc 1
nop 8
crap 1

How to fix   Many Parameters   

Many Parameters

Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.

There are several approaches to avoid long parameter lists:

1
<?php
2
3
namespace eXpansion\Framework\Core\Model\Gui;
4
5
use eXpansion\Framework\Core\Exceptions\Gui\MissingCloseActionException;
6
use eXpansion\Framework\Core\Helpers\Translations;
7
use eXpansion\Framework\Core\Model\Gui\Factory\WindowFrameFactory;
8
use eXpansion\Framework\Core\Model\UserGroups\Group;
9
use FML\Controls\Control;
10
use FML\Types\Container;
11
12
class Window extends Widget implements Container
13
{
14
    /** @var Control  */
15
    protected $closeButton;
16
17
    public function __construct(
18 3
        Group $group,
19
        Translations $translationHelper,
20
        WindowFrameFactory $windowFrameFactory,
21
        $name,
22
        $sizeX,
23
        $sizeY,
24
        $posX = null,
25
        $posY = null
26
    ) {
27
        parent::__construct($group, $translationHelper, $name, $sizeX, $sizeY, $posX, $posY);
28 3
29
        $this->translationHelper = $translationHelper;
30 3
        $this->closeButton = $windowFrameFactory->build($this->manialink, $this->windowFrame, $name, $sizeY, $sizeY);
31 3
    }
32
33 3
    /**
34 3
     * Set action to close the window.
35 3
     *
36 3
     * @param $actionId
37
     */
38
    public function setCloseAction($actionId)
39 3
    {
40 3
        $this->closeButton->setDataAttributes(['action' => $actionId]);
41 3
    }
42
43
    public function getXml()
44 3
    {
45 3
        if (empty($this->closeButton->getDataAttribute('action'))) {
46 3
            throw new MissingCloseActionException("Close action is missing for window. Check if you are using the proper factory.");
47 3
        }
48 3
49 3
        return parent::getXml();
50 3
    }
51
}
52