Passed
Pull Request — master (#34)
by Benjamin
26:50 queued 11:50
created

Point   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 13
c 1
b 0
f 0
dl 0
loc 30
rs 10
wmc 7

3 Methods

Rating   Name   Duplication   Size   Complexity  
A validateCoordinates() 0 5 5
A __construct() 0 6 1
A getCoordinates() 0 3 1
1
<?php
2
3
namespace Kmeans\Gps;
4
5
use Kmeans\Concerns\HasDataTrait;
6
use Kmeans\Concerns\HasSpaceTrait;
7
use Kmeans\Interfaces\PointInterface;
8
9
/**
10
 * @method array{0: float, 1: float} getCoordinates()
11
 */
0 ignored issues
show
Documentation Bug introduced by
The doc comment array{0: at position 4 could not be parsed: the token is null at position 4.
Loading history...
12
class Point implements PointInterface
13
{
14
    use HasDataTrait;
15
    use HasSpaceTrait;
16
17
    private float $lat;
18
19
    private float $long;
20
21
    public function __construct(float $lat, float $long)
22
    {
23
        $this->validateCoordinates($lat, $long);
24
        $this->setSpace(Space::singleton());
25
        $this->lat = $lat;
26
        $this->long = $long;
27
    }
28
29
    /**
30
     * @return array{0: float, 1: float}
31
     */
32
    public function getCoordinates(): array
33
    {
34
        return [$this->lat, $this->long];
35
    }
36
37
    private function validateCoordinates(float $lat, float $long): void
38
    {
39
        if ($lat < -90 || $lat > 90 || $long < -180 || $long > 180) {
40
            throw new \InvalidArgumentException(
41
                "Invalid GPS coordinates"
42
            );
43
        }
44
    }
45
}
46