Test Failed
Push — master ( e5d517...cfa2aa )
by Laurens
01:33
created

DateField::setDate()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 1
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
    /**
14
     * @var DateStyle|null
15
     */
16
    private $dateStyle;
17
18
    /**
19
     * @var DateStyle|null;
20
     */
21
    private $timeStyle;
22
23
    /**
24
     * @var bool
25
     */
26
    private $ignoresTimeZone = false;
27
28
    /**
29
     * @var bool
30
     */
31
    private $isRelative = false;
32
33 9
    public function __construct(?string $key = null, ?DateTimeImmutable $date = null, ?string $label = null)
34
    {
35 9
        parent::__construct($key, null, $label);
36
37 9
        if ($date !== null) {
38 9
            $this->setDate($date);
39
        }
40 9
    }
41
42 9
    public function setDate(DateTimeImmutable $date): void
43
    {
44 9
        parent::setValue($date->format(DateTimeImmutable::W3C));
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (setValue() instead of setDate()). Are you sure this is correct? If so, you might want to change this to $this->setValue().

This check looks for a call to a parent method whose name is different than the method from which it is called.

Consider the following code:

class Daddy
{
    protected function getFirstName()
    {
        return "Eidur";
    }

    protected function getSurName()
    {
        return "Gudjohnsen";
    }
}

class Son
{
    public function getFirstName()
    {
        return parent::getSurname();
    }
}

The getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
45 9
    }
46
47 1
    public function setDateStyle(DateStyle $dateStyle): void
48
    {
49 1
        $this->dateStyle = $dateStyle;
50 1
    }
51
52 1
    public function setTimeStyle(DateStyle $timeStyle): void
53
    {
54 1
        $this->timeStyle = $timeStyle;
55 1
    }
56
57 1
    public function ignoresTimeZone(): void
58
    {
59 1
        $this->ignoresTimeZone = true;
60 1
    }
61
62 1
    public function isRelative(): void
63
    {
64 1
        $this->isRelative = true;
65 1
    }
66
67 9
    public function getMetadata(): array
68
    {
69 9
        $data = parent::getMetadata();
70
71 9
        if ($this->dateStyle) {
72 1
            $data['dateStyle'] = $this->dateStyle->getValue();
73
        }
74
75 9
        if ($this->timeStyle) {
76 1
            $data['timeStyle'] = $this->timeStyle->getValue();
77
        }
78
79 9
        if ($this->ignoresTimeZone) {
80 1
            $data['ignoresTimeZone'] = $this->ignoresTimeZone;
81
        }
82
83 9
        if ($this->isRelative) {
84 1
            $data['isRelative'] = $this->isRelative;
85
        }
86
87 9
        return $data;
88
    }
89
}
90