Completed
Push — master ( a54a4b...bbfdca )
by Adam
15:54
created

Order   C

Coupling/Cohesion

Components 2
Dependencies 13

Complexity

Total Complexity 61

Size/Duplication

Total Lines 401
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 61
lcom 2
cbo 13
dl 0
loc 401
rs 6.018
c 0
b 0
f 0

58 Methods

Rating   Name   Duplication   Size   Complexity  
A getProducts() 0 4 1
A setProducts() 0 4 1
A getProductTotal() 0 4 1
A setProductTotal() 0 4 1
A hasModifier() 0 4 1
A removeModifier() 0 4 1
A getModifier() 0 4 1
A getModifiers() 0 4 1
A __construct() 0 14 1
A getClient() 0 4 1
A setClient() 0 4 1
A getClientDetails() 0 4 1
A setClientDetails() 0 4 1
A getContactDetails() 0 4 1
A setContactDetails() 0 4 1
A getBillingAddress() 0 4 1
A setBillingAddress() 0 4 1
A getShippingAddress() 0 4 1
A setShippingAddress() 0 4 1
A isConfirmed() 0 4 1
A setConfirmed() 0 4 1
A getNumber() 0 4 1
A setNumber() 0 4 1
A getCurrency() 0 4 1
A setCurrency() 0 4 1
A getCurrencyRate() 0 4 1
A setCurrencyRate() 0 4 1
A getSessionId() 0 4 1
A setSessionId() 0 4 1
A getCoupon() 0 4 1
A setCoupon() 0 4 1
A getSummary() 0 4 1
A setSummary() 0 4 1
A getCurrentStatus() 0 4 1
A setCurrentStatus() 0 4 1
A getOrderStatusHistory() 0 4 1
A getComment() 0 4 1
A setComment() 0 4 1
A getPayments() 0 4 1
A acceptVisitor() 0 4 1
A isEmpty() 0 4 1
A getShippingMethodOption() 0 4 1
A setShippingMethodOption() 0 4 1
A isConditionsAccepted() 0 4 1
A setConditionsAccepted() 0 4 1
A isIssueInvoice() 0 4 1
A setIssueInvoice() 0 4 1
A getShop() 0 4 1
A setShop() 0 4 1
A getShippingMethod() 0 4 1
A setShippingMethod() 0 4 1
A getPaymentMethod() 0 4 1
A setPaymentMethod() 0 4 1
A getMinimumOrderAmount() 0 4 1
A setMinimumOrderAmount() 0 4 1
A hasMinimumValue() 0 4 1
A hasMethods() 0 4 2
A isConfirmable() 0 4 3

How to fix   Complexity   

Complex Class

Complex classes like Order often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use Order, and based on these observations, apply Extract Interface, too.

1
<?php
2
/*
3
 * WellCommerce Open-Source E-Commerce Platform
4
 *
5
 * This file is part of the WellCommerce package.
6
 *
7
 * (c) Adam Piotrowski <[email protected]>
8
 *
9
 * For the full copyright and license information,
10
 * please view the LICENSE file that was distributed with this source code.
11
 */
12
namespace WellCommerce\Bundle\OrderBundle\Entity;
13
14
use Doctrine\Common\Collections\ArrayCollection;
15
use Doctrine\Common\Collections\Collection;
16
use Knp\DoctrineBehaviors\Model\Timestampable\Timestampable;
17
use WellCommerce\Bundle\AppBundle\Entity\Client;
18
use WellCommerce\Bundle\AppBundle\Entity\ClientBillingAddress;
19
use WellCommerce\Bundle\AppBundle\Entity\ClientContactDetails;
20
use WellCommerce\Bundle\AppBundle\Entity\ClientDetails;
21
use WellCommerce\Bundle\AppBundle\Entity\ClientShippingAddress;
22
use WellCommerce\Bundle\AppBundle\Entity\MinimumOrderAmount;
23
use WellCommerce\Bundle\AppBundle\Entity\Shop;
24
use WellCommerce\Bundle\CoreBundle\Doctrine\Behaviours\Identifiable;
25
use WellCommerce\Bundle\CoreBundle\Entity\EntityInterface;
26
use WellCommerce\Bundle\CouponBundle\Entity\Coupon;
27
use WellCommerce\Bundle\OrderBundle\Entity\Extra\OrderExtraTrait;
28
use WellCommerce\Bundle\OrderBundle\Visitor\OrderVisitorInterface;
29
30
/**
31
 * Class Order
32
 *
33
 * @author  Adam Piotrowski <[email protected]>
34
 */
35
class Order implements EntityInterface
36
{
37
    use Identifiable;
38
    use Timestampable;
39
    use OrderExtraTrait;
40
    
41
    protected $confirmed            = false;
42
    protected $number               = null;
43
    protected $currency             = null;
44
    protected $currencyRate         = 1.0000;
45
    protected $sessionId            = '';
46
    protected $shippingMethodOption = null;
47
    protected $comment              = '';
48
    protected $issueInvoice         = false;
49
    protected $conditionsAccepted   = false;
50
    
51
    /**
52
     * @var null|Client
53
     */
54
    protected $client;
55
    
56
    /**
57
     * @var ClientDetails
58
     */
59
    protected $clientDetails;
60
    
61
    /**
62
     * @var ClientContactDetails
63
     */
64
    protected $contactDetails;
65
    
66
    /**
67
     * @var ClientBillingAddress
68
     */
69
    protected $billingAddress;
70
    
71
    /**
72
     * @var ClientShippingAddress
73
     */
74
    protected $shippingAddress;
75
    
76
    /**
77
     * @var Coupon
78
     */
79
    protected $coupon;
80
    
81
    /**
82
     * @var OrderStatus
83
     */
84
    protected $currentStatus;
85
    
86
    /**
87
     * @var OrderSummary
88
     */
89
    protected $summary;
90
    
91
    /**
92
     * @var OrderProductTotal
93
     */
94
    protected $productTotal;
95
    
96
    /**
97
     * @var MinimumOrderAmount
98
     */
99
    protected $minimumOrderAmount;
100
    
101
    /**
102
     * @var Collection
103
     */
104
    protected $products;
105
    
106
    /**
107
     * @var Collection
108
     */
109
    protected $payments;
110
    
111
    /**
112
     * @var Collection
113
     */
114
    protected $orderStatusHistory;
115
    
116
    /**
117
     * @var Collection
118
     */
119
    protected $modifiers;
120
    
121
    /**
122
     * @var Shop
123
     */
124
    protected $shop;
125
    
126
    /**
127
     * @var ShippingMethod
128
     */
129
    protected $shippingMethod;
130
    
131
    /**
132
     * @var PaymentMethod
133
     */
134
    protected $paymentMethod;
135
    
136
    public function __construct()
137
    {
138
        $this->products           = new ArrayCollection();
139
        $this->modifiers          = new ArrayCollection();
140
        $this->payments           = new ArrayCollection();
141
        $this->orderStatusHistory = new ArrayCollection();
142
        $this->productTotal       = new OrderProductTotal();
143
        $this->summary            = new OrderSummary();
144
        $this->clientDetails      = new ClientDetails();
145
        $this->contactDetails     = new ClientContactDetails();
146
        $this->billingAddress     = new ClientBillingAddress();
147
        $this->shippingAddress    = new ClientShippingAddress();
148
        $this->minimumOrderAmount = new MinimumOrderAmount();
149
    }
150
    
151
    public function getClient()
152
    {
153
        return $this->client;
154
    }
155
    
156
    public function setClient(Client $client = null)
157
    {
158
        $this->client = $client;
159
    }
160
    
161
    public function getClientDetails(): ClientDetails
162
    {
163
        return $this->clientDetails;
164
    }
165
    
166
    public function setClientDetails(ClientDetails $clientDetails)
167
    {
168
        $this->clientDetails = $clientDetails;
169
    }
170
    
171
    public function getContactDetails(): ClientContactDetails
172
    {
173
        return $this->contactDetails;
174
    }
175
    
176
    public function setContactDetails(ClientContactDetails $contactDetails)
177
    {
178
        $this->contactDetails = $contactDetails;
179
    }
180
    
181
    public function getBillingAddress(): ClientBillingAddress
182
    {
183
        return $this->billingAddress;
184
    }
185
    
186
    public function setBillingAddress(ClientBillingAddress $billingAddress)
187
    {
188
        $this->billingAddress = $billingAddress;
189
    }
190
    
191
    public function getShippingAddress(): ClientShippingAddress
192
    {
193
        return $this->shippingAddress;
194
    }
195
    
196
    public function setShippingAddress(ClientShippingAddress $shippingAddress)
197
    {
198
        $this->shippingAddress = $shippingAddress;
199
    }
200
    
201
    public function isConfirmed(): bool
202
    {
203
        return $this->confirmed;
204
    }
205
    
206
    public function setConfirmed(bool $confirmed)
207
    {
208
        $this->confirmed = $confirmed;
209
    }
210
    
211
    public function getNumber()
212
    {
213
        return $this->number;
214
    }
215
    
216
    public function setNumber(string $number)
217
    {
218
        $this->number = $number;
219
    }
220
    
221
    public function getCurrency(): string
222
    {
223
        return $this->currency;
224
    }
225
    
226
    public function setCurrency(string $currency)
227
    {
228
        $this->currency = $currency;
229
    }
230
    
231
    public function getCurrencyRate(): float
232
    {
233
        return $this->currencyRate;
234
    }
235
    
236
    public function setCurrencyRate(float $currencyRate)
237
    {
238
        $this->currencyRate = $currencyRate;
239
    }
240
    
241
    public function getSessionId(): string
242
    {
243
        return $this->sessionId;
244
    }
245
    
246
    public function setSessionId(string $sessionId)
247
    {
248
        $this->sessionId = $sessionId;
249
    }
250
    
251
    public function getCoupon()
252
    {
253
        return $this->coupon;
254
    }
255
    
256
    public function setCoupon(Coupon $coupon = null)
257
    {
258
        $this->coupon = $coupon;
259
    }
260
    
261
    public function getProducts(): Collection
262
    {
263
        return $this->products;
264
    }
265
    
266
    public function setProducts(Collection $products)
267
    {
268
        $this->products = $products;
269
    }
270
    
271
    public function getProductTotal(): OrderProductTotal
272
    {
273
        return $this->productTotal;
274
    }
275
    
276
    public function setProductTotal(OrderProductTotal $productTotal)
277
    {
278
        $this->productTotal = $productTotal;
279
    }
280
    
281
    public function hasModifier(string $name): bool
282
    {
283
        return $this->modifiers->containsKey($name);
284
    }
285
    
286
    public function removeModifier(string $name)
287
    {
288
        $this->modifiers->remove($name);
289
    }
290
    
291
    public function getModifier(string $name): OrderModifier
292
    {
293
        return $this->modifiers->get($name);
294
    }
295
    
296
    public function getModifiers(): Collection
297
    {
298
        return $this->modifiers;
299
    }
300
    
301
    public function getSummary(): OrderSummary
302
    {
303
        return $this->summary;
304
    }
305
    
306
    public function setSummary(OrderSummary $summary)
307
    {
308
        $this->summary = $summary;
309
    }
310
    
311
    public function getCurrentStatus()
312
    {
313
        return $this->currentStatus;
314
    }
315
    
316
    public function setCurrentStatus(OrderStatus $currentStatus = null)
317
    {
318
        $this->currentStatus = $currentStatus;
319
    }
320
    
321
    public function getOrderStatusHistory(): Collection
322
    {
323
        return $this->orderStatusHistory;
324
    }
325
    
326
    public function getComment(): string
327
    {
328
        return $this->comment;
329
    }
330
    
331
    public function setComment(string $comment)
332
    {
333
        $this->comment = $comment;
334
    }
335
    
336
    public function getPayments(): Collection
337
    {
338
        return $this->payments;
339
    }
340
    
341
    public function acceptVisitor(OrderVisitorInterface $visitor)
342
    {
343
        $visitor->visitOrder($this);
344
    }
345
    
346
    public function isEmpty(): bool
347
    {
348
        return 0 === $this->productTotal->getQuantity();
349
    }
350
    
351
    public function getShippingMethodOption()
352
    {
353
        return $this->shippingMethodOption;
354
    }
355
    
356
    public function setShippingMethodOption($shippingMethodOption)
357
    {
358
        $this->shippingMethodOption = $shippingMethodOption;
359
    }
360
    
361
    public function isConditionsAccepted(): bool
362
    {
363
        return $this->conditionsAccepted;
364
    }
365
    
366
    public function setConditionsAccepted(bool $conditionsAccepted)
367
    {
368
        $this->conditionsAccepted = $conditionsAccepted;
369
    }
370
    
371
    public function isIssueInvoice(): bool
372
    {
373
        return $this->issueInvoice;
374
    }
375
    
376
    public function setIssueInvoice(bool $issueInvoice)
377
    {
378
        $this->issueInvoice = $issueInvoice;
379
    }
380
    
381
    public function getShop(): Shop
382
    {
383
        return $this->shop;
384
    }
385
    
386
    public function setShop(Shop $shop)
387
    {
388
        $this->shop = $shop;
389
    }
390
    
391
    public function getShippingMethod()
392
    {
393
        return $this->shippingMethod;
394
    }
395
    
396
    public function setShippingMethod(ShippingMethod $shippingMethod = null)
397
    {
398
        $this->shippingMethod = $shippingMethod;
399
    }
400
    
401
    public function getPaymentMethod()
402
    {
403
        return $this->paymentMethod;
404
    }
405
    
406
    public function setPaymentMethod(PaymentMethod $paymentMethod = null)
407
    {
408
        $this->paymentMethod = $paymentMethod;
409
    }
410
    
411
    public function getMinimumOrderAmount(): MinimumOrderAmount
412
    {
413
        return $this->minimumOrderAmount;
414
    }
415
    
416
    public function setMinimumOrderAmount(MinimumOrderAmount $minimumOrderAmount)
417
    {
418
        $this->minimumOrderAmount = $minimumOrderAmount;
419
    }
420
    
421
    public function hasMinimumValue(): bool
422
    {
423
        return $this->getSummary()->getGrossAmount() >= $this->minimumOrderAmount->getValue();
424
    }
425
    
426
    public function hasMethods(): bool
427
    {
428
        return $this->shippingMethod instanceof ShippingMethod && $this->paymentMethod instanceof PaymentMethod;
429
    }
430
    
431
    public function isConfirmable(): bool
432
    {
433
        return !$this->isEmpty() && $this->hasMinimumValue() && $this->hasMethods();
434
    }
435
}
436