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

Element::reset()   B

Complexity

Conditions 7
Paths 7

Size

Total Lines 21
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 16
CRAP Score 7

Importance

Changes 0
Metric Value
dl 0
loc 21
ccs 16
cts 16
cp 1
rs 7.551
c 0
b 0
f 0
cc 7
eloc 16
nc 7
nop 1
crap 7
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\Image;
11
12
class Element implements JsonSerializable
13
{
14
    private $id;
15
    private $type;
16
    private $default_value;
17
    private $auto_increment;
18
19
    public function getId(): ? string
20
    {
21
        return $this->id;
22
    }
23
24 1
    public function getType(): ? string
25
    {
26 1
        return $this->type;
27
    }
28
29 1
    public function getDefaultValue(): ? string
30
    {
31 1
        return $this->default_value;
32
    }
33
34 1
    public function getAutoIncrement(): ? bool
35
    {
36 1
        return $this->auto_increment;
37
    }
38
39 2
    public function reset(array $data = null)
40
    {
41 2
        if ($data) {
42 2
            foreach ($data as $key => $value) {
43
                switch ($key) {
44 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...
45 2
                        $this->id = $value;
46 2
                        break;
47 2
                    case 'type':
48 2
                        $this->type = $value;
49 2
                        break;
50 2
                    case 'default_value':
51 2
                        $this->default_value = $value;
52 2
                        break;
53 2
                    case 'auto_increment':
54 2
                        $this->auto_increment = $value;
55 2
                        break;
56
                }
57
            }
58
        }
59 2
    }
60
61 1
    public function setType(string $type)
62
    {
63 1
        $this->type = $type;
64 1
    }
65
66
    public function setDefaultValue(string $default_value = null)
67
    {
68
        $this->default_value = $default_value;
69
    }
70
71
    public function setAutoIncrement(bool $auto_increment = null)
72
    {
73
        $this->auto_increment = $auto_increment;
74
    }
75
76 1
    public function jsonSerialize()
77
    {
78
        return [
79 1
            'type' => $this->getType(),
80 1
            'default_value' => $this->getDefaultValue(),
81 1
            'auto_increment' => $this->getAutoIncrement(),
82
        ];
83
    }
84
}
85