Passed
Push — master ( 9ff768...b736eb )
by Laurens
02:33
created

Coordinates::isNumericInBounds()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 3

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 4
cts 4
cp 1
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 4
nc 2
nop 3
crap 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace LauLamanApps\IzettleApi\API\Purchase;
6
7
use LauLamanApps\IzettleApi\API\Purchase\Exceptions\InvalidLatitudeException;
8
use LauLamanApps\IzettleApi\API\Purchase\Exceptions\InvalidLongitudeException;
9
10
final class Coordinates
11
{
12
    private $latitude;
13
    private $longitude;
14
    private $accuracyMeters;
15
16 12
    public function __construct(float $latitude, float $longitude, float $accuracyMeters)
17
    {
18 12
        $this->validateLatitude($latitude);
19 10
        $this->validateLongitude($longitude);
20 8
        $this->longitude = $longitude;
21 8
        $this->latitude = $latitude;
22 8
        $this->accuracyMeters = $accuracyMeters;
23 8
    }
24
25 6
    public function getLatitude(): float
26
    {
27 6
        return $this->latitude;
28
    }
29
30 6
    public function getLongitude(): float
31
    {
32 6
        return $this->longitude;
33
    }
34
35 6
    public function getAccuracyMeters(): float
36
    {
37 6
        return $this->accuracyMeters;
38
    }
39
40 12
    private function validateLatitude(float $latitude): void
41
    {
42 12
        if (!$this->isNumericInBounds($latitude, -90.0, 90.0)) {
43 2
            throw new InvalidLatitudeException(sprintf('%d is not a valid latitude', $latitude));
44
        }
45 10
    }
46
47 10
    private function validateLongitude(float $longitude): void
48
    {
49 10
        if (!$this->isNumericInBounds($longitude, -180.0, 180.0)) {
50 2
            throw new InvalidLongitudeException(sprintf('%d is not a valid longitude', $longitude));
51
        }
52 8
    }
53
54 12
    private function isNumericInBounds(float $value, float $min, float $max): bool
55
    {
56 12
        if ($value < $min || $value > $max) {
57 4
            return false;
58
        }
59
60 10
        return true;
61
    }
62
}
63