Passed
Push — master ( 2c19f0...d4552d )
by Doug
46:35
created

CoordinateReferenceSystem::fromSRID()   B

Complexity

Conditions 8
Paths 8

Size

Total Lines 21
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 16
CRAP Score 8

Importance

Changes 0
Metric Value
cc 8
eloc 16
c 0
b 0
f 0
nc 8
nop 1
dl 0
loc 21
ccs 16
cts 16
cp 1
crap 8
rs 8.4444
1
<?php
2
/**
3
 * PHPCoord.
4
 *
5
 * @author Doug Wright
6
 */
7
declare(strict_types=1);
8
9
namespace PHPCoord\CoordinateReferenceSystem;
10
11
use PHPCoord\CoordinateSystem\CoordinateSystem;
12
use PHPCoord\Datum\Datum;
13
use PHPCoord\Exception\UnknownCoordinateReferenceSystemException;
14
use PHPCoord\Geometry\BoundingArea;
15
16
use function array_merge;
17
18
abstract class CoordinateReferenceSystem
19
{
20
    public const CRS_TYPE_COMPOUND = 'compound';
21
22
    public const CRS_TYPE_DERIVED = 'derived';
23
24
    public const CRS_TYPE_DYNAMIC_GEOCENTRIC = 'dynamic geocentric';
25
26
    public const CRS_TYPE_DYNAMIC_GEOGRAPHIC_2D = 'dynamic geographic 2D';
27
28
    public const CRS_TYPE_DYNAMIC_GEOGRAPHIC_3D = 'dynamic geographic 3D';
29
30
    public const CRS_TYPE_DYNAMIC_VERTICAL = 'dynamic vertical';
31
32
    public const CRS_TYPE_ENGINEERING = 'engineering';
33
34
    public const CRS_TYPE_GEOCENTRIC = 'geocentric';
35
36
    public const CRS_TYPE_GEOGRAPHIC_2D = 'geographic 2D';
37
38
    public const CRS_TYPE_GEOGRAPHIC_3D = 'geographic 3D';
39
40
    public const CRS_TYPE_PROJECTED = 'projected';
41
42
    public const CRS_TYPE_VERTICAL = 'vertical';
43
44
    public const CRS_SRID_PREFIX_EPSG = 'urn:ogc:def:crs:EPSG::';
45
46
    protected string $srid;
47
48
    protected string $name;
49
50
    protected CoordinateSystem $coordinateSystem;
51
52
    protected Datum $datum;
53
54
    protected BoundingArea $boundingArea;
55
56
    private static array $cachedObjects = [];
57
58 5328
    public function getSRID(): string
59
    {
60 5328
        return $this->srid;
61
    }
62
63 9126
    public function getName(): string
64
    {
65 9126
        return $this->name;
66
    }
67
68 11450
    public function getCoordinateSystem(): CoordinateSystem
69
    {
70 11450
        return $this->coordinateSystem;
71
    }
72
73 15231
    public function getDatum(): Datum
74
    {
75 15231
        return $this->datum;
76
    }
77
78 414
    public function getBoundingArea(): BoundingArea
79
    {
80 414
        return $this->boundingArea;
81
    }
82
83 6385
    public static function fromSRID(string $srid): Compound|Geocentric|Geographic2D|Geographic3D|Projected|Vertical
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...
84
    {
85 6385
        if (!isset(self::$cachedObjects[$srid])) {
86 4446
            if (isset(Projected::getSupportedSRIDs()[$srid])) {
87 235
                self::$cachedObjects[$srid] = Projected::fromSRID($srid);
88 4212
            } elseif (isset(Geographic2D::getSupportedSRIDs()[$srid])) {
89 3140
                self::$cachedObjects[$srid] = Geographic2D::fromSRID($srid);
90 1082
            } elseif (isset(Geographic3D::getSupportedSRIDs()[$srid])) {
91 450
                self::$cachedObjects[$srid] = Geographic3D::fromSRID($srid);
92 632
            } elseif (isset(Geocentric::getSupportedSRIDs()[$srid])) {
93 459
                self::$cachedObjects[$srid] = Geocentric::fromSRID($srid);
94 173
            } elseif (isset(Vertical::getSupportedSRIDs()[$srid])) {
95 10
                self::$cachedObjects[$srid] = Vertical::fromSRID($srid);
96 163
            } elseif (isset(Compound::getSupportedSRIDs()[$srid])) {
97 1
                self::$cachedObjects[$srid] = Compound::fromSRID($srid);
98
            } else {
99 162
                throw new UnknownCoordinateReferenceSystemException($srid);
100
            }
101
        }
102
103 6223
        return self::$cachedObjects[$srid];
104
    }
105
106
    public static function getSupportedSRIDs(): array
107
    {
108
        return array_merge(Compound::getSupportedSRIDs(), Geocentric::getSupportedSRIDs(), Geographic2D::getSupportedSRIDs(), Geographic3D::getSupportedSRIDs(), Projected::getSupportedSRIDs(), Vertical::getSupportedSRIDs());
109
    }
110
}
111