Passed
Push — master ( bd41e0...b80a23 )
by Gabriel
02:52
created

Code::reset()   B

Complexity

Conditions 6
Paths 6

Size

Total Lines 18
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 42

Importance

Changes 0
Metric Value
dl 0
loc 18
rs 8.8571
c 0
b 0
f 0
ccs 0
cts 13
cp 0
cc 6
eloc 13
nc 6
nop 1
crap 42
1
<?php
2
3
namespace Waredesk\Models\Inventory\Item;
4
5
use JsonSerializable;
6
use Waredesk\Entity;
7
8
class Code implements Entity, JsonSerializable
9
{
10
    private $code;
11
    private $name;
12
    private $value;
13
14
    public function __construct(array $data = null)
15
    {
16
        $this->reset($data);
17
    }
18
19
    public function __clone()
20
    {
21
    }
22
23
    public function getName(): ? string
24
    {
25
        return $this->name;
26
    }
27
28
    public function getValue(): ? string
29
    {
30
        return $this->value;
31
    }
32
33
    public function reset(array $data = null)
34
    {
35
        if ($data) {
36
            foreach ($data as $key => $value) {
37
                switch ($key) {
38
                    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...
39
                        $this->code = $value;
40
                        break;
41
                    case 'name':
42
                        $this->name = $value;
43
                        break;
44
                    case 'value':
45
                        $this->value = $value;
46
                        break;
47
                }
48
            }
49
        }
50
    }
51
52
    public function setCode(string $code)
53
    {
54
        $this->code = $code;
55
    }
56
57
    public function setValue(string $value)
58
    {
59
        $this->value = $value;
60
    }
61
62
    public function jsonSerialize(): array
63
    {
64
        $returnValue = [
65
            'code' => $this->getName(),
66
            'value' => $this->getValue(),
67
        ];
68
        return $returnValue;
69
    }
70
}
71