|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types = 1); |
|
4
|
|
|
|
|
5
|
|
|
namespace DummyGenerator\Core; |
|
6
|
|
|
|
|
7
|
|
|
use DummyGenerator\Definitions\Extension\Awareness\RandomizerAwareExtensionInterface; |
|
8
|
|
|
use DummyGenerator\Definitions\Extension\Awareness\RandomizerAwareExtensionTrait; |
|
9
|
|
|
use DummyGenerator\Definitions\Extension\CoordinatesExtensionInterface; |
|
10
|
|
|
use DummyGenerator\Definitions\Extension\Exception\ExtensionLogicException; |
|
11
|
|
|
|
|
12
|
|
|
class Coordinates implements CoordinatesExtensionInterface, RandomizerAwareExtensionInterface |
|
13
|
|
|
{ |
|
14
|
|
|
use RandomizerAwareExtensionTrait; |
|
15
|
|
|
|
|
16
|
4 |
|
public function latitude(float $min = -90.0, float $max = 90.0): float |
|
17
|
|
|
{ |
|
18
|
4 |
|
if ($min < -90 || $max < -90) { |
|
19
|
1 |
|
throw new ExtensionLogicException('Latitude cannot be less that -90.0'); |
|
20
|
|
|
} |
|
21
|
|
|
|
|
22
|
3 |
|
if ($min > 90 || $max > 90) { |
|
23
|
1 |
|
throw new ExtensionLogicException('Latitude cannot be greater that 90.0'); |
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
2 |
|
return round($this->randomizer->getFloat($min, $max), 6); |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
4 |
|
public function longitude(float $min = -180.0, float $max = 180.0): float |
|
30
|
|
|
{ |
|
31
|
4 |
|
if ($min < -180 || $max < -180) { |
|
32
|
1 |
|
throw new ExtensionLogicException('Longitude cannot be less that -180.0'); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
3 |
|
if ($min > 180 || $max > 180) { |
|
36
|
1 |
|
throw new ExtensionLogicException('Longitude cannot be greater that 180.0'); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
2 |
|
return round($this->randomizer->getFloat($min, $max), 6); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
1 |
|
public function coordinates(): array |
|
43
|
|
|
{ |
|
44
|
1 |
|
return [ |
|
45
|
1 |
|
'latitude' => $this->latitude(), |
|
46
|
1 |
|
'longitude' => $this->longitude(), |
|
47
|
1 |
|
]; |
|
48
|
|
|
} |
|
49
|
|
|
} |
|
50
|
|
|
|