Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
14 / 14
100.00% covered (success)
100.00%
4 / 4
CRAP
100.00% covered (success)
100.00%
1 / 1
AbstractParser
100.00% covered (success)
100.00%
14 / 14
100.00% covered (success)
100.00%
4 / 4
7
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getType
n/a
0 / 0
n/a
0 / 0
0
 parse
n/a
0 / 0
n/a
0 / 0
0
 supports
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
1 / 1
3
 check
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
2
 createWayPoint
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3declare(strict_types=1);
4
5namespace App\Parser;
6
7use App\Entity\Waypoint;
8use App\Service\WayPointHelper;
9use UnexpectedValueException;
10
11abstract class AbstractParser
12{
13    public bool $processImages = false;
14
15    public function __construct(protected WayPointHelper $wayPointHelper) {}
16
17    abstract protected function getType(): string;
18
19    /**
20     * @param array<string> $data
21     *
22     * @return Waypoint[]
23     */
24    abstract public function parse(array $data): array;
25
26    /**
27     * @param array<string> $data
28     */
29    public function supports(array $data): bool
30    {
31        $type = $this->gettype();
32
33        if ($type === '' || $type === '0') {
34            throw new UnexpectedValueException(
35                'Type is not set in class '.self::class
36            );
37        }
38
39        return $this->check($type, $data);
40    }
41
42    /**
43     * @param array<string> $data
44     */
45    protected function check(string $key, array $data): bool
46    {
47        return array_key_exists($key, $data) && $data[$key];
48    }
49
50    protected function createWayPoint(
51        string $guid,
52        float $lat,
53        float $lon,
54        string $name,
55        string $image,
56    ): Waypoint
57    {
58        return new Waypoint()
59            ->setGuid($guid)
60            ->setName($name)
61            ->setLat($lat)
62            ->setLon($lon)
63            ->setImage($image);
64    }
65}