Passed
Push — master ( b80a23...857a85 )
by Gabriel
02:58
created

Item   A

Complexity

Total Complexity 31

Size/Duplication

Total Lines 152
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 74.12%

Importance

Changes 0
Metric Value
wmc 31
lcom 1
cbo 2
dl 0
loc 152
ccs 63
cts 85
cp 0.7412
rs 9.8
c 0
b 0
f 0

18 Methods

Rating   Name   Duplication   Size   Complexity  
A __clone() 0 5 1
A getProduct() 0 4 1
A getCreation() 0 4 1
A getModification() 0 4 1
A setWarehouse() 0 4 1
A setIsInStock() 0 4 1
A setNote() 0 4 1
A __construct() 0 6 1
A getId() 0 4 1
A getWarehouse() 0 4 1
A getVariant() 0 4 1
A getActivities() 0 4 1
A getCodes() 0 4 1
A isInStock() 0 4 1
A getNote() 0 4 1
C reset() 0 39 13
A setVariant() 0 4 1
A jsonSerialize() 0 15 2
1
<?php
2
3
namespace Waredesk\Models\Inventory;
4
5
use DateTime;
6
use JsonSerializable;
7
use Waredesk\Collections\Inventory\Items\Activities;
8
use Waredesk\Collections\Inventory\Items\Codes;
9
use Waredesk\Entity;
10
use Waredesk\ReplaceableEntity;
11
12
class Item implements Entity, ReplaceableEntity, JsonSerializable
13
{
14
    private $id;
15
    private $warehouse;
16
    private $product;
17
    private $variant;
18
    private $activities;
19
    private $codes;
20
    private $in_stock = true;
21
    private $note;
22
    private $creation;
23
    private $modification;
24
25 2
    public function __construct(array $data = null)
26
    {
27 2
        $this->activities = new Activities();
28 2
        $this->codes = new Codes();
29 2
        $this->reset($data);
30 2
    }
31
32
    public function __clone()
33
    {
34
        $this->activities = clone $this->activities;
35
        $this->codes = clone $this->codes;
36
    }
37
38 1
    public function getId(): ? string
39
    {
40 1
        return $this->id;
41
    }
42
43 1
    public function getWarehouse(): ? string
44
    {
45 1
        return $this->warehouse;
46
    }
47
48
    public function getProduct(): ? string
49
    {
50
        return $this->product;
51
    }
52
53 1
    public function getVariant(): ? string
54
    {
55 1
        return $this->variant;
56
    }
57
58 1
    public function getActivities(): Activities
59
    {
60 1
        return $this->activities;
61
    }
62
63 1
    public function getCodes(): Codes
64
    {
65 1
        return $this->codes;
66
    }
67
68 1
    public function isInStock(): ? bool
69
    {
70 1
        return $this->in_stock;
71
    }
72
73 1
    public function getNote(): ? string
74
    {
75 1
        return $this->note;
76
    }
77
78
    public function getCreation(): ? DateTime
79
    {
80
        return $this->creation;
81
    }
82
83
    public function getModification(): ? DateTime
84
    {
85
        return $this->modification;
86
    }
87
88 2
    public function reset(array $data = null)
89
    {
90 2
        if ($data) {
91 2
            foreach ($data as $key => $value) {
92
                switch ($key) {
93 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...
94 2
                        $this->id = $value;
95 2
                        break;
96 2
                    case 'warehouse':
97 2
                        $this->warehouse = $value;
98 2
                        break;
99 2
                    case 'product':
100 2
                        $this->product = $value;
101 2
                        break;
102 2
                    case 'variant':
103 2
                        $this->variant = $value;
104 2
                        break;
105 2
                    case 'activities':
106 2
                        $this->activities = $value;
107 2
                        break;
108 2
                    case 'codes':
109 2
                        $this->codes = $value;
110 2
                        break;
111 2
                    case 'in_stock':
112
                        $this->in_stock = $value;
113
                        break;
114 2
                    case 'note':
115 2
                        $this->note = $value;
116 2
                        break;
117 2
                    case 'creation':
118 2
                        $this->creation = $value;
119 2
                        break;
120 2
                    case 'modification':
121 2
                        $this->modification = $value;
122 2
                        break;
123
                }
124
            }
125
        }
126 2
    }
127
128
    public function setWarehouse(string $warehouse = null)
129
    {
130
        $this->warehouse = $warehouse;
131
    }
132
133 1
    public function setVariant(string $variant)
134
    {
135 1
        $this->variant = $variant;
136 1
    }
137
138
    public function setIsInStock(string $in_stock)
139
    {
140
        $this->in_stock = $in_stock;
0 ignored issues
show
Documentation Bug introduced by
The property $in_stock was declared of type boolean, but $in_stock is of type string. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
141
    }
142
143
    public function setNote(string $note = null)
144
    {
145
        $this->note = $note;
146
    }
147
148 1
    public function jsonSerialize(): array
149
    {
150
        $returnValue = [
151 1
            'warehouse' => $this->getWarehouse(),
152 1
            'variant' => $this->getVariant(),
153 1
            'activities' => $this->getActivities()->jsonSerialize(),
154 1
            'codes' => $this->getCodes()->jsonSerialize(),
155 1
            'in_stock' => $this->isInStock(),
156 1
            'note' => $this->getNote(),
157
        ];
158 1
        if ($this->getId()) {
159
            $returnValue = array_merge(['id' => $this->getId()], $returnValue);
160
        }
161 1
        return $returnValue;
162
    }
163
}
164