AbstractOrder::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 7
ccs 6
cts 6
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 5
nc 1
nop 1
crap 1
1
<?php
2
3
namespace WSW\SiftScience\Events;
4
5
use InvalidArgumentException;
6
use WSW\Email\Email;
7
use WSW\Money\Money;
8
use WSW\SiftScience\Collections\Items;
9
use WSW\SiftScience\Collections\PaymentMethods;
10
use WSW\SiftScience\Collections\Promotions;
11
use WSW\SiftScience\Entities\Address;
12
use WSW\SiftScience\Entities\Item;
13
use WSW\SiftScience\Entities\PaymentMethod;
14
use WSW\SiftScience\Entities\Promotion;
15
use WSW\SiftScience\Support\AllowedValues\ShippingMethod;
16
17
/**
18
 * Class AbstractOrder
19
 *
20
 * @package WSW\SiftScience\Events
21
 * @author Ronaldo Matos Rodrigues <[email protected]>
22
 */
23
abstract class AbstractOrder extends BaseEvent
24
{
25
26
    /**
27
     * @var string
28
     */
29
    private $order;
30
31
    /**
32
     * @var Email
33
     */
34
    private $userEmail;
35
36
    /**
37
     * @var Money
38
     */
39
    private $amount;
40
41
    /**
42
     * @var Address
43
     */
44
    private $billingAddress;
45
46
    /**
47
     * @var PaymentMethods
48
     */
49
    private $paymentMethods;
50
51
    /**
52
     * @var Address
53
     */
54
    private $shippingAddress;
55
56
    /**
57
     * @var bool
58
     */
59
    private $expeditedShipping = false;
60
61
    /**
62
     * @var string
63
     */
64
    private $shippingMethod;
65
66
    /**
67
     * @var Items
68
     */
69
    private $items;
70
71
    /**
72
     * @var string
73
     */
74
    private $sellerUserId;
75
76
    /**
77
     * @var Promotions
78
     */
79
    private $promotions;
80
81
    /**
82
     * @param string $type
83
     */
84 17
    public function __construct($type)
85
    {
86 17
        $this->type = $type;
87 17
        $this->items = new Items();
88 17
        $this->paymentMethods = new PaymentMethods();
89 17
        $this->promotions = new Promotions();
90 17
    }
91
92
    /**
93
     * @return string
94
     */
95 5
    public function getOrder()
96
    {
97 5
        return $this->order;
98
    }
99
100
    /**
101
     * @param string $order
102
     *
103
     * @return $this
104
     */
105 1
    public function setOrder($order)
106
    {
107 1
        $this->order = $order;
108
109 1
        return $this;
110
    }
111
112
    /**
113
     * @return Email
114
     */
115 5
    public function getUserEmail()
116
    {
117 5
        return $this->userEmail;
118
    }
119
120
    /**
121
     * @param Email $userEmail
122
     *
123
     * @return $this
124
     */
125 1
    public function setUserEmail(Email $userEmail)
126
    {
127 1
        $this->userEmail = $userEmail;
128
129 1
        return $this;
130
    }
131
132
    /**
133
     * @return Money
134
     */
135 5
    public function getAmount()
136
    {
137 5
        return $this->amount;
138
    }
139
140
    /**
141
     * @param Money $amount
142
     *
143
     * @return $this
144
     */
145 1
    public function setAmount(Money $amount)
146
    {
147 1
        $this->amount = $amount;
148
149 1
        return $this;
150
    }
151
152
    /**
153
     * @return Address
154
     */
155 5
    public function getBillingAddress()
156
    {
157 5
        return $this->billingAddress;
158
    }
159
160
    /**
161
     * @param Address $billingAddress
162
     *
163
     * @return $this
164
     */
165 1
    public function setBillingAddress(Address $billingAddress)
166
    {
167 1
        $this->billingAddress = $billingAddress;
168
169 1
        return $this;
170
    }
171
172
    /**
173
     * @return PaymentMethods
174
     */
175 5
    public function getPaymentMethods()
176
    {
177 5
        return $this->paymentMethods;
178
    }
179
180
    /**
181
     * @param PaymentMethod $paymentMethod
182
     *
183
     * @return $this
184
     */
185 1
    public function addPaymentMethod(PaymentMethod $paymentMethod)
186
    {
187 1
        $this->paymentMethods->add($paymentMethod);
188
189 1
        return $this;
190
    }
191
192
    /**
193
     * @return Address
194
     */
195 5
    public function getShippingAddress()
196
    {
197 5
        return $this->shippingAddress;
198
    }
199
200
    /**
201
     * @param Address $shippingAddress
202
     *
203
     * @return $this
204
     */
205 1
    public function setShippingAddress(Address $shippingAddress)
206
    {
207 1
        $this->shippingAddress = $shippingAddress;
208
209 1
        return $this;
210
    }
211
212
    /**
213
     * @return bool
214
     */
215 5
    public function isExpeditedShipping()
216
    {
217 5
        return (bool) $this->expeditedShipping;
218
    }
219
220
    /**
221
     * @param bool $expeditedShipping
222
     *
223
     * @return $this
224
     */
225 1
    public function setExpeditedShipping($expeditedShipping)
226
    {
227 1
        $this->expeditedShipping = (bool) $expeditedShipping;
228
229 1
        return $this;
230
    }
231
232
    /**
233
     * @return string
234
     */
235 5
    public function getShippingMethod()
236
    {
237 5
        return $this->shippingMethod;
238
    }
239
240
    /**
241
     * @param string $shippingMethod
242
     *
243
     * @return $this
244
     */
245 2
    public function setShippingMethod($shippingMethod)
246
    {
247 2
        if (!ShippingMethod::isValid($shippingMethod)) {
248 1
            throw new InvalidArgumentException('You should inform a valid shipping method.');
249
        }
250
251 1
        $this->shippingMethod = $shippingMethod;
252
253 1
        return $this;
254
    }
255
256
    /**
257
     * @return Items
258
     */
259 5
    public function getItems()
260
    {
261 5
        return $this->items;
262
    }
263
264
    /**
265
     * @param Item $item
266
     *
267
     * @return $this
268
     */
269 1
    public function addItem(Item $item)
270
    {
271 1
        $this->items->add($item);
272
273 1
        return $this;
274
    }
275
276
    /**
277
     * @return string
278
     */
279 5
    public function getSellerUserId()
280
    {
281 5
        return $this->sellerUserId;
282
    }
283
284
    /**
285
     * @param string $sellerUserId
286
     *
287
     * @return $this
288
     */
289 1
    public function setSellerUserId($sellerUserId)
290
    {
291 1
        $this->sellerUserId = $sellerUserId;
292
293 1
        return $this;
294
    }
295
296
    /**
297
     * @return Promotions
298
     */
299 5
    public function getPromotions()
300
    {
301 5
        return $this->promotions;
302
    }
303
304
    /**
305
     * @param Promotion $promotion
306
     *
307
     * @return $this
308
     */
309 1
    public function addPromotion(Promotion $promotion)
310
    {
311 1
        $this->promotions->add($promotion);
312
313 1
        return $this;
314
    }
315
}
316