Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
24 / 24 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
| MultiExportJson | |
100.00% |
24 / 24 |
|
100.00% |
2 / 2 |
8 | |
100.00% |
1 / 1 |
| getType | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| parse | |
100.00% |
23 / 23 |
|
100.00% |
1 / 1 |
7 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace App\Parser\Type; |
| 6 | |
| 7 | use UnexpectedValueException; |
| 8 | use App\Parser\AbstractParser; |
| 9 | use JsonException; |
| 10 | |
| 11 | class MultiExportJson extends AbstractParser |
| 12 | { |
| 13 | protected function getType(): string |
| 14 | { |
| 15 | return 'multiexportjson'; |
| 16 | } |
| 17 | |
| 18 | /** |
| 19 | * {@inheritDoc} |
| 20 | */ |
| 21 | public function parse(array $data): array |
| 22 | { |
| 23 | $waypoints = []; |
| 24 | try { |
| 25 | $items = json_decode( |
| 26 | $data[$this->getType()], |
| 27 | true, |
| 28 | 512, |
| 29 | JSON_THROW_ON_ERROR |
| 30 | ); |
| 31 | } catch (JsonException) { |
| 32 | throw new UnexpectedValueException( |
| 33 | 'Invalid multiexport JSON data' |
| 34 | ); |
| 35 | } |
| 36 | |
| 37 | /** @var array<array{guid?: string, title?: string, coordinates: array{lat: float, lng: float}, image?: string}> $items */ |
| 38 | foreach ($items as $item) { |
| 39 | if (!$guid = $item['guid'] ?? '') { |
| 40 | continue; |
| 41 | } |
| 42 | |
| 43 | if (!$title = $item['title'] ?? '') { |
| 44 | continue; |
| 45 | } |
| 46 | |
| 47 | $lat = $item['coordinates']['lat']; |
| 48 | $lon = $item['coordinates']['lng']; |
| 49 | $image = $item['image'] ?? ''; |
| 50 | |
| 51 | if (isset($data['importImages']) && $data['importImages']) { |
| 52 | $this->wayPointHelper->checkImage($guid, $image); |
| 53 | } |
| 54 | |
| 55 | $waypoints[] = $this->createWayPoint($guid, $lat, $lon, $title, $image); |
| 56 | } |
| 57 | |
| 58 | return $waypoints; |
| 59 | } |
| 60 | } |