Passed
Push — master ( 2068f7...57e3ff )
by Doug
24:27
created

CoordinateReferenceSystem   A

Complexity

Total Complexity 14

Size/Duplication

Total Lines 91
Duplicated Lines 0 %

Test Coverage

Coverage 89.29%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 41
c 2
b 0
f 0
dl 0
loc 91
ccs 25
cts 28
cp 0.8929
rs 10
wmc 14

7 Methods

Rating   Name   Duplication   Size   Complexity  
A getDatum() 0 3 1
A getSupportedSRIDs() 0 3 1
A getBoundingArea() 0 3 1
A getSRID() 0 3 1
A getName() 0 3 1
A getCoordinateSystem() 0 3 1
B fromSRID() 0 21 8
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
use PHPCoord\Geometry\BoundingArea;
16
17
abstract class CoordinateReferenceSystem
18
{
19
    public const CRS_TYPE_COMPOUND = 'compound';
20
21
    public const CRS_TYPE_DERIVED = 'derived';
22
23
    public const CRS_TYPE_DYNAMIC_GEOCENTRIC = 'dynamic geocentric';
24
25
    public const CRS_TYPE_DYNAMIC_GEOGRAPHIC_2D = 'dynamic geographic 2D';
26
27
    public const CRS_TYPE_DYNAMIC_GEOGRAPHIC_3D = 'dynamic geographic 3D';
28
29
    public const CRS_TYPE_DYNAMIC_VERTICAL = 'dynamic vertical';
30
31
    public const CRS_TYPE_ENGINEERING = 'engineering';
32
33
    public const CRS_TYPE_GEOCENTRIC = 'geocentric';
34
35
    public const CRS_TYPE_GEOGRAPHIC_2D = 'geographic 2D';
36
37
    public const CRS_TYPE_GEOGRAPHIC_3D = 'geographic 3D';
38
39
    public const CRS_TYPE_PROJECTED = 'projected';
40
41
    public const CRS_TYPE_VERTICAL = 'vertical';
42
43
    public const CRS_SRID_PREFIX_EPSG = 'urn:ogc:def:crs:EPSG::';
44
45
    protected string $srid;
46
47
    protected string $name;
48
49
    protected CoordinateSystem $coordinateSystem;
50
51
    protected Datum $datum;
52
53
    protected BoundingArea $boundingArea;
54
55
    private static array $cachedObjects = [];
56
57 3576
    public function getSRID(): string
58
    {
59 3576
        return $this->srid;
60
    }
61
62 9144
    public function getName(): string
63
    {
64 9144
        return $this->name;
65
    }
66
67 8308
    public function getCoordinateSystem(): CoordinateSystem
68
    {
69 8308
        return $this->coordinateSystem;
70
    }
71
72 12119
    public function getDatum(): Datum
73
    {
74 12119
        return $this->datum;
75
    }
76
77 300
    public function getBoundingArea(): BoundingArea
78
    {
79 300
        return $this->boundingArea;
80
    }
81
82 6483
    public static function fromSRID(string $srid): self
83
    {
84 6483
        if (!isset(self::$cachedObjects[$srid])) {
85 4337
            if (isset(Projected::getSupportedSRIDs()[$srid])) {
0 ignored issues
show
Bug introduced by
The type PHPCoord\CoordinateReferenceSystem\Projected was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
86 127
                self::$cachedObjects[$srid] = Projected::fromSRID($srid);
87 4211
            } elseif (isset(Geographic2D::getSupportedSRIDs()[$srid])) {
88 3140
                self::$cachedObjects[$srid] = Geographic2D::fromSRID($srid);
89 1081
            } elseif (isset(Geographic3D::getSupportedSRIDs()[$srid])) {
90 450
                self::$cachedObjects[$srid] = Geographic3D::fromSRID($srid);
91 631
            } elseif (isset(Geocentric::getSupportedSRIDs()[$srid])) {
92 459
                self::$cachedObjects[$srid] = Geocentric::fromSRID($srid);
93 172
            } elseif (isset(Vertical::getSupportedSRIDs()[$srid])) {
94 10
                self::$cachedObjects[$srid] = Vertical::fromSRID($srid);
95 162
            } elseif (isset(Compound::getSupportedSRIDs()[$srid])) {
96
                self::$cachedObjects[$srid] = Compound::fromSRID($srid);
97
            } else {
98 162
                throw new UnknownCoordinateReferenceSystemException($srid);
99
            }
100
        }
101
102 6321
        return self::$cachedObjects[$srid];
103
    }
104
105
    public static function getSupportedSRIDs(): array
106
    {
107
        return array_merge(Compound::getSupportedSRIDs(), Geocentric::getSupportedSRIDs(), Geographic2D::getSupportedSRIDs(), Geographic3D::getSupportedSRIDs(), Projected::getSupportedSRIDs(), Vertical::getSupportedSRIDs());
108
    }
109
}
110