Completed
Push — master ( 9894be...cc7c8f )
by Tobias
21:38
created

Gpx::formatName()   A

Complexity

Conditions 4
Paths 8

Size

Total Lines 21
Code Lines 11

Duplication

Lines 6
Ratio 28.57 %

Code Coverage

Tests 10
CRAP Score 4.0119

Importance

Changes 0
Metric Value
dl 6
loc 21
ccs 10
cts 11
cp 0.9091
rs 9.0534
c 0
b 0
f 0
cc 4
eloc 11
nc 8
nop 1
crap 4.0119
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Geocoder package.
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 *
10
 * @license    MIT License
11
 */
12
13
namespace Geocoder\Dumper;
14
15
use Geocoder\Geocoder;
16
use Geocoder\Location;
17
18
/**
19
 * @author William Durand <[email protected]>
20
 */
21
final class Gpx extends AbstractDumper implements Dumper
22
{
23
    /**
24
     * @param Location $location
25
     *
26
     * @return string
27
     */
28 4
    public function dump(Location $location): string
29
    {
30 4
        $gpx = sprintf(<<<'GPX'
31 4
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
32
<gpx
33
version="1.0"
34
    creator="Geocoder" version="%s"
35
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
36
    xmlns="http://www.topografix.com/GPX/1/0"
37
    xsi:schemaLocation="http://www.topografix.com/GPX/1/0 http://www.topografix.com/GPX/1/0/gpx.xsd">
38
39
GPX
40 4
        , Geocoder::VERSION);
41
42 4
        if (null !== $bounds = $location->getBounds()) {
43 2
            $gpx .= sprintf(<<<'GPX'
44 2
    <bounds minlat="%f" minlon="%f" maxlat="%f" maxlon="%f"/>
45
46
GPX
47 2
            , $bounds->getWest(), $bounds->getSouth(), $bounds->getEast(), $bounds->getNorth());
48
        }
49
50 4
        $lat = null;
51 4
        $lon = null;
52 4
        if (null !== $coordinates = $location->getCoordinates()) {
53 3
            $lat = $coordinates->getLatitude();
54 3
            $lon = $coordinates->getLongitude();
55
        }
56
57 4
        $gpx .= sprintf(<<<'GPX'
58 4
    <wpt lat="%.7f" lon="%.7f">
59
        <name><![CDATA[%s]]></name>
60
        <type><![CDATA[Address]]></type>
61
    </wpt>
62
63
GPX
64 4
        , $lat, $lon, $this->formatName($location));
65
66
        $gpx .= <<<'GPX'
67 4
</gpx>
68
GPX;
69
70 4
        return $gpx;
71
    }
72
}
73