Passed
Push — master ( 144d24...fed8db )
by Petr
02:14
created

Passing::fromLonLat()   A

Complexity

Conditions 4
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 4

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
eloc 4
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 6
ccs 5
cts 5
cp 1
crap 4
rs 10
1
<?php
2
3
namespace kalanis\kw_coordinates\Codecs;
4
5
6
use kalanis\kw_coordinates\Interfaces;
7
use kalanis\kw_coordinates\Support;
8
9
10
/**
11
 * Class Passing
12
 * @package kalanis\kw_coordinates\Codecs
13
 * Just pass through
14
 * Good when you convert between more codecs and one of them is the basic format
15
 */
16
class Passing implements Interfaces\ICodecs
17
{
18
    /** @var Interfaces\INumbers */
19
    protected $pos = null;
20
    /** @var Interfaces\IFormatted */
21
    protected $out = null;
22
23 8
    public function __construct(?Interfaces\INumbers $position = null, ?Interfaces\IFormatted $output = null)
24
    {
25 8
        $this->pos = $position ?: new Support\Position();
26 8
        $this->out = $output ?: new Support\DegreesObject();
27
    }
28
29 4
    public function fromLonLat(Interfaces\INumbers $position): Interfaces\IFormatted
30
    {
31 4
        return (clone $this->out)->setData(
32 4
            is_null($position->getLongitude()) ? null : strval($position->getLongitude()),
0 ignored issues
show
introduced by
The condition is_null($position->getLongitude()) is always false.
Loading history...
33 4
            is_null($position->getLatitude()) ? null : strval($position->getLatitude()),
0 ignored issues
show
introduced by
The condition is_null($position->getLatitude()) is always false.
Loading history...
34 4
            is_null($position->getAltitude()) ? null : strval($position->getAltitude()),
0 ignored issues
show
introduced by
The condition is_null($position->getAltitude()) is always false.
Loading history...
35
        );
36
    }
37
38 4
    public function toLonLat(Interfaces\IFormatted $source): Interfaces\INumbers
39
    {
40 4
        return (clone $this->pos)->setData(
41 4
            is_null($source->getLongitude()) ? null : floatval(strval($source->getLongitude())),
0 ignored issues
show
Bug introduced by
It seems like is_null($source->getLong...ource->getLongitude())) can also be of type null; however, parameter $longitude of kalanis\kw_coordinates\I...ces\INumbers::setData() 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
            /** @scrutinizer ignore-type */ is_null($source->getLongitude()) ? null : floatval(strval($source->getLongitude())),
Loading history...
42 4
            is_null($source->getLatitude()) ? null : floatval(strval($source->getLatitude())),
0 ignored issues
show
Bug introduced by
It seems like is_null($source->getLati...source->getLatitude())) can also be of type null; however, parameter $latitude of kalanis\kw_coordinates\I...ces\INumbers::setData() 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

42
            /** @scrutinizer ignore-type */ is_null($source->getLatitude()) ? null : floatval(strval($source->getLatitude())),
Loading history...
43 4
            is_null($source->getAltitude()) ? null : floatval(strval($source->getAltitude()))
0 ignored issues
show
Bug introduced by
It seems like is_null($source->getAlti...source->getAltitude())) can also be of type null; however, parameter $altitude of kalanis\kw_coordinates\I...ces\INumbers::setData() 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

43
            /** @scrutinizer ignore-type */ is_null($source->getAltitude()) ? null : floatval(strval($source->getAltitude()))
Loading history...
44
        );
45
    }
46
}
47