Passed
Push — main ( e110ad...47f0cd )
by Dylan
02:09
created

Order::model()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
c 0
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 0
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 array $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
     * @return string
68
     */
69
    public function FulfillmentStatus(): string
70
    {
71
        switch ($this->Status) {
72
            case Orders::FULFILLMENT_PENDING:   return 'pending';
73
            case Orders::FULFILLMENT_FULFILLED: return 'fulfilled';
74
            case Orders::FULFILLMENT_DELIVERED: return 'delivered';
75
        }
76
77
        return '';
78
    }
79
80
    /**
81
     * @return string
82
     */
83
    public function Status(): string
84
    {
85
        switch ($this->Status) {
86
            case Orders::STATUS_OPEN:   return 'open';
87
            case Orders::STATUS_PAID:   return 'paid';
88
        }
89
90
        return '';
91
    }
92
}
93