Passed
Push — 4.x ( e9b635...bc20e1 )
by Doug
07:44
created

UnitOfMeasureFactory::getSupportedSRIDs()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 1
c 0
b 0
f 0
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
cc 1
nc 1
nop 0
crap 1
1
<?php
2
/**
3
 * PHPCoord.
4
 *
5
 * @author Doug Wright
6
 */
7
declare(strict_types=1);
8
9
namespace PHPCoord\UnitOfMeasure;
10
11
use PHPCoord\Exception\UnknownUnitOfMeasureException;
12
use PHPCoord\UnitOfMeasure\Angle\Angle;
13
use PHPCoord\UnitOfMeasure\Length\Length;
14
use PHPCoord\UnitOfMeasure\Scale\Scale;
15
use PHPCoord\UnitOfMeasure\Time\Time;
16
17
class UnitOfMeasureFactory
18
{
19
    /**
20
     * @param float|string $measurement
21
     */
22 85
    public static function makeUnit($measurement, string $srid): UnitOfMeasure
23
    {
24 85
        if (isset(Angle::getSupportedSRIDs()[$srid])) {
25 21
            return Angle::makeUnit($measurement, $srid);
26
        }
27
28 64
        if (isset(Length::getSupportedSRIDs()[$srid])) {
29 47
            return Length::makeUnit($measurement, $srid);
0 ignored issues
show
Bug introduced by
It seems like $measurement can also be of type string; however, parameter $measurement of PHPCoord\UnitOfMeasure\Length\Length::makeUnit() does only seem to accept double, maybe add an additional type check? ( Ignorable by Annotation )

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

29
            return Length::makeUnit(/** @scrutinizer ignore-type */ $measurement, $srid);
Loading history...
30
        }
31
32 17
        if (isset(Scale::getSupportedSRIDs()[$srid])) {
33 4
            return Scale::makeUnit($measurement, $srid);
0 ignored issues
show
Bug introduced by
It seems like $measurement can also be of type string; however, parameter $measurement of PHPCoord\UnitOfMeasure\Scale\Scale::makeUnit() does only seem to accept double, maybe add an additional type check? ( Ignorable by Annotation )

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

33
            return Scale::makeUnit(/** @scrutinizer ignore-type */ $measurement, $srid);
Loading history...
34
        }
35
36 13
        if (isset(Time::getSupportedSRIDs()[$srid])) {
37 2
            return Time::makeUnit($measurement, $srid);
0 ignored issues
show
Bug introduced by
It seems like $measurement can also be of type string; however, parameter $measurement of PHPCoord\UnitOfMeasure\Time\Time::makeUnit() does only seem to accept double, maybe add an additional type check? ( Ignorable by Annotation )

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

37
            return Time::makeUnit(/** @scrutinizer ignore-type */ $measurement, $srid);
Loading history...
38
        }
39
40 11
        if (isset(Rate::getSupportedSRIDs()[$srid])) {
41 10
            return Rate::makeUnit($measurement, $srid);
0 ignored issues
show
Bug introduced by
It seems like $measurement can also be of type string; however, parameter $measurement of PHPCoord\UnitOfMeasure\Rate::makeUnit() does only seem to accept double, maybe add an additional type check? ( Ignorable by Annotation )

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

41
            return Rate::makeUnit(/** @scrutinizer ignore-type */ $measurement, $srid);
Loading history...
42
        }
43
44 1
        throw new UnknownUnitOfMeasureException($srid);
45
    }
46
47 1
    public static function getSupportedSRIDs(): array
48
    {
49 1
        return array_merge(Angle::getSupportedSRIDs(), Length::getSupportedSRIDs(), Scale::getSupportedSRIDs(), Time::getSupportedSRIDs(), Rate::getSupportedSRIDs());
50
    }
51
}
52