Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
10 / 10
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
WayPointParser
100.00% covered (success)
100.00%
10 / 10
100.00% covered (success)
100.00%
2 / 2
5
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
 parse
100.00% covered (success)
100.00%
9 / 9
100.00% covered (success)
100.00%
1 / 1
4
1<?php
2
3declare(strict_types=1);
4
5namespace App\Parser;
6
7use App\Entity\Waypoint;
8use App\Service\WayPointHelper;
9use DirectoryIterator;
10use UnexpectedValueException;
11
12class WayPointParser
13{
14    public bool $processImages = false;
15
16    public function __construct(private readonly WayPointHelper $wayPointHelper) {}
17
18    /**
19     * @param array<string> $data
20     *
21     * @return Waypoint[]
22     */
23    public function parse(array $data): array
24    {
25        foreach (new DirectoryIterator(__DIR__.'/Type') as $item) {
26            if ($item->isDot()) {
27                continue;
28            }
29
30            $className = '\\'.__NAMESPACE__.'\\Type\\'
31                .basename($item->getFilename(), '.php');
32
33            /**
34             * @var AbstractParser $parser
35             */
36            $parser = new $className($this->wayPointHelper);
37
38            if ($parser->supports($data)) {
39                return $parser->parse($data);
40            }
41        }
42
43        throw new UnexpectedValueException('No suitable parser found :(');
44    }
45}