HighchartsTitle::setStyle()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
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\Legend;
13
14
use JsonSerializable;
15
use WBW\Library\Core\Utility\Argument\ArrayUtility;
16
17
/**
18
 * Highcharts title.
19
 *
20
 * @author webeweb <https://github.com/webeweb/>
21
 * @package WBW\Bundle\HighchartsBundle\API\Chart\Legend
22
 * @version 5.0.14
23
 * @final
24
 */
25
final class HighchartsTitle implements JsonSerializable {
26
27
    /**
28
     * Style.
29
     *
30
     * @var array
31
     * @since 3.0
32
     */
33
    private $style = ["fontWeight" => "bold"];
34
35
    /**
36
     * Text.
37
     *
38
     * @var string
39
     * @since 3.0
40
     */
41
    private $text;
42
43
    /**
44
     * Constructor.
45
     *
46
     * @param boolean $ignoreDefaultValues Ignore the default values.
47
     */
48
    public function __construct($ignoreDefaultValues = true) {
49
        if (true === $ignoreDefaultValues) {
50
            $this->clear();
51
        }
52
    }
53
54
    /**
55
     * Clear.
56
     *
57
     * @return void
58
     */
59
    public function clear() {
60
61
        // Clear the style.
62
        $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...
63
64
        // Clear the text.
65
        $this->text = null;
66
    }
67
68
    /**
69
     * Get the style.
70
     *
71
     * @return array Returns the style.
72
     */
73
    public function getStyle() {
74
        return $this->style;
75
    }
76
77
    /**
78
     * Get the text.
79
     *
80
     * @return string Returns the text.
81
     */
82
    public function getText() {
83
        return $this->text;
84
    }
85
86
    /**
87
     * Serialize this instance.
88
     *
89
     * @return array Returns an array representing this instance.
90
     */
91
    public function jsonSerialize() {
92
        return $this->toArray();
93
    }
94
95
    /**
96
     * Set the style.
97
     *
98
     * @param array $style The style.
99
     * @return \WBW\Bundle\HighchartsBundle\API\Chart\Legend\HighchartsTitle Returns the highcharts title.
100
     */
101
    public function setStyle(array $style = null) {
102
        $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...
103
        return $this;
104
    }
105
106
    /**
107
     * Set the text.
108
     *
109
     * @param string $text The text.
110
     * @return \WBW\Bundle\HighchartsBundle\API\Chart\Legend\HighchartsTitle Returns the highcharts title.
111
     */
112
    public function setText($text) {
113
        $this->text = $text;
114
        return $this;
115
    }
116
117
    /**
118
     * Convert into an array representing this instance.
119
     *
120
     * @return array Returns an array representing this instance.
121
     */
122
    public function toArray() {
123
124
        // Initialize the output.
125
        $output = [];
126
127
        // Set the style.
128
        ArrayUtility::set($output, "style", $this->style, [null]);
129
130
        // Set the text.
131
        ArrayUtility::set($output, "text", $this->text, [null]);
132
133
        // Return the output.
134
        return $output;
135
    }
136
137
}
138