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

UnitOfMeasureFactory   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 7
eloc 13
c 1
b 0
f 0
dl 0
loc 33
ccs 14
cts 14
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getSupportedSRIDs() 0 3 1
A makeUnit() 0 23 6
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