Completed
Push — master ( 743367...2eb0ee )
by Gabriel
06:30
created

Item::getAttributes()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 1
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\Attributes;
9
use Waredesk\Collections\Inventory\Items\Codes;
10
use Waredesk\Entity;
11
use Waredesk\ReplaceableEntity;
12
13
class Item implements Entity, ReplaceableEntity, JsonSerializable
14
{
15
    private $id;
16
    private $warehouse;
17
    private $product;
18
    private $variant;
19
    private $activities;
20
    private $attributes;
21
    private $in_stock = true;
22
    private $note;
23
    private $creation;
24
    private $modification;
25
26 2
    public function __construct(array $data = null)
27
    {
28 2
        $this->activities = new Activities();
29 2
        $this->attributes = new Attributes();
30 2
        $this->reset($data);
31 2
    }
32
33
    public function __clone()
34
    {
35
        $this->activities = clone $this->activities;
36
        $this->attributes = clone $this->attributes;
37
    }
38
39 1
    public function getId(): ? string
40
    {
41 1
        return $this->id;
42
    }
43
44 1
    public function getWarehouse(): ? string
45
    {
46 1
        return $this->warehouse;
47
    }
48
49
    public function getProduct(): ? string
50
    {
51
        return $this->product;
52
    }
53
54 1
    public function getVariant(): ? string
55
    {
56 1
        return $this->variant;
57
    }
58
59 1
    public function getActivities(): Activities
60
    {
61 1
        return $this->activities;
62
    }
63
64 1
    public function getAttributes(): Attributes
65
    {
66 1
        return $this->attributes;
67
    }
68
69 1
    public function isInStock(): ? bool
70
    {
71 1
        return $this->in_stock;
72
    }
73
74 1
    public function getNote(): ? string
75
    {
76 1
        return $this->note;
77
    }
78
79
    public function getCreation(): ? DateTime
80
    {
81
        return $this->creation;
82
    }
83
84
    public function getModification(): ? DateTime
85
    {
86
        return $this->modification;
87
    }
88
89 2
    public function reset(array $data = null)
90
    {
91 2
        if ($data) {
92 2
            foreach ($data as $key => $value) {
93
                switch ($key) {
94 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...
95 2
                        $this->id = $value;
96 2
                        break;
97 2
                    case 'warehouse':
98 2
                        $this->warehouse = $value;
99 2
                        break;
100 2
                    case 'product':
101 2
                        $this->product = $value;
102 2
                        break;
103 2
                    case 'variant':
104 2
                        $this->variant = $value;
105 2
                        break;
106 2
                    case 'activities':
107 2
                        $this->activities = $value;
108 2
                        break;
109 2
                    case 'attributes':
110 2
                        $this->attributes = $value;
111 2
                        break;
112 2
                    case 'in_stock':
113
                        $this->in_stock = $value;
114
                        break;
115 2
                    case 'note':
116 2
                        $this->note = $value;
117 2
                        break;
118 2
                    case 'creation':
119 2
                        $this->creation = $value;
120 2
                        break;
121 2
                    case 'modification':
122 2
                        $this->modification = $value;
123 2
                        break;
124
                }
125
            }
126
        }
127 2
    }
128
129
    public function setWarehouse(string $warehouse = null)
130
    {
131
        $this->warehouse = $warehouse;
132
    }
133
134 1
    public function setVariant(string $variant)
135
    {
136 1
        $this->variant = $variant;
137 1
    }
138
139
    public function setIsInStock(string $in_stock)
140
    {
141
        $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...
142
    }
143
144
    public function setNote(string $note = null)
145
    {
146
        $this->note = $note;
147
    }
148
149 1
    public function jsonSerialize(): array
150
    {
151
        $returnValue = [
152 1
            'warehouse' => $this->getWarehouse(),
153 1
            'variant' => $this->getVariant(),
154 1
            'activities' => $this->getActivities()->jsonSerialize(),
155 1
            'attributes' => $this->getAttributes()->jsonSerialize(),
156 1
            'in_stock' => $this->isInStock(),
157 1
            'note' => $this->getNote(),
158
        ];
159 1
        if ($this->getId()) {
160
            $returnValue = array_merge(['id' => $this->getId()], $returnValue);
161
        }
162 1
        return $returnValue;
163
    }
164
}
165