1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* PHPCoord. |
4
|
|
|
* |
5
|
|
|
* @author Doug Wright |
6
|
|
|
*/ |
7
|
|
|
declare(strict_types=1); |
8
|
|
|
|
9
|
|
|
namespace PHPCoord\UnitOfMeasure\Time; |
10
|
|
|
|
11
|
|
|
use PHPCoord\Exception\UnknownUnitOfMeasureException; |
12
|
|
|
use PHPCoord\UnitOfMeasure\UnitOfMeasure; |
13
|
|
|
|
14
|
|
|
abstract class Time implements UnitOfMeasure |
15
|
|
|
{ |
16
|
|
|
/** |
17
|
|
|
* year. |
18
|
|
|
*/ |
19
|
|
|
public const EPSG_YEAR = 'urn:ogc:def:uom:EPSG::1029'; |
20
|
|
|
|
21
|
|
|
protected static array $sridData = [ |
22
|
|
|
'urn:ogc:def:uom:EPSG::1029' => [ |
23
|
|
|
'name' => 'year', |
24
|
|
|
], |
25
|
|
|
]; |
26
|
|
|
|
27
|
|
|
private static array $supportedCache = []; |
28
|
|
|
|
29
|
|
|
abstract public function asYears(): Year; |
30
|
|
|
|
31
|
9 |
|
public function add(self $unit): self |
32
|
|
|
{ |
33
|
9 |
|
$resultAsYears = new Year($this->asYears()->getValue() + $unit->asYears()->getValue()); |
34
|
9 |
|
$conversionRatio = (new static(1))->asYears()->getValue(); |
|
|
|
|
35
|
|
|
|
36
|
9 |
|
return new static($resultAsYears->getValue() / $conversionRatio); |
37
|
|
|
} |
38
|
|
|
|
39
|
27 |
|
public function subtract(self $unit): self |
40
|
|
|
{ |
41
|
27 |
|
$resultAsYears = new Year($this->asYears()->getValue() - $unit->asYears()->getValue()); |
42
|
27 |
|
$conversionRatio = (new static(1))->asYears()->getValue(); |
|
|
|
|
43
|
|
|
|
44
|
27 |
|
return new static($resultAsYears->getValue() / $conversionRatio); |
45
|
|
|
} |
46
|
|
|
|
47
|
9 |
|
public function multiply(float $multiplicand): self |
48
|
|
|
{ |
49
|
9 |
|
return new static($this->getValue() * $multiplicand); |
|
|
|
|
50
|
|
|
} |
51
|
|
|
|
52
|
9 |
|
public function divide(float $divisor): self |
53
|
|
|
{ |
54
|
9 |
|
return new static($this->getValue() / $divisor); |
|
|
|
|
55
|
|
|
} |
56
|
|
|
|
57
|
36 |
|
public static function makeUnit(float $measurement, string $srid): self |
58
|
|
|
{ |
59
|
|
|
return match ($srid) { |
60
|
36 |
|
self::EPSG_YEAR => new Year($measurement), |
61
|
36 |
|
default => throw new UnknownUnitOfMeasureException($srid), |
62
|
|
|
}; |
63
|
|
|
} |
64
|
|
|
|
65
|
36 |
|
public static function getSupportedSRIDs(): array |
66
|
|
|
{ |
67
|
36 |
|
if (!self::$supportedCache) { |
|
|
|
|
68
|
|
|
foreach (static::$sridData as $srid => $data) { |
69
|
|
|
self::$supportedCache[$srid] = $data['name']; |
70
|
|
|
} |
71
|
|
|
} |
72
|
|
|
|
73
|
36 |
|
return self::$supportedCache; |
74
|
|
|
} |
75
|
|
|
|
76
|
18 |
|
public function __toString(): string |
77
|
|
|
{ |
78
|
18 |
|
return (string) $this->getValue(); |
79
|
|
|
} |
80
|
|
|
} |
81
|
|
|
|
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.