Passed
Push — master ( 1fa5c8...3c4917 )
by Gabriel
02:55
created

Variable::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
ccs 4
cts 4
cp 1
cc 1
eloc 3
nc 1
nop 1
crap 1
1
<?php
2
3
namespace Waredesk\Models;
4
5
use DateTime;
6
use Waredesk\Collections\Variables\Elements;
7
use JsonSerializable;
8
use Waredesk\Entity;
9
use Waredesk\ReplaceableEntity;
10
11
class Variable implements Entity, ReplaceableEntity, JsonSerializable
12
{
13
    private $id;
14
    private $name;
15
    private $elements;
16
    private $creation;
17
    private $modification;
18
19 3
    public function __construct(array $data = null)
20
    {
21 3
        $this->elements = new Elements();
22 3
        $this->reset($data);
23 3
    }
24
25 1
    public function __clone()
26
    {
27 1
        $this->elements = clone $this->elements;
28 1
    }
29
30 1
    public function getId(): ? string
31
    {
32 1
        return $this->id;
33
    }
34
35 1
    public function getName(): ? string
36
    {
37 1
        return $this->name;
38
    }
39
40 3
    public function getElements(): ? Elements
41
    {
42 3
        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 3
    public function reset(array $data = null)
56
    {
57 3
        if ($data) {
58 2
            foreach ($data as $key => $value) {
59
                switch ($key) {
60 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...
61 2
                        $this->id = $value;
62 2
                        break;
63 2
                    case 'name':
64 2
                        $this->name = $value;
65 2
                        break;
66 2
                    case 'elements':
67 2
                        $this->elements = $value;
68 2
                        break;
69 2
                    case 'creation':
70 2
                        $this->creation = $value;
71 2
                        break;
72 2
                    case 'modification':
73 2
                        $this->modification = $value;
74 2
                        break;
75
                }
76
            }
77
        }
78 3
    }
79
80 1
    public function setName(string $name = null)
81
    {
82 1
        $this->name = $name;
83 1
    }
84
85 1
    public function jsonSerialize(): array
86
    {
87
        $returnValue = [
88 1
            'name' => $this->getName(),
89 1
            'elements' => $this->getElements()->jsonSerialize(),
90
        ];
91 1
        if ($this->getId()) {
92
            $returnValue = array_merge(['id' => $this->getId()], $returnValue);
93
        }
94 1
        return $returnValue;
95
    }
96
}
97