Completed
Push — master ( e6ba08...9dbf89 )
by Gabriel
02:34
created

Code   A

Complexity

Total Complexity 16

Size/Duplication

Total Lines 77
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 84.62%

Importance

Changes 0
Metric Value
wmc 16
lcom 1
cbo 1
dl 0
loc 77
ccs 33
cts 39
cp 0.8462
rs 10
c 0
b 0
f 0

9 Methods

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