HighchartsSubtitle::toArray()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 35

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 35
rs 9.36
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
/**
4
 * This file is part of the highcharts-bundle package.
5
 *
6
 * (c) 2017 WEBEWEB
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace WBW\Bundle\HighchartsBundle\API\Chart;
13
14
use JsonSerializable;
15
use WBW\Library\Core\Utility\Argument\ArrayUtility;
16
17
/**
18
 * Highcharts subtitle.
19
 *
20
 * @author webeweb <https://github.com/webeweb/>
21
 * @package WBW\Bundle\HighchartsBundle\API\Chart
22
 * @version 5.0.14
23
 * @final
24
 */
25
final class HighchartsSubtitle implements JsonSerializable {
26
27
    /**
28
     * Align.
29
     *
30
     * @var string
31
     * @since 2.0
32
     */
33
    private $align = "center";
34
35
    /**
36
     * Floating.
37
     *
38
     * @var boolean
39
     * @since 2.1
40
     */
41
    private $floating = false;
42
43
    /**
44
     * Style.
45
     *
46
     * @var array
47
     */
48
    private $style = ["color" => "#666666"];
49
50
    /**
51
     * Text.
52
     *
53
     * @var string
54
     */
55
    private $text;
56
57
    /**
58
     * Use HTML.
59
     *
60
     * @var boolean
61
     */
62
    private $useHTML = false;
63
64
    /**
65
     * Vertical align.
66
     *
67
     * @var string
68
     * @since 2.1
69
     */
70
    private $verticalAlign;
71
72
    /**
73
     * Width adjust.
74
     *
75
     * @var integer
76
     * @since 4.2.5
77
     */
78
    private $widthAdjust = -44;
79
80
    /**
81
     * X.
82
     *
83
     * @var integer
84
     * @since 2.0
85
     */
86
    private $x = 0;
87
88
    /**
89
     * Y.
90
     *
91
     * @var integer
92
     * @since 2.0
93
     */
94
    private $y;
95
96
    /**
97
     * Constructor.
98
     *
99
     * @param boolean $ignoreDefaultValues Ignore the default values.
100
     */
101
    public function __construct($ignoreDefaultValues = true) {
102
        if (true === $ignoreDefaultValues) {
103
            $this->clear();
104
        }
105
    }
106
107
    /**
108
     * Clear.
109
     *
110
     * @return void
111
     */
112
    public function clear() {
113
114
        // Clear the align.
115
        $this->align = null;
116
117
        // Clear the floating.
118
        $this->floating = null;
119
120
        // Clear the style.
121
        $this->style = null;
0 ignored issues
show
Documentation Bug introduced by
It seems like null of type null is incompatible with the declared type array of property $style.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
122
123
        // Clear the text.
124
        $this->text = null;
125
126
        // Clear the use HTML.
127
        $this->useHTML = null;
128
129
        // Clear the vertical align.
130
        $this->verticalAlign = null;
131
132
        // Clear the width adjust.
133
        $this->widthAdjust = null;
134
135
        // Clear the x.
136
        $this->x = null;
137
138
        // Clear the y.
139
        $this->y = null;
140
    }
141
142
    /**
143
     * Get the align.
144
     *
145
     * @return string Returns the align.
146
     */
147
    public function getAlign() {
148
        return $this->align;
149
    }
150
151
    /**
152
     * Get the floating.
153
     *
154
     * @return boolean Returns the floating.
155
     */
156
    public function getFloating() {
157
        return $this->floating;
158
    }
159
160
    /**
161
     * Get the style.
162
     *
163
     * @return array Returns the style.
164
     */
165
    public function getStyle() {
166
        return $this->style;
167
    }
168
169
    /**
170
     * Get the text.
171
     *
172
     * @return string Returns the text.
173
     */
174
    public function getText() {
175
        return $this->text;
176
    }
177
178
    /**
179
     * Get the use HTML.
180
     *
181
     * @return boolean Returns the use HTML.
182
     */
183
    public function getUseHTML() {
184
        return $this->useHTML;
185
    }
186
187
    /**
188
     * Get the vertical align.
189
     *
190
     * @return string Returns the vertical align.
191
     */
192
    public function getVerticalAlign() {
193
        return $this->verticalAlign;
194
    }
195
196
    /**
197
     * Get the width adjust.
198
     *
199
     * @return integer Returns the width adjust.
200
     */
201
    public function getWidthAdjust() {
202
        return $this->widthAdjust;
203
    }
204
205
    /**
206
     * Get the x.
207
     *
208
     * @return integer Returns the x.
209
     */
210
    public function getX() {
211
        return $this->x;
212
    }
213
214
    /**
215
     * Get the y.
216
     *
217
     * @return integer Returns the y.
218
     */
219
    public function getY() {
220
        return $this->y;
221
    }
222
223
    /**
224
     * Serialize this instance.
225
     *
226
     * @return array Returns an array representing this instance.
227
     */
228
    public function jsonSerialize() {
229
        return $this->toArray();
230
    }
231
232
    /**
233
     * Set the align.
234
     *
235
     * @param string $align The align.
236
     * @return \WBW\Bundle\HighchartsBundle\API\Chart\HighchartsSubtitle Returns the highcharts subtitle.
237
     */
238
    public function setAlign($align) {
239
        switch ($align) {
240
            case "center":
241
            case "left":
242
            case "right":
243
            $this->align = $align;
244
            break;
245
        }
246
        return $this;
247
    }
248
249
    /**
250
     * Set the floating.
251
     *
252
     * @param boolean $floating The floating.
253
     * @return \WBW\Bundle\HighchartsBundle\API\Chart\HighchartsSubtitle Returns the highcharts subtitle.
254
     */
255
    public function setFloating($floating) {
256
        $this->floating = $floating;
257
        return $this;
258
    }
259
260
    /**
261
     * Set the style.
262
     *
263
     * @param array $style The style.
264
     * @return \WBW\Bundle\HighchartsBundle\API\Chart\HighchartsSubtitle Returns the highcharts subtitle.
265
     */
266
    public function setStyle(array $style = null) {
267
        $this->style = $style;
0 ignored issues
show
Documentation Bug introduced by
It seems like $style can be null. However, the property $style is declared as array. Maybe change the type of the property to array|null or add a type check?

Our type inference engine has found an assignment of a scalar value (like a string, an integer or null) to a property which is an array.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property.

To type hint that a parameter can be either an array or null, you can set a type hint of array and a default value of null. The PHP interpreter will then accept both an array or null for that parameter.

function aContainsB(array $needle = null, array  $haystack) {
    if (!$needle) {
        return false;
    }

    return array_intersect($haystack, $needle) == $haystack;
}

The function can be called with either null or an array for the parameter $needle but will only accept an array as $haystack.

Loading history...
268
        return $this;
269
    }
270
271
    /**
272
     * Set the text.
273
     *
274
     * @param string $text The text.
275
     * @return \WBW\Bundle\HighchartsBundle\API\Chart\HighchartsSubtitle Returns the highcharts subtitle.
276
     */
277
    public function setText($text) {
278
        $this->text = $text;
279
        return $this;
280
    }
281
282
    /**
283
     * Set the use HTML.
284
     *
285
     * @param boolean $useHTML The use HTML.
286
     * @return \WBW\Bundle\HighchartsBundle\API\Chart\HighchartsSubtitle Returns the highcharts subtitle.
287
     */
288
    public function setUseHTML($useHTML) {
289
        $this->useHTML = $useHTML;
290
        return $this;
291
    }
292
293
    /**
294
     * Set the vertical align.
295
     *
296
     * @param string $verticalAlign The vertical align.
297
     * @return \WBW\Bundle\HighchartsBundle\API\Chart\HighchartsSubtitle Returns the highcharts subtitle.
298
     */
299
    public function setVerticalAlign($verticalAlign) {
300
        switch ($verticalAlign) {
301
            case "bottom":
302
            case "middle":
303
            case "top":
304
            $this->verticalAlign = $verticalAlign;
305
            break;
306
        }
307
        return $this;
308
    }
309
310
    /**
311
     * Set the width adjust.
312
     *
313
     * @param integer $widthAdjust The width adjust.
314
     * @return \WBW\Bundle\HighchartsBundle\API\Chart\HighchartsSubtitle Returns the highcharts subtitle.
315
     */
316
    public function setWidthAdjust($widthAdjust) {
317
        $this->widthAdjust = $widthAdjust;
318
        return $this;
319
    }
320
321
    /**
322
     * Set the x.
323
     *
324
     * @param integer $x The x.
325
     * @return \WBW\Bundle\HighchartsBundle\API\Chart\HighchartsSubtitle Returns the highcharts subtitle.
326
     */
327
    public function setX($x) {
328
        $this->x = $x;
329
        return $this;
330
    }
331
332
    /**
333
     * Set the y.
334
     *
335
     * @param integer $y The y.
336
     * @return \WBW\Bundle\HighchartsBundle\API\Chart\HighchartsSubtitle Returns the highcharts subtitle.
337
     */
338
    public function setY($y) {
339
        $this->y = $y;
340
        return $this;
341
    }
342
343
    /**
344
     * Convert into an array representing this instance.
345
     *
346
     * @return array Returns an array representing this instance.
347
     */
348
    public function toArray() {
349
350
        // Initialize the output.
351
        $output = [];
352
353
        // Set the align.
354
        ArrayUtility::set($output, "align", $this->align, [null]);
355
356
        // Set the floating.
357
        ArrayUtility::set($output, "floating", $this->floating, [null]);
358
359
        // Set the style.
360
        ArrayUtility::set($output, "style", $this->style, [null]);
361
362
        // Set the text.
363
        ArrayUtility::set($output, "text", $this->text, [null]);
364
365
        // Set the use HTML.
366
        ArrayUtility::set($output, "useHTML", $this->useHTML, [null]);
367
368
        // Set the vertical align.
369
        ArrayUtility::set($output, "verticalAlign", $this->verticalAlign, [null]);
370
371
        // Set the width adjust.
372
        ArrayUtility::set($output, "widthAdjust", $this->widthAdjust, [null]);
373
374
        // Set the x.
375
        ArrayUtility::set($output, "x", $this->x, [null]);
376
377
        // Set the y.
378
        ArrayUtility::set($output, "y", $this->y, [null]);
379
380
        // Return the output.
381
        return $output;
382
    }
383
384
}
385