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

CoordinateReferenceSystem   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 81
Duplicated Lines 0 %

Test Coverage

Coverage 68.18%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 33
c 1
b 0
f 0
dl 0
loc 81
ccs 15
cts 22
cp 0.6818
rs 10
wmc 11

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getDatum() 0 3 1
A getSupportedSRIDs() 0 3 1
B fromSRID() 0 27 7
A getSRID() 0 3 1
A getCoordinateSystem() 0 3 1
1
<?php
2
/**
3
 * PHPCoord.
4
 *
5
 * @author Doug Wright
6
 */
7
declare(strict_types=1);
8
9
namespace PHPCoord\CoordinateReferenceSystem;
10
11
use function array_merge;
12
use PHPCoord\CoordinateSystem\CoordinateSystem;
13
use PHPCoord\Datum\Datum;
14
use PHPCoord\Exception\UnknownCoordinateReferenceSystemException;
15
16
abstract class CoordinateReferenceSystem
17
{
18
    public const CRS_TYPE_COMPOUND = 'compound';
19
20
    public const CRS_TYPE_DERIVED = 'derived';
21
22
    public const CRS_TYPE_DYNAMIC_GEOCENTRIC = 'dynamic geocentric';
23
24
    public const CRS_TYPE_DYNAMIC_GEOGRAPHIC_2D = 'dynamic geographic 2D';
25
26
    public const CRS_TYPE_DYNAMIC_GEOGRAPHIC_3D = 'dynamic geographic 3D';
27
28
    public const CRS_TYPE_DYNAMIC_VERTICAL = 'dynamic vertical';
29
30
    public const CRS_TYPE_ENGINEERING = 'engineering';
31
32
    public const CRS_TYPE_GEOCENTRIC = 'geocentric';
33
34
    public const CRS_TYPE_GEOGRAPHIC_2D = 'geographic 2D';
35
36
    public const CRS_TYPE_GEOGRAPHIC_3D = 'geographic 3D';
37
38
    public const CRS_TYPE_PROJECTED = 'projected';
39
40
    public const CRS_TYPE_VERTICAL = 'vertical';
41
42
    public const CRS_SRID_PREFIX_EPSG = 'urn:ogc:def:crs:EPSG::';
43
44
    protected string $srid;
45
46
    protected CoordinateSystem $coordinateSystem;
47
48
    protected Datum $datum;
49
50 137
    public function getSRID(): string
51
    {
52 137
        return $this->srid;
53
    }
54
55 209
    public function getCoordinateSystem(): CoordinateSystem
56
    {
57 209
        return $this->coordinateSystem;
58
    }
59
60 116
    public function getDatum(): Datum
61
    {
62 116
        return $this->datum;
63
    }
64
65 141
    public static function fromSRID(string $srid): self
66
    {
67 141
        if (isset(Projected::getSupportedSRIDs()[$srid])) {
68 4
            return Projected::fromSRID($srid);
69
        }
70
71 141
        if (isset(Geographic2D::getSupportedSRIDs()[$srid])) {
72 139
            return Geographic2D::fromSRID($srid);
73
        }
74
75 2
        if (isset(Geographic3D::getSupportedSRIDs()[$srid])) {
76 1
            return Geographic3D::fromSRID($srid);
77
        }
78
79 1
        if (isset(Geocentric::getSupportedSRIDs()[$srid])) {
80 1
            return Geocentric::fromSRID($srid);
81
        }
82
83
        if (isset(Vertical::getSupportedSRIDs()[$srid])) {
84
            return Vertical::fromSRID($srid);
85
        }
86
87
        if (isset(Compound::getSupportedSRIDs()[$srid])) {
88
            return Compound::fromSRID($srid);
89
        }
90
91
        throw new UnknownCoordinateReferenceSystemException($srid);
92
    }
93
94
    public static function getSupportedSRIDs(): array
95
    {
96
        return array_merge(Compound::getSupportedSRIDs(), Geocentric::getSupportedSRIDs(), Geographic2D::getSupportedSRIDs(), Geographic3D::getSupportedSRIDs(), Projected::getSupportedSRIDs(), Vertical::getSupportedSRIDs());
97
    }
98
}
99