DetourParser::parse()   A
last analyzed

Complexity

Conditions 3
Paths 1

Size

Total Lines 11
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 9
c 1
b 0
f 0
dl 0
loc 11
ccs 10
cts 10
cp 1
rs 9.9666
cc 3
nc 1
nop 2
crap 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