DecimalDegrees   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 1
dl 0
loc 51
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A format() 0 9 1
A setSeparator() 0 6 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Location\Formatter\Coordinate;
6
7
use Location\Coordinate;
8
9
/**
10
 * Coordinate Formatter "Decimal Degrees"
11
 *
12
 * @author Marcus Jaschen <[email protected]>
13
 */
14
class DecimalDegrees implements FormatterInterface
15
{
16
    /**
17
     * @var string Separator string between latitude and longitude
18
     */
19
    protected $separator;
20
21
    /**
22
     * @var int
23
     */
24
    protected $digits = 5;
25
26
    /**
27
     * @param string $separator
28
     * @param int $digits
29
     */
30
    public function __construct(string $separator = ' ', int $digits = 5)
31
    {
32
        $this->separator = $separator;
33
        $this->digits    = $digits;
34
    }
35
36
    /**
37
     * @param Coordinate $coordinate
38
     *
39
     * @return string
40
     */
41
    public function format(Coordinate $coordinate): string
42
    {
43
        return sprintf(
44
            '%.' . $this->digits . 'f%s%.' . $this->digits . 'f',
45
            $coordinate->getLat(),
46
            $this->separator,
47
            $coordinate->getLng()
48
        );
49
    }
50
51
    /**
52
     * Sets the separator between latitude and longitude values
53
     *
54
     * @param string $separator
55
     *
56
     * @return $this
57
     */
58
    public function setSeparator(string $separator): DecimalDegrees
59
    {
60
        $this->separator = $separator;
61
62
        return $this;
63
    }
64
}
65