PeriodParser::parse()   A
last analyzed

Complexity

Conditions 5
Paths 2

Size

Total Lines 25
Code Lines 20

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 13
CRAP Score 6.7117

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 20
c 1
b 0
f 0
dl 0
loc 25
ccs 13
cts 22
cp 0.5909
rs 9.2888
cc 5
nc 2
nop 2
crap 6.7117
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Swis\Melvin\Parsers;
6
7
use Swis\Melvin\Enums\PeriodStatus;
8
use Swis\Melvin\Models\Period;
9
use Swis\Melvin\Models\Week;
10
11
class PeriodParser
12
{
13 6
    public function parse(\stdClass $object, int $index): Period
14
    {
15 6
        if ($repeatingAt = $object->repeatingAt ?? null) {
16
            $repeatingAt = new Week(
17
                $repeatingAt[0],
18
                $repeatingAt[1],
19
                $repeatingAt[2],
20
                $repeatingAt[3],
21
                $repeatingAt[4],
22
                $repeatingAt[5],
23
                $repeatingAt[6]
24
            );
25
        }
26
27 6
        return new Period(
28 6
            $object->id,
29 6
            ($object->name ?? '') ?: sprintf('Uitvoerperiode %d', $index + 1),
30 6
            new \DateTime($object->startDateActual ?? $object->startDate, new \DateTimeZone('UTC')),
31 6
            ($endDate = $object->endDateActual ?? $object->endDate ?? null) ? new \DateTime($endDate, new \DateTimeZone('UTC')) : null,
32 6
            ($object->repeating ?? '') === 'WEEKLY',
33 3
            $repeatingAt,
34 6
            ($object->status ?? null) ? PeriodStatus::from($object->status) : null,
35 6
            $object->overrunning ?? null,
36 6
            $object->order ?? $index,
37 6
            $object->parentId ?? null
38 3
        );
39
    }
40
}
41