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

Element::jsonSerialize()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 11
ccs 7
cts 7
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 8
nc 1
nop 0
crap 1
1
<?php
2
3
namespace Waredesk\Models\Code;
4
5
use DateTime;
6
use JsonSerializable;
7
use Waredesk\Collections\Products\Variants\Annotations;
8
use Waredesk\Collections\Products\Variants\Codes;
9
use Waredesk\Collections\Products\Variants\Prices;
10
use Waredesk\Entity;
11
use Waredesk\Image;
12
use Waredesk\ReplaceableEntity;
13
14
class Element implements Entity, ReplaceableEntity, JsonSerializable
15
{
16
    private $id;
17
    private $type;
18
    private $value;
19
    private $auto_increment;
20
    private $pad_direction;
21
    private $pad_char;
22
    private $pad_length;
23
24 1
    public function __clone()
25
    {
26 1
    }
27
28 1
    public function getId(): ? string
29
    {
30 1
        return $this->id;
31
    }
32
33 1
    public function getType(): ? string
34
    {
35 1
        return $this->type;
36
    }
37
38 2
    public function getValue(): ? string
39
    {
40 2
        return $this->value;
41
    }
42
43 1
    public function getAutoIncrement(): ? bool
44
    {
45 1
        return $this->auto_increment;
46
    }
47
48 1
    public function getPadDirection(): ? string
49
    {
50 1
        return $this->pad_direction;
51
    }
52
53 1
    public function getPadChar(): ? string
54
    {
55 1
        return $this->pad_char;
56
    }
57
58 1
    public function getPadLength(): ? int
59
    {
60 1
        return $this->pad_length;
61
    }
62
63 2
    public function reset(array $data = null)
64
    {
65 2
        if ($data) {
66 2
            foreach ($data as $key => $value) {
67
                switch ($key) {
68 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...
69 2
                        $this->id = $value;
70 2
                        break;
71 2
                    case 'type':
72 2
                        $this->type = $value;
73 2
                        break;
74 2
                    case 'value':
75 2
                        $this->value = $value;
76 2
                        break;
77 2
                    case 'auto_increment':
78 2
                        $this->auto_increment = $value;
79 2
                        break;
80 2
                    case 'pad_direction':
81 2
                        $this->pad_direction = $value;
82 2
                        break;
83 2
                    case 'pad_char':
84 2
                        $this->pad_char = $value;
85 2
                        break;
86 2
                    case 'pad_length':
87 2
                        $this->pad_length = $value;
88 2
                        break;
89
                }
90
            }
91
        }
92 2
    }
93
94 1
    public function setType(string $type)
95
    {
96 1
        $this->type = $type;
97 1
    }
98
99 1
    public function setValue(string $value = null)
100
    {
101 1
        $this->value = $value;
102 1
    }
103
104
    public function setAutoIncrement(bool $auto_increment = null)
105
    {
106
        $this->auto_increment = $auto_increment;
107
    }
108
109
    public function setPadDirection(string $pad_direction = null)
110
    {
111
        $this->pad_direction = $pad_direction;
112
    }
113
114
    public function setPadChar(string $pad_char = null)
115
    {
116
        $this->pad_char = $pad_char;
117
    }
118
119
    public function setPadLength(int $pad_length = null)
120
    {
121
        $this->pad_length = $pad_length;
122
    }
123
124 1
    public function jsonSerialize()
125
    {
126
        return [
127 1
            'type' => $this->getType(),
128 1
            'value' => $this->getValue(),
129 1
            'auto_increment' => $this->getAutoIncrement(),
130 1
            'pad_direction' => $this->getPadDirection(),
131 1
            'pad_char' => $this->getPadChar(),
132 1
            'pad_length' => $this->getPadLength(),
133
        ];
134
    }
135
}
136