Passed
Push — master ( 1fa5c8...3c4917 )
by Gabriel
02:55
created

Attribute::setName()   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
rs 10
c 0
b 0
f 0
ccs 0
cts 3
cp 0
cc 1
eloc 2
nc 1
nop 1
crap 2
1
<?php
2
3
namespace Waredesk\Models\Product\Variant\Item;
4
5
use DateTime;
6
use JsonSerializable;
7
use Waredesk\Entity;
8
use Waredesk\ReplaceableEntity;
9
10
class Attribute implements Entity, ReplaceableEntity, JsonSerializable
11
{
12
    private $id;
13
    private $name;
14
    private $value;
15
    private $creation;
16
    private $modification;
17
18
    public function __clone()
19
    {
20
    }
21
22
    public function getId(): ? string
23
    {
24
        return $this->id;
25
    }
26
27
    public function getName(): ? string
28
    {
29
        return $this->name;
30
    }
31
32
    public function getValue(): ? string
33
    {
34
        return $this->value;
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 '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...
53
                        $this->id = $value;
54
                        break;
55
                    case 'name':
56
                        $this->name = $value;
57
                        break;
58
                    case 'value':
59
                        $this->value = $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 setName(string $label)
73
    {
74
        $this->name = $label;
75
    }
76
77
    public function setValue(string $value)
78
    {
79
        $this->value = $value;
80
    }
81
82
    public function jsonSerialize(): array
83
    {
84
        $returnValue = [
85
            'name' => $this->getName(),
86
            'value' => $this->getValue(),
87
        ];
88
        if ($this->getId()) {
89
            $returnValue = array_merge(['id' => $this->getId()], $returnValue);
90
        }
91
        return $returnValue;
92
    }
93
}
94