1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace CarlosIO\Geckoboard\Data; |
4
|
|
|
|
5
|
|
|
use CarlosIO\Geckoboard\Data\Point\SizeOutOfBoundsException; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* Class Point. |
9
|
|
|
*/ |
10
|
|
|
class Point |
11
|
|
|
{ |
12
|
|
|
/** |
13
|
|
|
* @var string |
14
|
|
|
*/ |
15
|
|
|
protected $cityName; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* @var string |
19
|
|
|
*/ |
20
|
|
|
protected $countryCode; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @var int |
24
|
|
|
*/ |
25
|
|
|
protected $size; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @var string |
29
|
|
|
*/ |
30
|
|
|
protected $color; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @var string |
34
|
|
|
*/ |
35
|
|
|
protected $cssClass; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @var string |
39
|
|
|
*/ |
40
|
|
|
protected $latitude; |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @var string |
44
|
|
|
*/ |
45
|
|
|
protected $longitude; |
46
|
|
|
|
47
|
4 |
|
public function __construct() |
48
|
|
|
{ |
49
|
4 |
|
$this->cityName = null; |
50
|
4 |
|
$this->countryCode = null; |
51
|
4 |
|
$this->size = null; |
52
|
4 |
|
$this->color = null; |
53
|
4 |
|
$this->cssClass = null; |
54
|
4 |
|
$this->latitude = null; |
55
|
4 |
|
$this->longitude = null; |
56
|
4 |
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* @param $latitude |
60
|
|
|
* |
61
|
|
|
* @return $this |
62
|
|
|
*/ |
63
|
1 |
|
public function setLatitude($latitude) |
64
|
|
|
{ |
65
|
1 |
|
$this->latitude = $latitude; |
66
|
|
|
|
67
|
1 |
|
return $this; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
*/ |
72
|
3 |
|
public function getLatitude() |
73
|
|
|
{ |
74
|
3 |
|
return $this->latitude; |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* @param $longitude |
79
|
|
|
* |
80
|
|
|
* @return $this |
81
|
|
|
*/ |
82
|
1 |
|
public function setLongitude($longitude) |
83
|
|
|
{ |
84
|
1 |
|
$this->longitude = $longitude; |
85
|
|
|
|
86
|
1 |
|
return $this; |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
*/ |
91
|
3 |
|
public function getLongitude() |
92
|
|
|
{ |
93
|
3 |
|
return $this->longitude; |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* @param $cityName |
98
|
|
|
* |
99
|
|
|
* @return $this |
100
|
|
|
*/ |
101
|
2 |
|
public function setCityName($cityName) |
102
|
|
|
{ |
103
|
2 |
|
$this->cityName = $cityName; |
104
|
|
|
|
105
|
2 |
|
return $this; |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
*/ |
110
|
3 |
|
public function getCityName() |
111
|
|
|
{ |
112
|
3 |
|
return $this->cityName; |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
/** |
116
|
|
|
* @param $color |
117
|
|
|
* |
118
|
|
|
* @return $this |
119
|
|
|
*/ |
120
|
2 |
|
public function setColor($color) |
121
|
|
|
{ |
122
|
2 |
|
$this->color = $color; |
123
|
|
|
|
124
|
2 |
|
return $this; |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
/** |
128
|
|
|
*/ |
129
|
3 |
|
public function getColor() |
130
|
|
|
{ |
131
|
3 |
|
return $this->color; |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
/** |
135
|
|
|
* @param $countryCode |
136
|
|
|
* |
137
|
|
|
* @return $this |
138
|
|
|
*/ |
139
|
2 |
|
public function setCountryCode($countryCode) |
140
|
|
|
{ |
141
|
2 |
|
$this->countryCode = $countryCode; |
142
|
|
|
|
143
|
2 |
|
return $this; |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
/** |
147
|
|
|
*/ |
148
|
3 |
|
public function getCountryCode() |
149
|
|
|
{ |
150
|
3 |
|
return $this->countryCode; |
151
|
|
|
} |
152
|
|
|
|
153
|
|
|
/** |
154
|
|
|
* @param $cssClass |
155
|
|
|
* |
156
|
|
|
* @return $this |
157
|
|
|
*/ |
158
|
1 |
|
public function setCssClass($cssClass) |
159
|
|
|
{ |
160
|
1 |
|
$this->cssClass = $cssClass; |
161
|
|
|
|
162
|
1 |
|
return $this; |
163
|
|
|
} |
164
|
|
|
|
165
|
|
|
/** |
166
|
|
|
*/ |
167
|
3 |
|
public function getCssClass() |
168
|
|
|
{ |
169
|
3 |
|
return $this->cssClass; |
170
|
|
|
} |
171
|
|
|
|
172
|
|
|
/** |
173
|
|
|
* @param $size |
174
|
|
|
* |
175
|
|
|
* @throws Point\SizeOutOfBoundsException |
176
|
|
|
* |
177
|
|
|
* @return $this |
178
|
|
|
*/ |
179
|
3 |
|
public function setSize($size) |
180
|
|
|
{ |
181
|
3 |
|
$size = abs((int) $size); |
182
|
3 |
|
if ($size < 1 || $size > 10) { |
183
|
1 |
|
throw new SizeOutOfBoundsException('Map point size should be between 1 and 10'); |
184
|
|
|
} |
185
|
|
|
|
186
|
2 |
|
$this->size = $size; |
|
|
|
|
187
|
|
|
|
188
|
2 |
|
return $this; |
189
|
|
|
} |
190
|
|
|
|
191
|
|
|
/** |
192
|
|
|
* @return int |
193
|
|
|
*/ |
194
|
3 |
|
public function getSize() |
195
|
|
|
{ |
196
|
3 |
|
return $this->size; |
197
|
|
|
} |
198
|
|
|
|
199
|
|
|
/** |
200
|
|
|
* @return array |
201
|
|
|
*/ |
202
|
3 |
|
public function toArray() |
203
|
|
|
{ |
204
|
3 |
|
$result = array(); |
205
|
3 |
|
$cityData = array(); |
206
|
|
|
|
207
|
3 |
|
$cityName = $this->getCityName(); |
208
|
3 |
|
if (null !== $cityName) { |
209
|
2 |
|
$cityData['city_name'] = $cityName; |
210
|
2 |
|
} |
211
|
|
|
|
212
|
3 |
|
$countryCode = $this->getCountryCode(); |
213
|
3 |
|
if (null !== $countryCode) { |
214
|
2 |
|
$cityData['country_code'] = $countryCode; |
215
|
2 |
|
} |
216
|
|
|
|
217
|
3 |
|
if (!empty($cityData)) { |
218
|
2 |
|
$result['city'] = $cityData; |
219
|
2 |
|
} |
220
|
|
|
|
221
|
3 |
|
$latitude = $this->getLatitude(); |
222
|
3 |
|
if (null !== $latitude) { |
223
|
1 |
|
$result['latitude'] = $latitude; |
224
|
1 |
|
} |
225
|
|
|
|
226
|
3 |
|
$longitude = $this->getLongitude(); |
227
|
3 |
|
if (null !== $longitude) { |
228
|
1 |
|
$result['longitude'] = $longitude; |
229
|
1 |
|
} |
230
|
|
|
|
231
|
3 |
|
$size = $this->getSize(); |
232
|
3 |
|
if (null !== $size) { |
233
|
2 |
|
$result['size'] = $size; |
234
|
2 |
|
} |
235
|
|
|
|
236
|
3 |
|
$color = $this->getColor(); |
237
|
3 |
|
if (null !== $color) { |
238
|
2 |
|
$result['color'] = $color; |
239
|
2 |
|
} |
240
|
|
|
|
241
|
3 |
|
$cssClass = $this->getCssClass(); |
242
|
3 |
|
if (null !== $cssClass) { |
243
|
1 |
|
$result['cssclass'] = $cssClass; |
244
|
1 |
|
} |
245
|
|
|
|
246
|
3 |
|
return $result; |
247
|
|
|
} |
248
|
|
|
} |
249
|
|
|
|
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.
For example, imagine you have a variable
$accountId
that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to theid
property of an instance of theAccount
class. This class holds a proper account, so the id value must no longer be false.Either this assignment is in error or a type check should be added for that assignment.