1 | <?php |
||
17 | class GlobeCoordinateValue extends DataValueObject { |
||
18 | |||
19 | /** |
||
20 | * @var LatLongValue |
||
21 | */ |
||
22 | private $latLong; |
||
23 | |||
24 | /** |
||
25 | * The precision of the coordinate in degrees, e.g. 0.01. |
||
26 | * |
||
27 | * @var float|int|null |
||
28 | */ |
||
29 | private $precision; |
||
30 | |||
31 | /** |
||
32 | * IRI of the globe on which the location resides. |
||
33 | * |
||
34 | * @var string |
||
35 | */ |
||
36 | private $globe; |
||
37 | |||
38 | /** |
||
39 | * Wikidata concept URI for the Earth. Used as default value when no other globe was specified. |
||
40 | */ |
||
41 | public const GLOBE_EARTH = 'http://www.wikidata.org/entity/Q2'; |
||
42 | |||
43 | /** |
||
44 | * @param LatLongValue $latLong |
||
45 | * @param float|int|null $precision in degrees, e.g. 0.01. |
||
46 | * @param string|null $globe IRI, defaults to 'http://www.wikidata.org/entity/Q2'. |
||
47 | * |
||
48 | * @throws IllegalValueException |
||
49 | */ |
||
50 | 70 | public function __construct( LatLongValue $latLong, float $precision = null, string $globe = null ) { |
|
63 | |||
64 | /** |
||
65 | * @see LatLongValue::assertIsLatitude |
||
66 | * @see LatLongValue::assertIsLongitude |
||
67 | * |
||
68 | * @param float|int|null $precision |
||
69 | * |
||
70 | * @throws IllegalValueException |
||
71 | */ |
||
72 | 70 | private function assertIsPrecision( $precision ) { |
|
73 | 70 | if ( $precision !== null ) { |
|
74 | 66 | if ( !is_float( $precision ) && !is_int( $precision ) ) { |
|
75 | throw new IllegalValueException( '$precision must be a number or null' ); |
||
76 | 66 | } elseif ( $precision < -360 || $precision > 360 ) { |
|
77 | 2 | throw new IllegalValueException( '$precision needs to be between -360 and 360' ); |
|
78 | } |
||
79 | } |
||
80 | 68 | } |
|
81 | |||
82 | /** |
||
83 | * @see Serializable::serialize |
||
84 | * |
||
85 | * @return string |
||
86 | */ |
||
87 | 48 | public function serialize(): string { |
|
90 | |||
91 | /** |
||
92 | * @see Serializable::unserialize |
||
93 | * |
||
94 | * @param string $value |
||
95 | * |
||
96 | * @throws IllegalValueException |
||
97 | */ |
||
98 | 49 | public function unserialize( $value ) { |
|
102 | |||
103 | /** |
||
104 | * @see DataValue::getType |
||
105 | * |
||
106 | * @return string |
||
107 | */ |
||
108 | 32 | public static function getType(): string { |
|
111 | |||
112 | /** |
||
113 | * @see DataValue::getSortKey |
||
114 | * |
||
115 | * @return float |
||
116 | */ |
||
117 | public function getSortKey(): float { |
||
120 | |||
121 | 18 | public function getLatitude(): float { |
|
122 | 18 | return $this->latLong->getLatitude(); |
|
123 | } |
||
124 | |||
125 | 18 | public function getLongitude(): float { |
|
126 | 18 | return $this->latLong->getLongitude(); |
|
127 | } |
||
128 | |||
129 | /** |
||
130 | * @see DataValue::getValue |
||
131 | * |
||
132 | * @return self |
||
133 | */ |
||
134 | 16 | public function getValue(): self { |
|
135 | 16 | return $this; |
|
136 | } |
||
137 | |||
138 | public function getLatLong(): LatLongValue { |
||
139 | return $this->latLong; |
||
140 | } |
||
141 | |||
142 | /** |
||
143 | * Returns the precision of the coordinate in degrees, e.g. 0.01. |
||
144 | * |
||
145 | * @return float|int|null |
||
146 | */ |
||
147 | 18 | public function getPrecision(): ?float { |
|
148 | 18 | return $this->precision; |
|
149 | } |
||
150 | |||
151 | /** |
||
152 | * Returns the IRI of the globe on which the location resides. |
||
153 | * |
||
154 | * @return string |
||
155 | */ |
||
156 | 18 | public function getGlobe(): string { |
|
159 | |||
160 | /** |
||
161 | * @see Hashable::getHash |
||
162 | * |
||
163 | * @since 2.0 |
||
164 | * |
||
165 | * @return string |
||
166 | */ |
||
167 | 17 | public function getHash(): string { |
|
168 | 17 | return md5( $this->latLong->getLatitude() . '|' |
|
169 | 17 | . $this->latLong->getLongitude() . '|' |
|
170 | 17 | . $this->precision . '|' |
|
171 | 17 | . $this->globe ); |
|
172 | } |
||
173 | |||
174 | /** |
||
175 | * @see DataValue::getArrayValue |
||
176 | * |
||
177 | * @return array |
||
178 | */ |
||
179 | 80 | public function getArrayValue(): array { |
|
192 | |||
193 | /** |
||
194 | * Constructs a new instance from the provided data. Required for @see DataValueDeserializer. |
||
195 | * This is expected to round-trip with @see getArrayValue. |
||
196 | * |
||
197 | * @deprecated since 2.0.1. Static DataValue::newFromArray constructors like this are |
||
198 | * underspecified (not in the DataValue interface), and misleadingly named (should be named |
||
199 | * newFromArrayValue). Instead, use DataValue builder callbacks in @see DataValueDeserializer. |
||
200 | * |
||
201 | * @param mixed $data Warning! Even if this is expected to be a value as returned by |
||
202 | * @see getArrayValue, callers of this specific newFromArray implementation can not guarantee |
||
203 | * this. This is not even guaranteed to be an array! |
||
204 | * |
||
205 | * @throws IllegalValueException if $data is not in the expected format. Subclasses of |
||
206 | * InvalidArgumentException are expected and properly handled by @see DataValueDeserializer. |
||
207 | * @return self |
||
208 | */ |
||
209 | 6 | public static function newFromArray( $data ): self { |
|
221 | |||
222 | } |
||
223 |
This checks looks for assignemnts to variables using the
list(...)
function, where not all assigned variables are subsequently used.Consider the following code example.
Only the variables
$a
and$c
are used. There was no need to assign$b
.Instead, the list call could have been.