Passing   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 13
c 1
b 0
f 0
dl 0
loc 26
ccs 14
cts 14
cp 1
rs 10
wmc 8

3 Methods

Rating   Name   Duplication   Size   Complexity  
A toLonLat() 0 6 4
A fromLonLat() 0 6 1
A __construct() 0 4 3
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