Completed
Pull Request — master (#404)
by De Cramer
03:04
created

ServerInfoWindow::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 15

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 15
ccs 0
cts 14
cp 0
rs 9.7666
c 0
b 0
f 0
cc 1
nc 1
nop 8
crap 2

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\Bundle\ServerInformation\Plugins\Gui;
4
5
use eXpansion\Bundle\ServerInformation\Services\ServerInformationInterface;
6
use eXpansion\Framework\Core\Model\Gui\ManialinkInterface;
7
use eXpansion\Framework\Core\Model\Gui\WindowFactoryContext;
8
use eXpansion\Framework\Core\Plugins\Gui\WindowFactory;
9
use eXpansion\Framework\Gui\Ui\Factory;
10
use FML\Controls\Frame;
11
12
class ServerInfoWindow extends WindowFactory
13
{
14
    /** @var ServerInformationInterface[] */
15
    protected $serverInfos;
16
17
    /** @var Factory */
18
    protected $factory;
19
20
    public function __construct(
21
        $name,
22
        $sizeX,
23
        $sizeY,
24
        $posX = null,
25
        $posY = null,
26
        WindowFactoryContext $context,
27
        $serverInfos = [],
28
        Factory $factory
29
    ) {
30
        parent::__construct($name, $sizeX, $sizeY, $posX, $posY, $context);
31
32
        $this->serverInfos = $serverInfos;
33
        $this->factory = $factory;
34
    }
35
36
    /**
37
     * @param ManialinkInterface $manialink
38
     */
39
    protected function updateContent(ManialinkInterface $manialink)
40
    {
41
        parent::updateContent($manialink);
42
43
        /** @var Frame $contentFrame */
44
        $contentFrame = $manialink->getContentFrame();
45
        $contentFrame->removeAllChildren();
46
47
        $login = $manialink->getUserGroup()->getLogins()[0];
48
49
        $elements = [];
50
        foreach ($this->serverInfos as $serverInfo) {
51
            if ($serverInfo->canShow($login)) {
52
                $elements[] = $serverInfo->getInformation($login);
53
            }
54
        }
55
56
        $contentFrame->addChild($this->factory->createLayoutRow(0, 0, $elements));
57
    }
58
59
60
}