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

Point::getCoordinates()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
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