Code::reset()   D
last analyzed

Complexity

Conditions 9
Paths 9

Size

Total Lines 27
Code Lines 22

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 90

Importance

Changes 0
Metric Value
dl 0
loc 27
ccs 0
cts 22
cp 0
rs 4.909
c 0
b 0
f 0
cc 9
eloc 22
nc 9
nop 1
crap 90
1
<?php
2
3
namespace Waredesk\Models\Product\Variant;
4
5
use DateTime;
6
use JsonSerializable;
7
use Waredesk\Collections\Products\Variants\Codes\Elements;
8
use Waredesk\Entity;
9
10
class Code implements Entity, JsonSerializable
11
{
12
    private $id;
13
    private $type;
14
    private $custom_type;
15
    private $value;
16
    private $creation;
17
    private $modification;
18
19
    public function __construct()
20
    {
21
    }
22
23
    public function __clone()
24
    {
25
    }
26
27
    public function getId(): ? string
28
    {
29
        return $this->id;
30
    }
31
32
    public function getType(): ? string
33
    {
34
        return $this->type;
35
    }
36
37
    public function getCustomType(): ? string
38
    {
39
        return $this->custom_type;
40
    }
41
42
    public function getValue(): ? string
43
    {
44
        return $this->value;
45
    }
46
47
    public function getCreation(): ? DateTime
48
    {
49
        return $this->creation;
50
    }
51
52
    public function getModification(): ? DateTime
53
    {
54
        return $this->modification;
55
    }
56
57
    public function reset(array $data = null)
58
    {
59
        if ($data) {
60
            foreach ($data as $key => $value) {
61
                switch ($key) {
62
                    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...
63
                        $this->id = $value;
64
                        break;
65
                    case 'type':
66
                        $this->type = $value;
67
                        break;
68
                    case 'custom_type':
69
                        $this->custom_type = $value;
70
                        break;
71
                    case 'value':
72
                        $this->value = $value;
73
                        break;
74
                    case 'creation':
75
                        $this->creation = $value;
76
                        break;
77
                    case 'modification':
78
                        $this->modification = $value;
79
                        break;
80
                }
81
            }
82
        }
83
    }
84
85
    public function setType(string $type = null)
86
    {
87
        $this->type = $type;
88
    }
89
90
    public function setCustomType(string $custom_type = null)
91
    {
92
        $this->custom_type = $custom_type;
93
    }
94
95
    public function setValue(string $value)
96
    {
97
        $this->value = $value;
98
    }
99
100
    public function jsonSerialize(): array
101
    {
102
        $returnValue = [
103
            'type' => $this->getType(),
104
            'custom_type' => $this->getCustomType(),
105
            'value' => $this->getValue(),
106
        ];
107
        if ($this->getId()) {
108
            $returnValue = array_merge(['id' => $this->getId()], $returnValue);
109
        }
110
        return $returnValue;
111
    }
112
}
113