Passed
Push — master ( fd93b5...48e916 )
by Doug
40:26 queued 29:39
created

Time::__toString()   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 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
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\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();
0 ignored issues
show
Unused Code introduced by
The call to PHPCoord\UnitOfMeasure\Time\Time::__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

34
        $conversionRatio = (/** @scrutinizer ignore-call */ new static(1))->asYears()->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...
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();
0 ignored issues
show
Unused Code introduced by
The call to PHPCoord\UnitOfMeasure\Time\Time::__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

42
        $conversionRatio = (/** @scrutinizer ignore-call */ new static(1))->asYears()->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...
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);
0 ignored issues
show
Unused Code introduced by
The call to PHPCoord\UnitOfMeasure\Time\Time::__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

49
        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...
50
    }
51
52 9
    public function divide(float $divisor): self
53
    {
54 9
        return new static($this->getValue() / $divisor);
0 ignored issues
show
Unused Code introduced by
The call to PHPCoord\UnitOfMeasure\Time\Time::__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

54
        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...
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) {
0 ignored issues
show
Bug Best Practice introduced by
The expression self::supportedCache of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
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