Order   A
last analyzed

Complexity

Total Complexity 15

Size/Duplication

Total Lines 60
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 15
eloc 30
c 1
b 0
f 0
dl 0
loc 60
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A FulfillmentType() 0 9 4
A Status() 0 8 3
B formatPrice() 0 13 8
1
<?php
2
3
namespace Lifeboat\Models;
4
5
use Lifeboat\Resource\ObjectResource;
6
use Lifeboat\Services\Orders;
7
8
/**
9
 * Class Order
10
 * @package Lifeboat\Models
11
 *
12
 * @property string $Status
13
 * @property string $Fulfillment
14
 * @property string|null $DiscountCode
15
 * @property \DateTime|string|null $Created
16
 * @property \DateTime|string|null $LastModified
17
 * @property string $OID
18
 * @property float $Subtotal
19
 * @property float $Tax
20
 * @property float $Delivery
21
 * @property float $Handling
22
 * @property float $Discount
23
 * @property float $Total
24
 * @property \DateTime|string|null $PaidOn
25
 * @property \DateTime|string|null $DeliveredOn
26
 * @property string $PaymentMethod
27
 * @property string $Provider
28
 * @property int $FulfillmentType
29
 * @property array $Discounts
30
 * @property string $Currency
31
 * @property array $Products
32
 * @property ObjectResource|null $ShipTo
33
 * @property ObjectResource|null $BillTo
34
 * @property array $Waypoints
35
 * @property ObjectResource|null $Route
36
 */
37
class Order extends Model {
38
39
    protected static $casting = [
40
        'Created'       => 'lifeboat_date_formatter',
41
        'LastModified'  => 'lifeboat_date_formatter',
42
        'Subtotal'      => 'floatval',
43
        'Tax'           => 'floatval',
44
        'Delivery'      => 'floatval',
45
        'Handling'      => 'floatval',
46
        'Discount'      => 'floatval',
47
        'Total'         => 'floatval',
48
        'PaidOn'        => 'lifeboat_date_formatter',
49
        'DeliveredOn'   => 'lifeboat_date_formatter',
50
    ];
51
52
    /**
53
     * @return string
54
     */
55
    public function FulfillmentType(): string
56
    {
57
        switch ($this->FulfillmentType) {
58
            case Orders::FULFILLMENT_SHIP:      return 'ship';
59
            case Orders::FULFILLMENT_DELIVER:   return 'deliver';
60
            case Orders::FULFILLMENT_PICKUP:    return 'pickup';
61
        }
62
63
        return '';
64
    }
65
66
67
    /**
68
     * @return string
69
     */
70
    public function Status(): string
71
    {
72
        switch ($this->Status) {
73
            case Orders::STATUS_OPEN:   return 'open';
74
            case Orders::STATUS_PAID:   return 'paid';
75
        }
76
77
        return '';
78
    }
79
80
    /**
81
     * @param string $price
82
     * @return string
83
     */
84
    public function formatPrice(string $price): string
85
    {
86
        switch (strtolower($price)) {
87
            case 'subtotal' : $value = $this->Subtotal; break;
88
            case 'tax'      : $value = $this->Tax; break;
89
            case 'delivery' : $value = $this->Delivery; break;
90
            case 'handling' : $value = $this->Handling; break;
91
            case 'discount' : $value = $this->Discount; break;
92
            case 'total'    : $value = $this->Total; break;
93
            default: return '';
94
        }
95
96
        return ($value !== 0) ?  number_format($value, 2) . $this->Currency : '-';
0 ignored issues
show
introduced by
The condition $value !== 0 is always true.
Loading history...
97
    }
98
}
99