Completed
Push — master ( b2620d...cacd0e )
by Gabriel
02:27
created

Code::setCreationDatetime()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 3
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 2
1
<?php
2
3
namespace Waredesk\Models\Product\Variant;
4
5
use DateTime;
6
use JsonSerializable;
7
8
class Code implements JsonSerializable
9
{
10
    private $id;
11
    private $label;
12
    private $value;
13
    private $creation_datetime;
14
    private $modification_datetime;
15
16
    public function getId(): ?int
17
    {
18
        return $this->id;
19
    }
20
21
    public function getLabel(): ?string
22
    {
23
        return $this->label;
24
    }
25
26
    public function getValue(): ?string
27
    {
28
        return $this->value;
29
    }
30
31
    public function getCreationDatetime(): ?DateTime
32
    {
33
        return $this->creation_datetime;
34
    }
35
36
    public function getModificationDatetime(): ?DateTime
37
    {
38
        return $this->modification_datetime;
39
    }
40
41
    public function reset(array $data = null)
42
    {
43
        if ($data) {
44
            foreach ($data as $key => $value) {
45
                switch ($key) {
46
                    case 'id':
0 ignored issues
show
Coding Style introduced by
case statements should be defined using a colon.

As per the PSR-2 coding standard, case statements should not be wrapped in curly braces. There is no need for braces, since each case is terminated by the next break.

There is also the option to use a semicolon instead of a colon, this is discouraged because many programmers do not even know it works and the colon is universal between programming languages.

switch ($expr) {
    case "A": { //wrong
        doSomething();
        break;
    }
    case "B"; //wrong
        doSomething();
        break;
    case "C": //right
        doSomething();
        break;
}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
47
                        $this->id = $value;
48
                        break;
49
                    case 'label':
50
                        $this->label = $value;
51
                        break;
52
                    case 'value':
53
                        $this->value = $value;
54
                        break;
55
                    case 'creation_datetime':
56
                        $this->creation_datetime = $value;
57
                        break;
58
                    case 'modification_datetime':
59
                        $this->modification_datetime = $value;
60
                        break;
61
                }
62
            }
63
        }
64
    }
65
66
    public function setLabel(string $label)
67
    {
68
        $this->label = $label;
69
    }
70
71
    public function setValue(string $value)
72
    {
73
        $this->value = $value;
74
    }
75
76
    public function jsonSerialize()
77
    {
78
        return [
79
            'label' => $this->getLabel(),
80
            'value' => $this->getValue(),
81
        ];
82
    }
83
}
84