Passed
Pull Request — master (#6)
by Laurens
01:54
created

DateField::getMetadata()   A

Complexity

Conditions 5
Paths 16

Size

Total Lines 22

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 5

Importance

Changes 0
Metric Value
dl 0
loc 22
ccs 11
cts 11
cp 1
rs 9.2568
c 0
b 0
f 0
cc 5
nc 16
nop 0
crap 5
1
<?php
2
3
declare(strict_types=1);
4
5
namespace LauLamanApps\ApplePassbook\MetaData\Field;
6
7
use DateTimeImmutable;
8
use LauLamanApps\ApplePassbook\Exception\InvalidArgumentException;
9
use LauLamanApps\ApplePassbook\Style\DateStyle;
10
11
class DateField extends Field
12
{
13
    private DateStyle $dateStyle;
0 ignored issues
show
Bug introduced by
This code did not parse for me. Apparently, there is an error somewhere around this line:

Syntax error, unexpected T_STRING, expecting T_FUNCTION or T_CONST
Loading history...
14
    private DateStyle $timeStyle;
15
    private bool $ignoresTimeZone = false;
16
    private bool $isRelative = false;
17
18 9
    public function __construct(?string $key = null, ?DateTimeImmutable $date = null, ?string $label = null)
19
    {
20 9
        parent::__construct($key, null, $label);
21
22 9
        if ($date !== null) {
23 9
            $this->setDate($date);
24
        }
25 9
    }
26
27 9
    public function setDate(DateTimeImmutable $date): void
28
    {
29 9
        parent::setValue($date->format(DateTimeImmutable::W3C));
30 9
    }
31
32 1
    public function setDateStyle(DateStyle $dateStyle): void
33
    {
34 1
        $this->dateStyle = $dateStyle;
35 1
    }
36
37 1
    public function setTimeStyle(DateStyle $timeStyle): void
38
    {
39 1
        $this->timeStyle = $timeStyle;
40 1
    }
41
42 1
    public function ignoresTimeZone(): void
43
    {
44 1
        $this->ignoresTimeZone = true;
45 1
    }
46
47 1
    public function isRelative(): void
48
    {
49 1
        $this->isRelative = true;
50 1
    }
51
52
    /**
53
     * @return array<string>
54
     */
55 9
    public function getMetadata(): array
56
    {
57 9
        $data = parent::getMetadata();
58
59 9
        if (isset($this->dateStyle)) {
60 1
            $data['dateStyle'] = $this->dateStyle->getValue();
61
        }
62
63 9
        if (isset($this->timeStyle)) {
64 1
            $data['timeStyle'] = $this->timeStyle->getValue();
65
        }
66
67 9
        if ($this->ignoresTimeZone) {
68 1
            $data['ignoresTimeZone'] = $this->ignoresTimeZone;
69
        }
70
71 9
        if ($this->isRelative) {
72 1
            $data['isRelative'] = $this->isRelative;
73
        }
74
75 9
        return $data;
76
    }
77
}
78