WidgetBackground::setPosition()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 7
ccs 0
cts 6
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
crap 2
1
<?php
2
3
namespace eXpansion\Framework\Gui\Builders;
4
5
use FML\Controls\Quad;
6
use FML\Types\Renderable;
7
8
/**
9
 * Class WidgetBackground
10
 * @package eXpansion\Framework\Gui\Builders
11
 */
12
class WidgetBackground implements Renderable
13
{
14
    /**
15
     * @var float
16
     */
17
    protected $posX = 0;
18
    /**
19
     * @var float
20
     */
21
    protected $posY = 0;
22
    /**
23
     * @var float
24
     */
25
    protected $posZ = 0;
26
    /**
27
     * @var string
28
     */
29
    protected $id;
30
    /**
31
     * @var float
32
     */
33
    protected $width;
34
    /**
35
     * @var float
36
     */
37
    protected $height;
38
    /**
39
     * @var string
40
     */
41
    protected $action;
42
43
    /**
44
     * WidgetBackground constructor.
45
     * @param float $width
46
     * @param float $height
47
     */
48
    public function __construct($width, $height)
49
    {
50
        $this->width = $width;
51
        $this->height = $height;
52
    }
53
54
    /**
55
     * Render the XML element
56
     *
57
     * @param \DOMDocument $domDocument DOMDocument for which the XML element should be rendered
58
     * @return \DOMElement
59
     */
60
    public function render(\DOMDocument $domDocument)
61
    {
62
        $quad = Quad::create();
63
        $quad->setPosition($this->posX, $this->posY)->setZ($this->posZ)
64
            ->setOpacity(0.4)->setBackgroundColor("000")
65
            ->setSize($this->width, $this->height);
66
        if ($this->id) {
67
            $quad->setId($this->id);
68
        }
69
        if ($this->action) {
70
            $quad->setAction($this->action)->setFocusBackgroundColor("999");
71
        }
72
73
        return $quad->render($domDocument);
74
    }
75
76
    /**
77
     * @return int
78
     */
79
    public function getPosX(): int
80
    {
81
        return $this->posX;
82
    }
83
84
    /**
85
     * @param int $posX
86
     * @return WidgetBackground
87
     */
88
    public function setPosX(int $posX)
89
    {
90
        $this->posX = $posX;
0 ignored issues
show
Documentation Bug introduced by
The property $posX was declared of type double, but $posX is of type integer. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
91
92
        return $this;
93
    }
94
95
    /**
96
     * @param int $posX
97
     * @param int $posY
98
     * @return WidgetBackground
99
     */
100
    public function setPosition(int $posX, int $posY)
101
    {
102
        $this->posX = $posX;
0 ignored issues
show
Documentation Bug introduced by
The property $posX was declared of type double, but $posX is of type integer. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
103
        $this->posY = $posY;
0 ignored issues
show
Documentation Bug introduced by
The property $posY was declared of type double, but $posY is of type integer. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
104
105
        return $this;
106
    }
107
108
    /**
109
     * @return int
110
     */
111
    public function getPosY(): int
112
    {
113
        return $this->posY;
114
    }
115
116
    /**
117
     * @param int $posY
118
     * @return WidgetBackground
119
     */
120
    public function setPosY(int $posY)
121
    {
122
        $this->posY = $posY;
0 ignored issues
show
Documentation Bug introduced by
The property $posY was declared of type double, but $posY is of type integer. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
123
124
        return $this;
125
    }
126
127
    /**
128
     * @return int
129
     */
130
    public function getPosZ(): int
131
    {
132
        return $this->posZ;
133
    }
134
135
    /**
136
     * @param int $posZ
137
     * @return WidgetBackground
138
     */
139
    public function setPosZ(int $posZ)
140
    {
141
        $this->posZ = $posZ;
0 ignored issues
show
Documentation Bug introduced by
The property $posZ was declared of type double, but $posZ is of type integer. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
142
143
        return $this;
144
    }
145
146
    /**
147
     * @return double
148
     */
149
    public function getWidth()
150
    {
151
        return $this->width;
152
    }
153
154
    /**
155
     * @param mixed $width
156
     * @return WidgetBackground
157
     */
158
    public function setWidth($width)
159
    {
160
        $this->width = $width;
161
162
        return $this;
163
    }
164
165
    /**
166
     * @return double
167
     */
168
    public function getHeight()
169
    {
170
        return $this->height;
171
    }
172
173
    /**
174
     * @param mixed $height
175
     * @return WidgetBackground
176
     */
177
    public function setHeight($height)
178
    {
179
        $this->height = $height;
180
181
        return $this;
182
    }
183
184
    /**
185
     * @return string
186
     */
187
    public function getAction()
188
    {
189
        return $this->action;
190
    }
191
192
    /**
193
     * @param mixed $action
194
     * @return WidgetBackground
195
     */
196
    public function setAction($action)
197
    {
198
        $this->action = $action;
199
200
        return $this;
201
    }
202
203
    /**
204
     * @return string
205
     */
206
    public function getId()
207
    {
208
        return $this->id;
209
    }
210
211
    /**
212
     * @param mixed $id
213
     * @return WidgetBackground
214
     */
215
    public function setId($id)
216
    {
217
        $this->id = $id;
218
219
        return $this;
220
    }
221
222
223
}
224