Passed
Push — master ( 6a435f...dad6c0 )
by Doug
13:08
created

CoordinateReferenceSystem   A

Complexity

Total Complexity 14

Size/Duplication

Total Lines 93
Duplicated Lines 0 %

Test Coverage

Coverage 87.5%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 45
c 1
b 0
f 0
dl 0
loc 93
ccs 28
cts 32
cp 0.875
rs 10
wmc 14

6 Methods

Rating   Name   Duplication   Size   Complexity  
A getDatum() 0 3 1
A getSRID() 0 3 1
A getCoordinateSystem() 0 3 1
A getBoundingArea() 0 3 1
A getSupportedSRIDs() 0 3 1
B fromSRID() 0 28 9
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\Geometry\BoundingArea;
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
    protected BoundingArea $boundingArea;
51
52
    private static array $cachedObjects = [];
53
54
    private static array $sridCache = [];
55
56 1510
    public function getSRID(): string
57
    {
58 1510
        return $this->srid;
59
    }
60
61 2184
    public function getCoordinateSystem(): CoordinateSystem
62
    {
63 2184
        return $this->coordinateSystem;
64
    }
65
66 1368
    public function getDatum(): Datum
67
    {
68 1368
        return $this->datum;
69
    }
70
71 11
    public function getBoundingArea(): BoundingArea
72
    {
73 11
        return $this->boundingArea;
74
    }
75
76 245
    public static function fromSRID(string $srid): self
77
    {
78 245
        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...
79 9
            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...
80 9
            self::$sridCache['geographic2d'] = Geographic2D::getSupportedSRIDs();
81 9
            self::$sridCache['geographic3d'] = Geographic3D::getSupportedSRIDs();
82 9
            self::$sridCache['geocentric'] = Geocentric::getSupportedSRIDs();
83 9
            self::$sridCache['vertical'] = Vertical::getSupportedSRIDs();
84 9
            self::$sridCache['compound'] = Compound::getSupportedSRIDs();
85
        }
86
87 245
        if (!isset(self::$cachedObjects[$srid])) {
88 146
            if (isset(self::$sridCache['projected'][$srid])) {
89 45
                self::$cachedObjects[$srid] = Projected::fromSRID($srid);
90 101
            } elseif (isset(self::$sridCache['geographic2d'][$srid])) {
91 73
                self::$cachedObjects[$srid] = Geographic2D::fromSRID($srid);
92 38
            } elseif (isset(self::$sridCache['geographic3d'][$srid])) {
93 19
                self::$cachedObjects[$srid] = Geographic3D::fromSRID($srid);
94 19
            } elseif (isset(self::$sridCache['geocentric'][$srid])) {
95 9
                self::$cachedObjects[$srid] = Geocentric::fromSRID($srid);
96 10
            } elseif (isset(self::$sridCache['vertical'][$srid])) {
97 10
                self::$cachedObjects[$srid] = Vertical::fromSRID($srid);
98
            } elseif (isset(self::$sridCache['compound'][$srid])) {
99
                self::$cachedObjects[$srid] = Compound::fromSRID($srid);
100
            }
101
        }
102
103 245
        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