Completed
Pull Request — master (#270)
by
unknown
03:25
created

Label::__construct()   B

Complexity

Conditions 4
Paths 4

Size

Total Lines 33
Code Lines 28

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 33
rs 8.5806
c 0
b 0
f 0
cc 4
eloc 28
nc 4
nop 3
1
<?php
2
3
namespace eXpansion\Framework\Gui\Components;
4
5
use DOMDocument;
6
use DOMElement;
7
use FML\Controls\Label as FMLLabel;
8
9
class Label extends FMLLabel
10
{
11
12
    const TYPE_NORMAL = "normal";
13
    const TYPE_TITLE = "title";
14
    const TYPE_HEADER = "header";
15
16
    /**
17
     * Label constructor.
18
     * @param string      $text
19
     * @param string      $type
20
     * @param string|null $controlId
21
     */
22
    public function __construct($text = "", $type = self::TYPE_NORMAL, $controlId = null)
23
    {
24
        parent::__construct($controlId);
25
        $this->setText($text)
26
            ->setAreaColor("0000")
27
            ->setAreaFocusColor('0000')
28
            ->setScriptEvents(true)
29
            ->setTextColor('fff')
30
            ->setWidth(30);
31
32
        switch ($type) {
33
            case self::TYPE_NORMAL:
34
                $this->setTextSize(1)
35
                    ->setHeight(5)
36
                    ->setTextFont('BiryaniDemiBold');
37
                break;
38
            case self::TYPE_TITLE:
39
                $this->setTextSize(1)
40
                    ->setHeight(5)
41
                    ->setTextFont('RajdhaniMono');
42
43
                break;
44
            case self::TYPE_HEADER:
45
                $this->setTextSize(1)
46
                    ->setHeight(5)
47
                    ->setTextFont('BiryaniDemiBold');
48
                break;
49
            default:
50
                $this->setTextSize(1)
51
                    ->setHeight(5);
52
                break;
53
        }
54
    }
55
56
    /**
57
     * @param DOMDocument $domDocument
58
     * @return DOMElement
59
     */
60
61
    public function render(\DOMDocument $domDocument)
62
    {
63
        if ($this->getTranslate() === true) {
64
            if ($this->getText()) {
65
                $this->setText(null);
66
            }
67
        }
68
69
        return parent::render($domDocument);
70
    }
71
72
    /**
73
     * @param boolean $translate
74
     * @return Label
75
     */
76
    public function setTranslate($translate)
77
    {
78
        if ($translate) {
79
            $text = $this->getText();
80
            if ($text) {
81
                parent::setText(null);
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (setText() instead of setTranslate()). Are you sure this is correct? If so, you might want to change this to $this->setText().

This check looks for a call to a parent method whose name is different than the method from which it is called.

Consider the following code:

class Daddy
{
    protected function getFirstName()
    {
        return "Eidur";
    }

    protected function getSurName()
    {
        return "Gudjohnsen";
    }
}

class Son
{
    public function getFirstName()
    {
        return parent::getSurname();
    }
}

The getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
82
                parent::setTextId($text);
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (setTextId() instead of setTranslate()). Are you sure this is correct? If so, you might want to change this to $this->setTextId().

This check looks for a call to a parent method whose name is different than the method from which it is called.

Consider the following code:

class Daddy
{
    protected function getFirstName()
    {
        return "Eidur";
    }

    protected function getSurName()
    {
        return "Gudjohnsen";
    }
}

class Son
{
    public function getFirstName()
    {
        return parent::getSurname();
    }
}

The getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
83
            }
84
        }
85
86
        parent::setTranslate($translate);
87
88
        return $this;
89
    }
90
91
    public function setTextId($textId)
92
    {
93
        $this->setText($textId);
94
        $this->setTranslate(true);
95
96
        return $this;
97
    }
98
99
}
100