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

ServerInformationLineFactory::create()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 24

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
dl 0
loc 24
ccs 0
cts 20
cp 0
rs 9.536
c 0
b 0
f 0
cc 3
nc 4
nop 2
crap 12
1
<?php
2
3
namespace eXpansion\Bundle\ServerInformation\Ui\Factory;
4
5
6
use eXpansion\Framework\Gui\Components\Label;
7
use eXpansion\Framework\Gui\Ui\Factory;
8
use FML\Controls\Frame;
9
10
class ServerInformationLineFactory
11
{
12
    /** @var Factory */
13
    protected $factory;
14
15
    /** @var float */
16
    protected $titleWidth;
17
18
    /** @var float */
19
    protected $dataWidth;
20
21
    /**
22
     * ServerInformationLineFactory constructor.
23
     * @param Factory $factory
24
     * @param string $class
0 ignored issues
show
Bug introduced by
There is no parameter named $class. 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...
25
     * @param float $titleWidth
26
     * @param float $dataWidth
27
     */
28
    public function __construct(Factory $factory, float $titleWidth, float $dataWidth)
29
    {
30
        $this->factory = $factory;
31
        $this->titleWidth = $titleWidth;
32
        $this->dataWidth = $dataWidth;
33
    }
34
35
36
    /**
37
     * Create a server information line.
38
     *
39
     * @param $title
40
     * @param $data
41
     * @return Frame
42
     */
43
    public function create($title, $data)
44
    {
45
        if (!is_array($data)) {
46
            $data = [$data];
47
        }
48
        $nbLine = count($data);
49
50
        $frame = new Frame();
51
        $frame->setWidth($this->titleWidth + $this->dataWidth + 1);
52
        $frame->setHeight(3.5 * $nbLine);
53
54
        $frame->addChild($this->factory->createLabel($title, Label::TYPE_TITLE)->setWidth($this->titleWidth)->setTranslate(true));
55
56
        foreach ($data as $i => $dataLine) {
57
            $frame->addChild(
58
                $this->factory->createLabel($dataLine, Label::TYPE_NORMAL)
59
                    ->setWidth($this->dataWidth)
60
                    ->setX($this->titleWidth + 1)
61
                    ->setY(-3.5 * $i)
62
            );
63
        }
64
65
        return $frame;
66
    }
67
}
68