Conditions | 3 |
Paths | 3 |
Total Lines | 20 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | <?php |
||
25 | public function format(Polygon $polygon): string |
||
26 | { |
||
27 | if ($polygon->getNumberOfPoints() < 3) { |
||
28 | throw new InvalidPolygonException('A polygon must consist of at least three points.'); |
||
29 | } |
||
30 | |||
31 | $points = []; |
||
32 | |||
33 | /** @var Coordinate $point */ |
||
34 | foreach ($polygon->getPoints() as $point) { |
||
35 | $points[] = [$point->getLng(), $point->getLat()]; |
||
36 | } |
||
37 | |||
38 | return json_encode( |
||
39 | [ |
||
40 | 'type' => 'Polygon', |
||
41 | 'coordinates' => [$points], |
||
42 | ] |
||
43 | ); |
||
44 | } |
||
45 | } |
||
46 |