Passed
Push — extents ( 6d8774...01b6e3 )
by Doug
61:12
created

CoordinateReferenceSystem::getName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 1
cts 1
cp 1
crap 1
rs 10
c 0
b 0
f 0
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 47137
57
    private static array $sridCache = [];
58 47137
59
    public function getSRID(): string
60
    {
61 65139
        return $this->srid;
62
    }
63 65139
64
    public function getName(): string
65
    {
66 62978
        return $this->name;
67
    }
68 62978
69
    public function getCoordinateSystem(): CoordinateSystem
70
    {
71 26
        return $this->coordinateSystem;
72
    }
73 26
74
    public function getDatum(): Datum
75
    {
76 63200
        return $this->datum;
77
    }
78 63200
79 9
    public function getBoundingArea(): BoundingArea
80 9
    {
81 9
        return $this->boundingArea;
82 9
    }
83 9
84 9
    public static function fromSRID(string $srid): self
85
    {
86
        if (!self::$sridCache) {
0 ignored issues
show
Bug Best Practice introduced by
The expression self::sridCache of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
87 63200
            self::$sridCache['projected'] = Projected::getSupportedSRIDs();
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...
88 49735
            self::$sridCache['geographic2d'] = Geographic2D::getSupportedSRIDs();
89 44424
            self::$sridCache['geographic3d'] = Geographic3D::getSupportedSRIDs();
90 5311
            self::$sridCache['geocentric'] = Geocentric::getSupportedSRIDs();
91 2393
            self::$sridCache['vertical'] = Vertical::getSupportedSRIDs();
92 2928
            self::$sridCache['compound'] = Compound::getSupportedSRIDs();
93 1764
        }
94 1164
95 657
        if (!isset(self::$cachedObjects[$srid])) {
96 507
            if (isset(self::$sridCache['projected'][$srid])) {
97 492
                self::$cachedObjects[$srid] = Projected::fromSRID($srid);
98 15
            } elseif (isset(self::$sridCache['geographic2d'][$srid])) {
99 15
                self::$cachedObjects[$srid] = Geographic2D::fromSRID($srid);
100
            } elseif (isset(self::$sridCache['geographic3d'][$srid])) {
101
                self::$cachedObjects[$srid] = Geographic3D::fromSRID($srid);
102
            } elseif (isset(self::$sridCache['geocentric'][$srid])) {
103 63200
                self::$cachedObjects[$srid] = Geocentric::fromSRID($srid);
104
            } elseif (isset(self::$sridCache['vertical'][$srid])) {
105
                self::$cachedObjects[$srid] = Vertical::fromSRID($srid);
106
            } elseif (isset(self::$sridCache['compound'][$srid])) {
107
                self::$cachedObjects[$srid] = Compound::fromSRID($srid);
108
            } else {
109
                throw new UnknownCoordinateReferenceSystemException($srid);
110
            }
111
        }
112
113
        return self::$cachedObjects[$srid];
114
    }
115
116
    public static function getSupportedSRIDs(): array
117
    {
118
        return array_merge(Compound::getSupportedSRIDs(), Geocentric::getSupportedSRIDs(), Geographic2D::getSupportedSRIDs(), Geographic3D::getSupportedSRIDs(), Projected::getSupportedSRIDs(), Vertical::getSupportedSRIDs());
119
    }
120
}
121