Passed
Push — master ( e6ff17...562f58 )
by Gabriel
02:33
created

Code   A

Complexity

Total Complexity 18

Size/Duplication

Total Lines 86
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 86.67%

Importance

Changes 0
Metric Value
wmc 18
lcom 1
cbo 1
dl 0
loc 86
ccs 39
cts 45
cp 0.8667
rs 10
c 0
b 0
f 0

10 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A __clone() 0 4 1
A getId() 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 setName() 0 4 1
A jsonSerialize() 0 11 2
1
<?php
2
3
namespace Waredesk\Models;
4
5
use DateTime;
6
use Waredesk\Collections\Codes\Elements;
7
use JsonSerializable;
8
use Waredesk\Entity;
9
use Waredesk\ReplaceableEntity;
10
11
class Code implements Entity, ReplaceableEntity, JsonSerializable
12
{
13
    private $id;
14
    private $name;
15
    private $elements;
16
    private $creation;
17
    private $modification;
18
19 4
    public function __construct(array $data = null)
20
    {
21 4
        $this->elements = new Elements();
22 4
        $this->reset($data);
23 4
    }
24
25 1
    public function __clone()
26
    {
27 1
        $this->elements = clone $this->elements;
28 1
    }
29
30 2
    public function getId(): ? string
31
    {
32 2
        return $this->id;
33
    }
34
35 2
    public function getName(): ? string
36
    {
37 2
        return $this->name;
38
    }
39
40 4
    public function getElements(): ? Elements
41
    {
42 4
        return $this->elements;
43
    }
44
45
    public function getCreation(): ?DateTime
46
    {
47
        return $this->creation;
48
    }
49
50
    public function getModification(): ? DateTime
51
    {
52
        return $this->modification;
53
    }
54
55 4
    public function reset(array $data = null)
56
    {
57 4
        if ($data) {
58 3
            foreach ($data as $key => $value) {
59
                switch ($key) {
60 3
                    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...
61 3
                        $this->id = $value;
62 3
                        break;
63 3
                    case 'name':
64 3
                        $this->name = $value;
65 3
                        break;
66 3
                    case 'variants':
67
                        $this->elements = $value;
68
                        break;
69 3
                    case 'creation':
70 3
                        $this->creation = $value;
71 3
                        break;
72 3
                    case 'modification':
73 3
                        $this->modification = $value;
74 3
                        break;
75
                }
76
            }
77
        }
78 4
    }
79
80 1
    public function setName(string $name = null)
81
    {
82 1
        $this->name = $name;
83 1
    }
84
85 2
    public function jsonSerialize(): array
86
    {
87
        $returnValue = [
88 2
            'name' => $this->getName(),
89 2
            'elements' => $this->getElements()->jsonSerialize(),
90
        ];
91 2
        if ($this->getId()) {
92 1
            $returnValue = array_merge(['id' => $this->getId()], $returnValue);
93
        }
94 2
        return $returnValue;
95
    }
96
}
97