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

Coordinates   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 11
lcom 0
cbo 2
dl 0
loc 53
ccs 25
cts 25
cp 1
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 1
A getLatitude() 0 4 1
A getLongitude() 0 4 1
A getAccuracyMeters() 0 4 1
A validateLatitude() 0 6 2
A validateLongitude() 0 6 2
A isNumericInBounds() 0 8 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