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

Scale   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 95
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 11
eloc 34
c 0
b 0
f 0
dl 0
loc 95
ccs 26
cts 26
cp 1
rs 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A multiply() 0 3 1
A add() 0 6 1
A __toString() 0 3 1
A makeUnit() 0 14 5
A divide() 0 3 1
A getSupportedSRIDs() 0 3 1
A subtract() 0 6 1
1
<?php
2
/**
3
 * PHPCoord.
4
 *
5
 * @author Doug Wright
6
 */
7
declare(strict_types=1);
8
9
namespace PHPCoord\UnitOfMeasure\Scale;
10
11
use PHPCoord\Exception\UnknownUnitOfMeasureException;
12
use PHPCoord\UnitOfMeasure\UnitOfMeasure;
13
14
abstract class Scale implements UnitOfMeasure
15
{
16
    /**
17
     * coefficient
18
     * Used when parameters are coefficients.  They inherently take the units which depend upon the term to which the
19
     * coefficient applies.
20
     */
21
    public const EPSG_COEFFICIENT = 'urn:ogc:def:uom:EPSG::9203';
22
23
    /**
24
     * parts per billion
25
     * Billion is internationally ambiguous, in different languages being 1E+9 and 1E+12. One billion taken here to be
26
     * 1E+9.
27
     */
28
    public const EPSG_PARTS_PER_BILLION = 'urn:ogc:def:uom:EPSG::1028';
29
30
    /**
31
     * parts per million.
32
     */
33
    public const EPSG_PARTS_PER_MILLION = 'urn:ogc:def:uom:EPSG::9202';
34
35
    /**
36
     * unity
37
     * EPSG standard unit for scale. SI coherent derived unit (standard unit) for dimensionless quantity, expressed by
38
     * the number one but this is not explicitly shown.
39
     */
40
    public const EPSG_UNITY = 'urn:ogc:def:uom:EPSG::9201';
41
42
    protected static array $sridData = [
43
        'urn:ogc:def:uom:EPSG::1028' => [
44
            'name' => 'parts per billion',
45
        ],
46
        'urn:ogc:def:uom:EPSG::9201' => [
47
            'name' => 'unity',
48
        ],
49
        'urn:ogc:def:uom:EPSG::9202' => [
50
            'name' => 'parts per million',
51
        ],
52
        'urn:ogc:def:uom:EPSG::9203' => [
53
            'name' => 'coefficient',
54
        ],
55
    ];
56
57
    abstract public function asUnity(): Unity;
58
59 4
    public function add(self $unit): self
60
    {
61 4
        $resultAsUnity = new Unity($this->asUnity()->getValue() + $unit->asUnity()->getValue());
62 4
        $conversionRatio = (new static(1))->asUnity()->getValue();
0 ignored issues
show
Unused Code introduced by
The call to PHPCoord\UnitOfMeasure\Scale\Scale::__construct() has too many arguments starting with 1. ( Ignorable by Annotation )

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

62
        $conversionRatio = (/** @scrutinizer ignore-call */ new static(1))->asUnity()->getValue();

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...
63
64 4
        return new static($resultAsUnity->getValue() / $conversionRatio);
65
    }
66
67 1
    public function subtract(self $unit): self
68
    {
69 1
        $resultAsUnity = new Unity($this->asUnity()->getValue() - $unit->asUnity()->getValue());
70 1
        $conversionRatio = (new static(1))->asUnity()->getValue();
0 ignored issues
show
Unused Code introduced by
The call to PHPCoord\UnitOfMeasure\Scale\Scale::__construct() has too many arguments starting with 1. ( Ignorable by Annotation )

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

70
        $conversionRatio = (/** @scrutinizer ignore-call */ new static(1))->asUnity()->getValue();

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...
71
72 1
        return new static($resultAsUnity->getValue() / $conversionRatio);
73
    }
74
75 4
    public function multiply(float $multiplicand): self
76
    {
77 4
        return new static($this->getValue() * $multiplicand);
0 ignored issues
show
Unused Code introduced by
The call to PHPCoord\UnitOfMeasure\Scale\Scale::__construct() has too many arguments starting with $this->getValue() * $multiplicand. ( Ignorable by Annotation )

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

77
        return /** @scrutinizer ignore-call */ new static($this->getValue() * $multiplicand);

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...
78
    }
79
80 3
    public function divide(float $divisor): self
81
    {
82 3
        return new static($this->getValue() / $divisor);
0 ignored issues
show
Unused Code introduced by
The call to PHPCoord\UnitOfMeasure\Scale\Scale::__construct() has too many arguments starting with $this->getValue() / $divisor. ( Ignorable by Annotation )

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

82
        return /** @scrutinizer ignore-call */ new static($this->getValue() / $divisor);

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...
83
    }
84
85 9
    public static function makeUnit(float $measurement, string $srid): self
86
    {
87
        switch ($srid) {
88 9
            case self::EPSG_COEFFICIENT:
89 2
                return new Coefficient($measurement);
90 7
            case self::EPSG_PARTS_PER_BILLION:
91 2
                return new PartsPerBillion($measurement);
92 5
            case self::EPSG_PARTS_PER_MILLION:
93 2
                return new PartsPerMillion($measurement);
94 3
            case self::EPSG_UNITY:
95 2
                return new Unity($measurement);
96
        }
97
98 1
        throw new UnknownUnitOfMeasureException($srid);
99
    }
100
101 19
    public static function getSupportedSRIDs(): array
102
    {
103 19
        return array_map(function ($sridData) {return $sridData['name']; }, static::$sridData);
104
    }
105
106 1
    public function __toString(): string
107
    {
108 1
        return (string) $this->getValue();
109
    }
110
}
111