Passed
Push — 4.x ( f9780c...a64886 )
by Doug
05:20
created

GeographicValue   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 22
c 1
b 0
f 0
dl 0
loc 50
ccs 24
cts 24
cp 1
rs 10
wmc 7

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 2
A getLongitude() 0 3 1
A getLatitude() 0 3 1
A getHeight() 0 3 1
A asGeocentricValue() 0 14 2
1
<?php
2
/**
3
 * PHPCoord.
4
 *
5
 * @author Doug Wright
6
 */
7
declare(strict_types=1);
8
9
namespace PHPCoord\CoordinateOperation;
10
11
use function cos;
12
use PHPCoord\Datum\Datum;
13
use PHPCoord\UnitOfMeasure\Angle\Angle;
14
use PHPCoord\UnitOfMeasure\Angle\Radian;
15
use PHPCoord\UnitOfMeasure\Length\Length;
16
use PHPCoord\UnitOfMeasure\Length\Metre;
17
use function sin;
18
use function sqrt;
19
20
/**
21
 * A geographic point w/out a CRS.
22
 * @internal
23
 */
24
class GeographicValue
25
{
26
    private Radian $latitude;
27
28
    private Radian $longitude;
29
30
    private ?Metre $height;
31
32
    private Datum $datum;
33
34 28
    public function __construct(Angle $latitude, Angle $longitude, ?Length $height, Datum $datum)
35
    {
36 28
        $this->latitude = $latitude->asRadians();
37 28
        $this->longitude = $longitude->asRadians();
38 28
        $this->datum = $datum;
39
40 28
        if ($height) {
41 17
            $this->height = $height->asMetres();
42
        }
43 28
    }
44
45 25
    public function getLatitude(): Radian
46
    {
47 25
        return $this->latitude;
48
    }
49
50 25
    public function getLongitude(): Radian
51
    {
52 25
        return $this->longitude;
53
    }
54
55 7
    public function getHeight(): ?Metre
56
    {
57 7
        return $this->height;
58
    }
59
60 13
    public function asGeocentricValue(): GeocentricValue
61
    {
62 13
        $a = $this->datum->getEllipsoid()->getSemiMajorAxis()->asMetres()->getValue();
63 13
        $e2 = $this->datum->getEllipsoid()->getEccentricitySquared();
64 13
        $latitude = $this->latitude->getValue();
65 13
        $longitude = $this->longitude->getValue() - $this->datum->getPrimeMeridian()->getGreenwichLongitude()->asRadians()->getValue();
66 13
        $h = isset($this->height) ? $this->height->getValue() : 0;
0 ignored issues
show
Bug introduced by
The method getValue() does not exist on null. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

66
        $h = isset($this->height) ? $this->height->/** @scrutinizer ignore-call */ getValue() : 0;

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
67
68 13
        $nu = $a / sqrt(1 - $e2 * (sin($latitude) ** 2));
69 13
        $x = ($nu + $h) * cos($latitude) * cos($longitude);
70 13
        $y = ($nu + $h) * cos($latitude) * sin($longitude);
71 13
        $z = ((1 - $e2) * $nu + $h) * sin($latitude);
72
73 13
        return new GeocentricValue(new Metre($x), new Metre($y), new Metre($z), $this->datum);
74
    }
75
}
76