Passed
Push — 4.x ( 17e0c5...e9b635 )
by Doug
07:44
created

CompoundPoint::getVerticalPoint()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
cc 1
nc 1
nop 0
crap 1
1
<?php
2
/**
3
 * PHPCoord.
4
 *
5
 * @author Doug Wright
6
 */
7
declare(strict_types=1);
8
9
namespace PHPCoord;
10
11
use PHPCoord\CoordinateReferenceSystem\Compound;
12
use PHPCoord\CoordinateReferenceSystem\CoordinateReferenceSystem;
13
use PHPCoord\Exception\InvalidCoordinateReferenceSystemException;
14
use PHPCoord\UnitOfMeasure\Length\Length;
15
16
/**
17
 * Coordinate representing a point expressed in 2 different CRSs (2D horizontal + 1D Vertical).
18
 */
19
class CompoundPoint extends Point
20
{
21
    /**
22
     * Horizontal point.
23
     * @var GeocentricPoint|GeographicPoint|ProjectedPoint
24
     */
25
    protected $horizontalPoint;
26
27
    /**
28
     * Vertical point.
29
     * @var VerticalPoint
30
     */
31
    protected $verticalPoint;
32
33
    /**
34
     * Coordinate reference system.
35
     * @var CoordinateReferenceSystem
36
     */
37
    protected $crs;
38
39
    /**
40
     * Constructor.
41
     * @param GeocentricPoint|GeographicPoint|ProjectedPoint $horizontalPoint
42
     */
43 4
    public function __construct(Point $horizontalPoint, VerticalPoint $verticalPoint, CoordinateReferenceSystem $crs)
44
    {
45 4
        if (!$crs instanceof Compound) {
46 1
            throw new InvalidCoordinateReferenceSystemException(sprintf("A compound point must be associated with a compound CRS, but a '%s' CRS was given", get_class($crs)));
47
        }
48
49 3
        $this->horizontalPoint = $horizontalPoint;
0 ignored issues
show
Documentation Bug introduced by
$horizontalPoint is of type PHPCoord\Point, but the property $horizontalPoint was declared to be of type PHPCoord\GeocentricPoint...PHPCoord\ProjectedPoint. Are you sure that you always receive this specific sub-class here, or does it make sense to add an instanceof check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a given class or a super-class is assigned to a property that is type hinted more strictly.

Either this assignment is in error or an instanceof check should be added for that assignment.

class Alien {}

class Dalek extends Alien {}

class Plot
{
    /** @var  Dalek */
    public $villain;
}

$alien = new Alien();
$plot = new Plot();
if ($alien instanceof Dalek) {
    $plot->villain = $alien;
}
Loading history...
50 3
        $this->verticalPoint = $verticalPoint;
51 3
        $this->crs = $crs;
52 3
    }
53
54 1
    public function getHorizontalPoint(): Point
55
    {
56 1
        return $this->horizontalPoint;
57
    }
58
59 1
    public function getVerticalPoint(): VerticalPoint
60
    {
61 1
        return $this->verticalPoint;
62
    }
63
64 3
    public function getCRS(): CoordinateReferenceSystem
65
    {
66 3
        return $this->crs;
67
    }
68
69
    /**
70
     * Calculate distance between two points.
71
     */
72 2
    public function calculateDistance(Point $to): Length
73
    {
74 2
        if ($to->getCRS()->getEpsgCode() !== $this->crs->getEpsgCode()) {
75 1
            throw new InvalidCoordinateReferenceSystemException('Can only calculate distances between two points in the same CRS');
76
        }
77
78
        /* @var CompoundPoint $to */
79 1
        return $this->horizontalPoint->calculateDistance($to->horizontalPoint);
80
    }
81
82 1
    public function __toString(): string
83
    {
84 1
        return "({$this->horizontalPoint}, {$this->verticalPoint})";
85
    }
86
}
87