Completed
Push — master ( 134b2d...f2c57a )
by Gabriel
02:40
created

Category   A

Complexity

Total Complexity 19

Size/Duplication

Total Lines 89
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 78.26%

Importance

Changes 0
Metric Value
wmc 19
lcom 1
cbo 0
dl 0
loc 89
ccs 36
cts 46
cp 0.7826
rs 10
c 0
b 0
f 0

11 Methods

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