Passed
Push — master ( b80a23...857a85 )
by Gabriel
02:58
created

Code   A

Complexity

Total Complexity 13

Size/Duplication

Total Lines 63
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 43.75%

Importance

Changes 0
Metric Value
wmc 13
lcom 1
cbo 0
dl 0
loc 63
ccs 14
cts 32
cp 0.4375
rs 10
c 0
b 0
f 0

8 Methods

Rating   Name   Duplication   Size   Complexity  
A __clone() 0 3 1
A getName() 0 4 1
A getValue() 0 4 1
A setCode() 0 4 1
A setValue() 0 4 1
A jsonSerialize() 0 8 1
A __construct() 0 4 1
B reset() 0 18 6
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 2
    public function __construct(array $data = null)
15
    {
16 2
        $this->reset($data);
17 2
    }
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 2
    public function reset(array $data = null)
34
    {
35 2
        if ($data) {
36 2
            foreach ($data as $key => $value) {
37
                switch ($key) {
38 2
                    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 2
                    case 'name':
42 2
                        $this->name = $value;
43 2
                        break;
44 2
                    case 'value':
45 2
                        $this->value = $value;
46 2
                        break;
47
                }
48
            }
49
        }
50 2
    }
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