GeoJSON   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 2
dl 0
loc 23
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A format() 0 15 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Location\Formatter\Polyline;
6
7
use Location\Polyline;
8
9
/**
10
 * GeoJSON Polyline Formatter
11
 *
12
 * @author Richard Barnes <[email protected]>
13
 */
14
class GeoJSON implements FormatterInterface
15
{
16
    /**
17
     * @param Polyline $polyline
18
     *
19
     * @return string
20
     */
21
    public function format(Polyline $polyline): string
22
    {
23
        $points = [];
24
25
        foreach ($polyline->getPoints() as $point) {
26
            $points[] = [$point->getLng(), $point->getLat()];
27
        }
28
29
        return json_encode(
30
            [
31
                'type'        => 'LineString',
32
                'coordinates' => $points,
33
            ]
34
        );
35
    }
36
}
37