Passed
Branch master (b57997)
by Doug
12:41
created

Geographic::getSupportedSRIDs()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 3
nc 2
nop 0
dl 0
loc 7
ccs 4
cts 4
cp 1
crap 2
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\Exception\UnknownCoordinateReferenceSystemException;
13
14
abstract class Geographic extends CoordinateReferenceSystem
15
{
16
    private static array $supportedCache = [];
17
18 45
    public static function fromSRID(string $srid): self
19
    {
20 45
        if (isset(Geographic2D::getSupportedSRIDs()[$srid])) {
21 27
            return Geographic2D::fromSRID($srid);
22
        }
23
24 18
        if (isset(Geographic3D::getSupportedSRIDs()[$srid])) {
25 9
            return Geographic3D::fromSRID($srid);
26
        }
27
28 9
        throw new UnknownCoordinateReferenceSystemException($srid);
29
    }
30
31 9
    public static function getSupportedSRIDs(): array
32
    {
33 9
        if (!self::$supportedCache) {
0 ignored issues
show
Bug Best Practice introduced by
The expression self::supportedCache 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...
34 9
            self::$supportedCache = array_merge(Geographic2D::getSupportedSRIDs(), Geographic3D::getSupportedSRIDs());
35
        }
36
37 9
        return self::$supportedCache;
38
    }
39
}
40