Passed
Push — 4.x ( c37faa...bd875a )
by Doug
12:53
created

CoordinateReferenceSystem   A

Complexity

Total Complexity 14

Size/Duplication

Total Lines 113
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 14
eloc 59
c 1
b 0
f 0
dl 0
loc 113
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
B fromEPSGCode() 0 56 11
A getDatum() 0 3 1
A getEpsgCode() 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 PHPCoord\CoordinateSystem\CoordinateSystem;
12
use PHPCoord\Datum\Datum;
13
use PHPCoord\EPSG\Repository;
14
use PHPCoord\Exception\UnknownCoordinateReferenceSystemException;
15
16
abstract class CoordinateReferenceSystem implements CoordinateReferenceSystemIds
0 ignored issues
show
Bug introduced by
The type PHPCoord\CoordinateRefer...inateReferenceSystemIds 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...
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
    /** @var int */
43
    protected $epsgCode;
44
45
    /** @var CoordinateSystem */
46
    protected $coordinateSystem;
47
48
    /** @var Datum */
49
    protected $datum;
50
51
    /** @var CoordinateReferenceSystem */
52
    protected $baseCRS;
53
54
    /** @var Repository */
55
    private static $repository;
56
57
    public static function fromEPSGCode(int $epsgCode): self
58
    {
59
        $repository = static::$repository ?? new Repository();
0 ignored issues
show
Bug introduced by
Since $repository is declared private, accessing it with static will lead to errors in possible sub-classes; you can either use self, or increase the visibility of $repository to at least protected.
Loading history...
60
        $allData = $repository->getCoordinateReferenceSystems(true);
0 ignored issues
show
Unused Code introduced by
The call to PHPCoord\EPSG\Repository...inateReferenceSystems() has too many arguments starting with true. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

60
        /** @scrutinizer ignore-call */ 
61
        $allData = $repository->getCoordinateReferenceSystems(true);

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
61
62
        if (!isset($allData[$epsgCode])) {
63
            throw new UnknownCoordinateReferenceSystemException($epsgCode);
64
        }
65
66
        $data = $allData[$epsgCode];
67
68
        switch ($data['coord_ref_sys_kind']) {
69
            case self::CRS_TYPE_GEOCENTRIC:
70
                return new Geocentric(
71
                    $epsgCode,
72
                    CoordinateSystem::fromEPSGCode($data['coord_sys_code']),
73
                    $data['datum_code'] ? Datum::fromEPSGCode($data['datum_code']) : self::fromEPSGCode($data['base_crs_code'])->getDatum()
74
                );
75
76
            case self::CRS_TYPE_GEOGRAPHIC_2D:
77
                return new Geographic2D(
78
                    $epsgCode,
79
                    CoordinateSystem::fromEPSGCode($data['coord_sys_code']),
80
                    $data['datum_code'] ? Datum::fromEPSGCode($data['datum_code']) : self::fromEPSGCode($data['base_crs_code'])->getDatum()
81
                );
82
83
            case self::CRS_TYPE_GEOGRAPHIC_3D:
84
                return new Geographic3D(
85
                    $epsgCode,
86
                    CoordinateSystem::fromEPSGCode($data['coord_sys_code']),
87
                    $data['datum_code'] ? Datum::fromEPSGCode($data['datum_code']) : self::fromEPSGCode($data['base_crs_code'])->getDatum()
88
                );
89
90
            case self::CRS_TYPE_PROJECTED:
91
                return new Projected(
92
                    $epsgCode,
93
                    CoordinateSystem::fromEPSGCode($data['coord_sys_code']),
94
                    self::fromEPSGCode($data['base_crs_code'])
95
                );
96
97
            case self::CRS_TYPE_VERTICAL:
98
                return new Vertical(
99
                    $epsgCode,
100
                    CoordinateSystem::fromEPSGCode($data['coord_sys_code']),
101
                    Datum::fromEPSGCode($data['datum_code'])
102
                );
103
104
            case self::CRS_TYPE_COMPOUND:
105
                return new Compound(
106
                    $epsgCode,
107
                    self::fromEPSGCode($data['cmpd_horizcrs_code']),
108
                    self::fromEPSGCode($data['cmpd_vertcrs_code'])
109
                );
110
111
            default:
112
                throw new UnknownCoordinateReferenceSystemException($epsgCode);
113
        }
114
    }
115
116
    public function getEpsgCode(): int
117
    {
118
        return $this->epsgCode;
119
    }
120
121
    public function getCoordinateSystem(): CoordinateSystem
122
    {
123
        return $this->coordinateSystem;
124
    }
125
126
    public function getDatum(): Datum
127
    {
128
        return $this->datum;
129
    }
130
}
131