Completed
Push — master ( 422de2...c9b46a )
by recca
02:36
created

Item   A

Complexity

Total Complexity 15

Size/Duplication

Total Lines 216
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 15
c 0
b 0
f 0
lcom 1
cbo 0
dl 0
loc 216
ccs 46
cts 46
cp 1
rs 10

15 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 1
A getId() 0 4 1
A setId() 0 6 1
A getName() 0 4 1
A setName() 0 6 1
A getPrice() 0 4 1
A setPrice() 0 6 1
A getQuantity() 0 4 1
A setQuantity() 0 6 1
A getAttributes() 0 4 1
A setAttributes() 0 6 1
A getTotal() 0 4 1
A total() 0 4 1
A toArray() 0 11 1
A toJson() 0 4 1
1
<?php
2
3
namespace Recca0120\Cart;
4
5
class Item
6
{
7
    /**
8
     * $id.
9
     *
10
     * @var string
11
     */
12
    public $id;
13
14
    /**
15
     * $name.
16
     *
17
     * @var string
18
     */
19
    public $name;
20
21
    /**
22
     * $price.
23
     *
24
     * @var float
25
     */
26
    public $price;
27
28
    /**
29
     * $quantity.
30
     *
31
     * @var int
32
     */
33
    public $quantity;
34
35
    /**
36
     * $attributes.
37
     *
38
     * @var array
39
     */
40
    public $attributes = [];
41
42
    /**
43
     * __construct.
44
     *
45
     * @param string $id
46
     * @param string $name
47
     * @param float $price
48
     * @param array $attributes
49
     */
50 2
    public function __construct($id, $name, $price, $quantity = 1, $attributes = [])
51
    {
52 2
        $this->setId($id)
53 2
            ->setName($name)
54 2
            ->setPrice($price)
55 2
            ->setQuantity($quantity)
56 2
            ->setAttributes($attributes);
57 2
    }
58
59
    /**
60
     * getId.
61
     *
62
     * @return string
63
     */
64 2
    public function getId()
65
    {
66 2
        return $this->id;
67
    }
68
69
    /**
70
     * setId.
71
     *
72
     * @param string $id
73
     * @return $this
74
     */
75 2
    public function setId($id)
76
    {
77 2
        $this->id = $id;
78
79 2
        return $this;
80
    }
81
82
    /**
83
     * getId.
84
     *
85
     * @return string
86
     */
87 1
    public function getName()
88
    {
89 1
        return $this->name;
90
    }
91
92
    /**
93
     * setName.
94
     *
95
     * @param string $name
96
     * @return $this
97
     */
98 2
    public function setName($name)
99
    {
100 2
        $this->name = $name;
101
102 2
        return $this;
103
    }
104
105
    /**
106
     * getPrice.
107
     *
108
     * @return float
109
     */
110 2
    public function getPrice()
111
    {
112 2
        return $this->price;
113
    }
114
115
    /**
116
     * setPrice.
117
     *
118
     * @param float $price
119
     * @return $this
120
     */
121 2
    public function setPrice($price)
122
    {
123 2
        $this->price = $price;
124
125 2
        return $this;
126
    }
127
128
    /**
129
     * getQuantity.
130
     *
131
     * @return int
132
     */
133 2
    public function getQuantity()
134
    {
135 2
        return $this->quantity;
136
    }
137
138
    /**
139
     * setQuantity.
140
     *
141
     * @param int $quantity
142
     * @return $this
143
     */
144 2
    public function setQuantity($quantity)
145
    {
146 2
        $this->quantity = $quantity;
147
148 2
        return $this;
149
    }
150
151
    /**
152
     * getAttributes.
153
     *
154
     * @return array
155
     */
156 1
    public function getAttributes()
157
    {
158 1
        return $this->attributes;
159
    }
160
161
    /**
162
     * setAttributes.
163
     *
164
     * @param array $attributes
165
     * @return $this
166
     */
167 2
    public function setAttributes($attributes)
168
    {
169 2
        $this->attributes = $attributes;
170
171 2
        return $this;
172
    }
173
174
    /**
175
     * getTotal.
176
     *
177
     * @return float
178
     */
179 1
    public function getTotal()
180
    {
181 1
        return $this->total();
182
    }
183
184
    /**
185
     * total.
186
     *
187
     * @return float
188
     */
189 2
    public function total()
190
    {
191 2
        return $this->getPrice() * $this->getQuantity();
192
    }
193
194
    /**
195
     * toArray.
196
     *
197
     * @return array
198
     */
199 1
    public function toArray()
200
    {
201
        return [
202 1
            'id' => $this->getId(),
203 1
            'name' => $this->getName(),
204 1
            'price' => $this->getPrice(),
205 1
            'quantity' => $this->getQuantity(),
206 1
            'attributes' => $this->getAttributes(),
207 1
            'total' => $this->getTotal(),
208 1
        ];
209
    }
210
211
    /**
212
     * toJson.
213
     *
214
     * @return string
215
     */
216 1
    public function toJson($option = 0)
217
    {
218 1
        return json_encode($this->toArray(), $option);
219
    }
220
}
221