1 | <?php namespace Arcanedev\Units\Bases; |
||
14 | abstract class UnitMeasure implements UnitMeasureContract |
||
15 | { |
||
16 | /* ------------------------------------------------------------------------------------------------ |
||
17 | | Properties |
||
18 | | ------------------------------------------------------------------------------------------------ |
||
19 | */ |
||
20 | /** |
||
21 | * The unit. |
||
22 | * |
||
23 | * @var string |
||
24 | */ |
||
25 | protected $unit; |
||
26 | |||
27 | /** |
||
28 | * The value. |
||
29 | * |
||
30 | * @var float|int |
||
31 | */ |
||
32 | protected $value; |
||
33 | |||
34 | /** |
||
35 | * The unit symbols. |
||
36 | * |
||
37 | * @var array |
||
38 | */ |
||
39 | protected $symbols = []; |
||
40 | |||
41 | /** |
||
42 | * The unit names. |
||
43 | * |
||
44 | * @var array |
||
45 | */ |
||
46 | protected $names = []; |
||
47 | |||
48 | /** |
||
49 | * The number of decimals to format. |
||
50 | * |
||
51 | * @var int |
||
52 | */ |
||
53 | protected $decimals = 0; |
||
54 | |||
55 | /** |
||
56 | * The decimal separator. |
||
57 | * |
||
58 | * @var string |
||
59 | */ |
||
60 | protected $decimalSeparator = '.'; |
||
61 | |||
62 | /** |
||
63 | * The thousands separator. |
||
64 | * |
||
65 | * @var string |
||
66 | */ |
||
67 | protected $thousandsSeparator = ','; |
||
68 | |||
69 | /* ------------------------------------------------------------------------------------------------ |
||
70 | | Init Function |
||
71 | | ------------------------------------------------------------------------------------------------ |
||
72 | */ |
||
73 | /** |
||
74 | * Initialize the unit. |
||
75 | * |
||
76 | * @param float|int $value |
||
77 | * @param string $unit |
||
78 | * @param array $options |
||
79 | */ |
||
80 | 528 | protected function init($value, $unit, array $options) |
|
92 | |||
93 | /* ------------------------------------------------------------------------------------------------ |
||
94 | | Getters & Setters |
||
95 | | ------------------------------------------------------------------------------------------------ |
||
96 | */ |
||
97 | /** |
||
98 | * Get the unit value. |
||
99 | * |
||
100 | * @return float|int |
||
101 | */ |
||
102 | 408 | public function value() |
|
106 | |||
107 | /** |
||
108 | * Set the unit value. |
||
109 | * |
||
110 | * @param float|int $value |
||
111 | * |
||
112 | * @return static |
||
113 | */ |
||
114 | 528 | public function setValue($value) |
|
120 | |||
121 | /** |
||
122 | * Get the default units. |
||
123 | * |
||
124 | * @return array |
||
125 | */ |
||
126 | 528 | public static function units() |
|
133 | |||
134 | /** |
||
135 | * Get the unit key. |
||
136 | * |
||
137 | * @return string |
||
138 | */ |
||
139 | 288 | public function unit() |
|
143 | |||
144 | /** |
||
145 | * Set the unit key. |
||
146 | * |
||
147 | * @param string $unit |
||
148 | * |
||
149 | * @return static |
||
150 | */ |
||
151 | 528 | public function setUnit($unit) |
|
159 | |||
160 | /** |
||
161 | * Get the unit symbols. |
||
162 | * |
||
163 | * @return array |
||
164 | */ |
||
165 | 96 | public function symbols() |
|
169 | |||
170 | /** |
||
171 | * Get the default symbols. |
||
172 | * |
||
173 | * @return array |
||
174 | */ |
||
175 | 504 | protected static function defaultSymbols() |
|
179 | |||
180 | /** |
||
181 | * Set the unit symbols. |
||
182 | * |
||
183 | * @param array $symbols |
||
184 | * |
||
185 | * @return static |
||
186 | */ |
||
187 | 528 | public function setSymbols(array $symbols) |
|
197 | |||
198 | /** |
||
199 | * Get the unit symbol. |
||
200 | * |
||
201 | * @return string |
||
202 | */ |
||
203 | 72 | public function symbol() |
|
207 | |||
208 | /** |
||
209 | * Set the unit symbol. |
||
210 | * |
||
211 | * @param string $unit |
||
212 | * @param string $symbol |
||
213 | * |
||
214 | * @return static |
||
215 | */ |
||
216 | 528 | public function setSymbol($unit, $symbol) |
|
224 | |||
225 | /** |
||
226 | * Get the unit names. |
||
227 | * |
||
228 | * @return array |
||
229 | */ |
||
230 | 48 | public function names() |
|
234 | |||
235 | /** |
||
236 | * Get the default names. |
||
237 | * |
||
238 | * @return array |
||
239 | */ |
||
240 | abstract protected function defaultNames(); |
||
241 | |||
242 | /** |
||
243 | * Set the unit names. |
||
244 | * |
||
245 | * @param array $names |
||
246 | * |
||
247 | * @return static |
||
248 | */ |
||
249 | 528 | public function setNames(array $names) |
|
259 | |||
260 | /** |
||
261 | * Get the unit name. |
||
262 | * |
||
263 | * @return string |
||
264 | */ |
||
265 | 24 | public function name() |
|
269 | |||
270 | /** |
||
271 | * Get the name by a given unit. |
||
272 | * |
||
273 | * @param string $unit |
||
274 | * |
||
275 | * @return string |
||
276 | */ |
||
277 | 48 | public function getName($unit) |
|
283 | |||
284 | /** |
||
285 | * Set the unit name. |
||
286 | * |
||
287 | * @param string $unit |
||
288 | * @param string $name |
||
289 | * |
||
290 | * @return static |
||
291 | */ |
||
292 | 528 | public function setName($unit, $name) |
|
300 | |||
301 | /** |
||
302 | * Set the format. |
||
303 | * |
||
304 | * @param int $decimals |
||
305 | * @param string $decimalSeparator |
||
306 | * @param string $thousandsSeparator |
||
307 | * |
||
308 | * @return static |
||
309 | */ |
||
310 | 528 | public function setFormat($decimals = 0, $decimalSeparator = ',', $thousandsSeparator = '.') |
|
318 | |||
319 | /* ------------------------------------------------------------------------------------------------ |
||
320 | | Main Functions |
||
321 | | ------------------------------------------------------------------------------------------------ |
||
322 | */ |
||
323 | /** |
||
324 | * Format the weight. |
||
325 | * |
||
326 | * @param int|null $decimals |
||
327 | * @param string|null $decimalSeparator |
||
328 | * @param string|null $thousandsSeparator |
||
329 | * |
||
330 | * @return string |
||
331 | */ |
||
332 | 72 | public function format( |
|
343 | |||
344 | /** |
||
345 | * Format the weight with symbol. |
||
346 | * |
||
347 | * @param int|null $decimals |
||
348 | * @param string|null $decimalSeparator |
||
349 | * @param string|null $thousandsSeparator |
||
350 | * |
||
351 | * @return string |
||
352 | */ |
||
353 | 48 | public function formatWithSymbol( |
|
360 | |||
361 | /** |
||
362 | * Convert object to string. |
||
363 | * |
||
364 | * @return string |
||
365 | */ |
||
366 | 24 | public function __toString() |
|
370 | |||
371 | /* ------------------------------------------------------------------------------------------------ |
||
372 | | Check Functions |
||
373 | | ------------------------------------------------------------------------------------------------ |
||
374 | */ |
||
375 | /** |
||
376 | * Check the weight unit. |
||
377 | * |
||
378 | * @param string $unit |
||
379 | */ |
||
380 | 528 | protected static function checkUnit($unit) |
|
390 | } |
||
391 |
This check looks for calls to
isset(...)
orempty()
on variables that are yet undefined. These calls will always produce the same result and can be removed.This is most likely caused by the renaming of a variable or the removal of a function/method parameter.