|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace LeKoala\GeoTools\Models; |
|
4
|
|
|
|
|
5
|
|
|
/** |
|
6
|
|
|
* A global coordinates model |
|
7
|
|
|
*/ |
|
8
|
|
|
class Coordinates |
|
9
|
|
|
{ |
|
10
|
|
|
/** |
|
11
|
|
|
* @var float |
|
12
|
|
|
*/ |
|
13
|
|
|
protected $latitude; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* @var float |
|
17
|
|
|
*/ |
|
18
|
|
|
protected $longitude; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* @param string|float $latitude |
|
22
|
|
|
* @param string|float $longitude |
|
23
|
|
|
*/ |
|
24
|
|
|
public function __construct($latitude = null, $longitude = null) |
|
25
|
|
|
{ |
|
26
|
|
|
if ($latitude && !is_float($latitude)) { |
|
27
|
|
|
$latitude = floatval($latitude); |
|
28
|
|
|
} |
|
29
|
|
|
if ($longitude && !is_float($longitude)) { |
|
30
|
|
|
$longitude = floatval($longitude); |
|
31
|
|
|
} |
|
32
|
|
|
if ($latitude && $longitude) { |
|
33
|
|
|
$this->latitude = $latitude; |
|
|
|
|
|
|
34
|
|
|
$this->longitude = $longitude; |
|
|
|
|
|
|
35
|
|
|
} |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* Create from a given source (array, pairs) |
|
40
|
|
|
* |
|
41
|
|
|
* Coordinates::create('lat,lon') |
|
42
|
|
|
* Coordinates::create('lat','lon') |
|
43
|
|
|
* Coordinates::create(['lat','lon']) |
|
44
|
|
|
* |
|
45
|
|
|
* @param mixed $source |
|
46
|
|
|
* @param array<string> $more |
|
47
|
|
|
* @return self |
|
48
|
|
|
*/ |
|
49
|
|
|
public static function create($source, ...$more) |
|
50
|
|
|
{ |
|
51
|
|
|
if (!is_array($source)) { |
|
52
|
|
|
$source = explode(',', $source); |
|
53
|
|
|
} |
|
54
|
|
|
if (!empty($more)) { |
|
55
|
|
|
$source = array_merge($source, $more); |
|
56
|
|
|
} |
|
57
|
|
|
return new self($source[0], $source[1]); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* Get the value of latitude |
|
62
|
|
|
*/ |
|
63
|
|
|
public function getLatitude(): ?float |
|
64
|
|
|
{ |
|
65
|
|
|
return $this->latitude; |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* Set the value of latitude |
|
70
|
|
|
* |
|
71
|
|
|
* @return $this |
|
72
|
|
|
*/ |
|
73
|
|
|
public function setLatitude(float $latitude) |
|
74
|
|
|
{ |
|
75
|
|
|
$this->latitude = $latitude; |
|
76
|
|
|
return $this; |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* Get the value of longitude |
|
81
|
|
|
*/ |
|
82
|
|
|
public function getLongitude(): ?float |
|
83
|
|
|
{ |
|
84
|
|
|
return $this->longitude; |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
/** |
|
88
|
|
|
* Set the value of longitude |
|
89
|
|
|
* |
|
90
|
|
|
* @return $this |
|
91
|
|
|
*/ |
|
92
|
|
|
public function setLongitude(float $longitude) |
|
93
|
|
|
{ |
|
94
|
|
|
$this->longitude = $longitude; |
|
95
|
|
|
return $this; |
|
96
|
|
|
} |
|
97
|
|
|
} |
|
98
|
|
|
|
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
$accountIdthat can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to theidproperty of an instance of theAccountclass. 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.