Passed
Push — master ( 199ece...6bc7da )
by y
02:13
created

AbandonedCheckout   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A _setData() 0 8 1
A getDiscountCodes() 0 4 1
1
<?php
2
3
namespace Helix\Shopify;
4
5
use Helix\Shopify\AbandonedCheckout\Discount;
6
use Helix\Shopify\Base\Data;
7
use Helix\Shopify\Order\Address;
8
use Helix\Shopify\Order\OrderItem;
9
use Helix\Shopify\Order\Shipping;
10
use Helix\Shopify\Order\Tax;
11
12
/**
13
 * An abandoned checkout.
14
 *
15
 * @see https://shopify.dev/docs/admin-api/rest/reference/orders/abandoned-checkouts
16
 *
17
 * @method string       getAbandonedCheckoutUrl ()
18
 * @method Address      getBillingAddress       ()
19
 * @method bool         getBuyerAcceptsMarketing()
20
 * @method string       getCartToken            ()
21
 * @method string       getClosedAt             ()
22
 * @method string       getCreatedAt            ()
23
 * @method string       getCurrency             ()
24
 * @method Customer     getCustomer             ()
25
 * @method string       getCustomerLocale       ()
26
 * @method int          getDeviceId             ()
27
 * @method string       getEmail                ()
28
 * @method string       getLandingSite          ()
29
 * @method OrderItem[]  getLineItems            ()
30
 * @method int          getLocationId           ()
31
 * @method string       getNote                 ()
32
 * @method string       getPhone                ()
33
 * @method string       getPresentmentCurrency  ()
34
 * @method string       getReferringSite        ()
35
 * @method Address      getShippingAddress      ()
36
 * @method Shipping[]   getShippingLines        ()
37
 * @method string       getSourceName           ()
38
 * @method string       getSubtotalPrice        ()
39
 * @method Tax[]        getTaxLines             ()
40
 * @method bool         hasTaxesIncluded        ()
41
 * @method string       getToken                ()
42
 * @method string       getTotalDiscounts       ()
43
 * @method string       getTotalLineItemsPrice  ()
44
 * @method string       getTotalPrice           ()
45
 * @method string       getTotalTax             ()
46
 * @method number       getTotalWeight          ()
47
 * @method string       getUpdatedAt            ()
48
 * @method string       getUserId               ()
49
 */
50
class AbandonedCheckout extends Data {
51
52
    const SEARCH_STATUS_CLOSED = 'closed';
53
    const SEARCH_STATUS_OPEN = 'open';
54
55
    const MAP = [
56
        'billing_address' => Address::class,
57
        'customer' => Customer::class,
58
        'line_items' => [OrderItem::class],
59
        'shipping_address' => Address::class,
60
        'shipping_lines' => Shipping::class,
61
        'tax_lines' => [Tax::class]
62
    ];
63
64
    protected function _setData (array $data) {
65
        // abandoned checkouts aren't entities.
66
        unset($data['id']);
67
68
        // always null
69
        unset($data['completed_at'], $data['gateway']);
70
71
        return parent::_setData($data);
72
    }
73
74
    /**
75
     * @return Discount[]
76
     */
77
    public function getDiscountCodes () {
78
        // the discounts are in an extra dimension for some reason.
79
        $discounts = array_column($this->data['discount_codes'], 'discount_code');
80
        return $this->api->factoryAll($this, Discount::class, $discounts);
81
    }
82
}