Passing::toLonLat()   A
last analyzed

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 2
dl 0
loc 6
rs 10
ccs 5
cts 5
cp 1
crap 4
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
    protected Interfaces\INumbers $pos;
19
    protected Interfaces\IFormatted $out;
20
21 8
    public function __construct(?Interfaces\INumbers $position = null, ?Interfaces\IFormatted $output = null)
22
    {
23 8
        $this->pos = $position ?: new Support\Position();
24 8
        $this->out = $output ?: new Support\DegreesObject();
25 8
    }
26
27 4
    public function fromLonLat(Interfaces\INumbers $position, array $params): Interfaces\IFormatted
28
    {
29 4
        return (clone $this->out)->setData(
30 4
            $position->getLongitude(),
31 4
            $position->getLatitude(),
32 4
            $position->getAltitude(),
33
        );
34
    }
35
36 4
    public function toLonLat(Interfaces\IFormatted $source, array $params): Interfaces\INumbers
37
    {
38 4
        return (clone $this->pos)->setData(
39 4
            is_null($source->getLongitude()) ? null : floatval(strval($source->getLongitude())),
40 4
            is_null($source->getLatitude()) ? null : floatval(strval($source->getLatitude())),
41 4
            is_null($source->getAltitude()) ? null : floatval(strval($source->getAltitude()))
42
        );
43
    }
44
}
45