Passed
Push — master ( b50380...c789e7 )
by Gabriel
02:38
created

Code::getCode()   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 2
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 2
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
9
class Code implements JsonSerializable
10
{
11
    private $code;
12
    private $name;
13
    private $elements;
14
    private $creation;
15
    private $modification;
16
17
    public function __construct()
18
    {
19
        $this->elements = new Elements();
20
    }
21
22
    public function getCode(): ? string
23
    {
24
        return $this->code;
25
    }
26
27
    public function getName(): ? string
28
    {
29
        return $this->name;
30
    }
31
32
    public function getElements(): ? Elements
33
    {
34
        return $this->elements;
35
    }
36
37
    public function getCreation(): ? DateTime
38
    {
39
        return $this->creation;
40
    }
41
42
    public function getModification(): ? DateTime
43
    {
44
        return $this->modification;
45
    }
46
47
    public function reset(array $data = null)
48
    {
49
        if ($data) {
50
            foreach ($data as $key => $value) {
51
                switch ($key) {
52
                    case 'code':
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...
53
                        $this->code = $value;
54
                        break;
55
                    case 'name':
56
                        $this->name = $value;
57
                        break;
58
                    case 'elements':
59
                        $this->elements = $value;
60
                        break;
61
                    case 'creation':
62
                        $this->creation = $value;
63
                        break;
64
                    case 'modification':
65
                        $this->modification = $value;
66
                        break;
67
                }
68
            }
69
        }
70
    }
71
72
    public function jsonSerialize()
73
    {
74
        return [
75
            'code' => $this->getCode(),
76
            'elements' => $this->getElements()->jsonSerialize(),
77
        ];
78
    }
79
}
80