Completed
Push — master ( b4ecb3...bd41e0 )
by Gabriel
04:57
created

Code   A

Complexity

Total Complexity 20

Size/Duplication

Total Lines 96
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 20
lcom 1
cbo 1
dl 0
loc 96
ccs 0
cts 50
cp 0
rs 10
c 0
b 0
f 0

12 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A __clone() 0 4 1
A getCode() 0 4 1
A getName() 0 4 1
A getQuantity() 0 4 1
A getElements() 0 4 1
A getCreation() 0 4 1
A getModification() 0 4 1
D reset() 0 27 9
A setCode() 0 4 1
A setQuantity() 0 4 1
A jsonSerialize() 0 8 1
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 $code;
13
    private $name;
14
    private $quantity;
15
    private $elements;
16
    private $creation;
17
    private $modification;
18
19
    public function __construct()
20
    {
21
        $this->elements = new Elements();
22
    }
23
24
    public function __clone()
25
    {
26
        $this->elements = clone $this->elements;
27
    }
28
29
    public function getCode(): ? string
30
    {
31
        return $this->code;
32
    }
33
34
    public function getName(): ? string
35
    {
36
        return $this->name;
37
    }
38
39
    public function getQuantity(): ? int
40
    {
41
        return $this->quantity;
42
    }
43
44
    public function getElements(): ? Elements
45
    {
46
        return $this->elements;
47
    }
48
49
    public function getCreation(): ? DateTime
50
    {
51
        return $this->creation;
52
    }
53
54
    public function getModification(): ? DateTime
55
    {
56
        return $this->modification;
57
    }
58
59
    public function reset(array $data = null)
60
    {
61
        if ($data) {
62
            foreach ($data as $key => $value) {
63
                switch ($key) {
64
                    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...
65
                        $this->code = $value;
66
                        break;
67
                    case 'name':
68
                        $this->name = $value;
69
                        break;
70
                    case 'quantity':
71
                        $this->quantity = $value;
72
                        break;
73
                    case 'elements':
74
                        $this->elements = $value;
75
                        break;
76
                    case 'creation':
77
                        $this->creation = $value;
78
                        break;
79
                    case 'modification':
80
                        $this->modification = $value;
81
                        break;
82
                }
83
            }
84
        }
85
    }
86
87
    public function setCode(string $code)
88
    {
89
        $this->code = $code;
90
    }
91
92
    public function setQuantity(int $quantity = null)
93
    {
94
        $this->quantity = $quantity;
95
    }
96
97
    public function jsonSerialize(): array
98
    {
99
        return [
100
            'code' => $this->getCode(),
101
            'quantity' => $this->getQuantity(),
102
            'elements' => $this->getElements()->jsonSerialize(),
103
        ];
104
    }
105
}
106