DetourParser   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 17
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
eloc 10
c 1
b 0
f 0
dl 0
loc 17
ccs 12
cts 12
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 2 1
A parse() 0 11 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Swis\Melvin\Parsers;
6
7
use Swis\Melvin\Enums\BoatType;
8
use Swis\Melvin\Enums\Direction;
9
use Swis\Melvin\Enums\TransportMode;
10
use Swis\Melvin\Enums\VehicleType;
11
use Swis\Melvin\Models\Detour;
12
13
class DetourParser
14
{
15 6
    public function __construct(protected GeometryParser $geometryParser)
16
    {
17 6
    }
18
19 6
    public function parse(\stdClass $object, int $index): Detour
20
    {
21 6
        return new Detour(
22 6
            $object->id,
23 6
            str_contains($object->properties->type, '_EXTERNAL'),
24 6
            $this->geometryParser->parse($object->geometry),
25 6
            ($object->properties->name ?? '') ?: sprintf('Omleiding %d', $index + 1),
26 6
            Direction::from($object->properties->direction),
27 6
            !empty($object->properties->transportMode) ? TransportMode::from($object->properties->transportMode) : null,
28 6
            array_map([VehicleType::class, 'from'], $object->properties->vehicleTypes),
29 6
            array_map([BoatType::class, 'from'], $object->properties->boatTypes)
30 3
        );
31
    }
32
}
33