HighchartsCredits::setText()   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;
13
14
use JsonSerializable;
15
use WBW\Library\Core\Utility\Argument\ArrayUtility;
16
17
/**
18
 * Highcharts credits.
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 HighchartsCredits implements JsonSerializable {
26
27
    /**
28
     * Enabled.
29
     *
30
     * @var boolean
31
     */
32
    private $enabled = true;
33
34
    /**
35
     * Href.
36
     *
37
     * @var string
38
     */
39
    private $href = "http://www.highcharts.com";
40
41
    /**
42
     * Position.
43
     *
44
     * @var array
45
     * @since 2.1
46
     */
47
    private $position;
48
49
    /**
50
     * Style.
51
     *
52
     * @var array
53
     */
54
    private $style = ["cursor" => "pointer", "color" => "#999999", "fontSize" => "10px"];
55
56
    /**
57
     * Text.
58
     *
59
     * @var string
60
     */
61
    private $text = "Highcharts.com";
62
63
    /**
64
     * Constructor.
65
     *
66
     * @param boolean $ignoreDefaultValues Ignore the default values.
67
     */
68
    public function __construct($ignoreDefaultValues = true) {
69
        if (true === $ignoreDefaultValues) {
70
            $this->clear();
71
        }
72
    }
73
74
    /**
75
     * Clear.
76
     *
77
     * @return void
78
     */
79
    public function clear() {
80
81
        // Clear the enabled.
82
        $this->enabled = null;
83
84
        // Clear the href.
85
        $this->href = null;
86
87
        // Clear the position.
88
        $this->position = 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 $position.

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...
89
90
        // Clear the style.
91
        $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...
92
93
        // Clear the text.
94
        $this->text = null;
95
    }
96
97
    /**
98
     * Get the enabled.
99
     *
100
     * @return boolean Returns the enabled.
101
     */
102
    public function getEnabled() {
103
        return $this->enabled;
104
    }
105
106
    /**
107
     * Get the href.
108
     *
109
     * @return string Returns the href.
110
     */
111
    public function getHref() {
112
        return $this->href;
113
    }
114
115
    /**
116
     * Get the position.
117
     *
118
     * @return array Returns the position.
119
     */
120
    public function getPosition() {
121
        return $this->position;
122
    }
123
124
    /**
125
     * Get the style.
126
     *
127
     * @return array Returns the style.
128
     */
129
    public function getStyle() {
130
        return $this->style;
131
    }
132
133
    /**
134
     * Get the text.
135
     *
136
     * @return string Returns the text.
137
     */
138
    public function getText() {
139
        return $this->text;
140
    }
141
142
    /**
143
     * Serialize this instance.
144
     *
145
     * @return array Returns an array representing this instance.
146
     */
147
    public function jsonSerialize() {
148
        return $this->toArray();
149
    }
150
151
    /**
152
     * Set the enabled.
153
     *
154
     * @param boolean $enabled The enabled.
155
     * @return \WBW\Bundle\HighchartsBundle\API\Chart\HighchartsCredits Returns the highcharts credits.
156
     */
157
    public function setEnabled($enabled) {
158
        $this->enabled = $enabled;
159
        return $this;
160
    }
161
162
    /**
163
     * Set the href.
164
     *
165
     * @param string $href The href.
166
     * @return \WBW\Bundle\HighchartsBundle\API\Chart\HighchartsCredits Returns the highcharts credits.
167
     */
168
    public function setHref($href) {
169
        $this->href = $href;
170
        return $this;
171
    }
172
173
    /**
174
     * Set the position.
175
     *
176
     * @param array $position The position.
177
     * @return \WBW\Bundle\HighchartsBundle\API\Chart\HighchartsCredits Returns the highcharts credits.
178
     */
179
    public function setPosition(array $position = null) {
180
        $this->position = $position;
0 ignored issues
show
Documentation Bug introduced by
It seems like $position can be null. However, the property $position 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...
181
        return $this;
182
    }
183
184
    /**
185
     * Set the style.
186
     *
187
     * @param array $style The style.
188
     * @return \WBW\Bundle\HighchartsBundle\API\Chart\HighchartsCredits Returns the highcharts credits.
189
     */
190
    public function setStyle(array $style = null) {
191
        $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...
192
        return $this;
193
    }
194
195
    /**
196
     * Set the text.
197
     *
198
     * @param string $text The text.
199
     * @return \WBW\Bundle\HighchartsBundle\API\Chart\HighchartsCredits Returns the highcharts credits.
200
     */
201
    public function setText($text) {
202
        $this->text = $text;
203
        return $this;
204
    }
205
206
    /**
207
     * Convert into an array representing this instance.
208
     *
209
     * @return array Returns an array representing this instance.
210
     */
211
    public function toArray() {
212
213
        // Initialize the output.
214
        $output = [];
215
216
        // Set the enabled.
217
        ArrayUtility::set($output, "enabled", $this->enabled, [null]);
218
219
        // Set the href.
220
        ArrayUtility::set($output, "href", $this->href, [null]);
221
222
        // Set the position.
223
        ArrayUtility::set($output, "position", $this->position, [null]);
224
225
        // Set the style.
226
        ArrayUtility::set($output, "style", $this->style, [null]);
227
228
        // Set the text.
229
        ArrayUtility::set($output, "text", $this->text, [null]);
230
231
        // Return the output.
232
        return $output;
233
    }
234
235
}
236