Coordinates::longitude()   A
last analyzed

Complexity

Conditions 5
Paths 3

Size

Total Lines 11
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 5

Importance

Changes 0
Metric Value
eloc 5
dl 0
loc 11
ccs 6
cts 6
cp 1
rs 9.6111
c 0
b 0
f 0
cc 5
nc 3
nop 2
crap 5
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