Completed
Push — master ( 4e457c...e6ff17 )
by Gabriel
02:37
created

Code   A

Complexity

Total Complexity 17

Size/Duplication

Total Lines 81
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 17
lcom 1
cbo 1
dl 0
loc 81
ccs 0
cts 41
cp 0
rs 10
c 0
b 0
f 0

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