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
|
|
|
private static array $supportedCache = []; |
58
|
|
|
|
59
|
|
|
abstract public function asUnity(): Unity; |
60
|
|
|
|
61
|
36 |
|
public function add(self $unit): self |
62
|
|
|
{ |
63
|
36 |
|
$resultAsUnity = new Unity($this->asUnity()->getValue() + $unit->asUnity()->getValue()); |
64
|
36 |
|
$conversionRatio = (new static(1))->asUnity()->getValue(); |
|
|
|
|
65
|
|
|
|
66
|
36 |
|
return new static($resultAsUnity->getValue() / $conversionRatio); |
67
|
|
|
} |
68
|
|
|
|
69
|
9 |
|
public function subtract(self $unit): self |
70
|
|
|
{ |
71
|
9 |
|
$resultAsUnity = new Unity($this->asUnity()->getValue() - $unit->asUnity()->getValue()); |
72
|
9 |
|
$conversionRatio = (new static(1))->asUnity()->getValue(); |
|
|
|
|
73
|
|
|
|
74
|
9 |
|
return new static($resultAsUnity->getValue() / $conversionRatio); |
75
|
|
|
} |
76
|
|
|
|
77
|
36 |
|
public function multiply(float $multiplicand): self |
78
|
|
|
{ |
79
|
36 |
|
return new static($this->getValue() * $multiplicand); |
|
|
|
|
80
|
|
|
} |
81
|
|
|
|
82
|
27 |
|
public function divide(float $divisor): self |
83
|
|
|
{ |
84
|
27 |
|
return new static($this->getValue() / $divisor); |
|
|
|
|
85
|
|
|
} |
86
|
|
|
|
87
|
260 |
|
public static function makeUnit(float $measurement, string $srid): self |
88
|
|
|
{ |
89
|
|
|
return match ($srid) { |
90
|
260 |
|
self::EPSG_COEFFICIENT => new Coefficient($measurement), |
91
|
242 |
|
self::EPSG_PARTS_PER_BILLION => new PartsPerBillion($measurement), |
92
|
224 |
|
self::EPSG_PARTS_PER_MILLION => new PartsPerMillion($measurement), |
93
|
143 |
|
self::EPSG_UNITY => new Unity($measurement), |
94
|
260 |
|
default => throw new UnknownUnitOfMeasureException($srid), |
95
|
|
|
}; |
96
|
|
|
} |
97
|
|
|
|
98
|
27 |
|
public static function getSupportedSRIDs(): array |
99
|
|
|
{ |
100
|
27 |
|
if (!self::$supportedCache) { |
|
|
|
|
101
|
|
|
foreach (static::$sridData as $srid => $data) { |
102
|
|
|
self::$supportedCache[$srid] = $data['name']; |
103
|
|
|
} |
104
|
|
|
} |
105
|
|
|
|
106
|
27 |
|
return self::$supportedCache; |
107
|
|
|
} |
108
|
|
|
|
109
|
9 |
|
public function __toString(): string |
110
|
|
|
{ |
111
|
9 |
|
return (string) $this->getValue(); |
112
|
|
|
} |
113
|
|
|
} |
114
|
|
|
|
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.