ManagesOrders   A
last analyzed

Complexity

Total Complexity 33

Size/Duplication

Total Lines 177
Duplicated Lines 0 %

Importance

Changes 3
Bugs 1 Features 0
Metric Value
wmc 33
eloc 40
c 3
b 1
f 0
dl 0
loc 177
rs 9.76

33 Methods

Rating   Name   Duplication   Size   Complexity  
A getDraftOrdersCount() 0 3 1
A openOrder() 0 5 1
A completeDraftOrder() 0 5 1
A getDraftOrder() 0 3 1
A createOrder() 0 3 1
A createOrderRisk() 0 3 1
A getOrderRefund() 0 3 1
A getOrder() 0 3 1
A getOrdersCount() 0 3 1
A sendDraftOrderInvoice() 0 5 1
A cancelOrder() 0 5 1
A getDraftOrders() 0 3 1
A getOrderTransactions() 0 3 1
A deleteDraftOrder() 0 3 1
A getOrderRisk() 0 3 1
A createOrderTransaction() 0 3 1
A getOrderRefunds() 0 3 1
A updateOrderRisk() 0 3 1
A createOrderRefund() 0 3 1
A deleteOrder() 0 3 1
A paginateDraftOrders() 0 3 1
A deleteOrderRisk() 0 3 1
A calculateOrderRefund() 0 5 1
A getOrders() 0 3 1
A createDraftOrder() 0 3 1
A paginateOrders() 0 3 1
A getCheckouts() 0 3 1
A getOrderRisks() 0 3 1
A getOrderTransactionsCount() 0 3 1
A updateDraftOrder() 0 3 1
A updateOrder() 0 3 1
A closeOrder() 0 5 1
A getCheckoutsCount() 0 3 1
1
<?php
2
3
namespace Signifly\Shopify\REST\Actions;
4
5
use Illuminate\Support\Collection;
6
use Signifly\Shopify\REST\Cursor;
7
use Signifly\Shopify\REST\Resources\ApiResource;
8
use Signifly\Shopify\REST\Resources\DraftOrderResource;
9
use Signifly\Shopify\REST\Resources\OrderResource;
10
use Signifly\Shopify\REST\Resources\RefundResource;
11
use Signifly\Shopify\REST\Resources\RiskResource;
12
use Signifly\Shopify\REST\Resources\TransactionResource;
13
use Signifly\Shopify\Shopify;
14
15
/** @mixin Shopify */
16
trait ManagesOrders
17
{
18
    public function createOrder(array $data): OrderResource
19
    {
20
        return $this->createResource('orders', $data);
0 ignored issues
show
Bug introduced by
It seems like createResource() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

20
        return $this->/** @scrutinizer ignore-call */ createResource('orders', $data);
Loading history...
21
    }
22
23
    public function getOrdersCount(array $params = []): int
24
    {
25
        return $this->getResourceCount('orders', $params);
0 ignored issues
show
Bug introduced by
It seems like getResourceCount() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

25
        return $this->/** @scrutinizer ignore-call */ getResourceCount('orders', $params);
Loading history...
26
    }
27
28
    public function paginateOrders(array $params = []): Cursor
29
    {
30
        return $this->cursor($this->getOrders($params));
0 ignored issues
show
Bug introduced by
It seems like cursor() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

30
        return $this->/** @scrutinizer ignore-call */ cursor($this->getOrders($params));
Loading history...
31
    }
32
33
    public function getOrders(array $params = []): Collection
34
    {
35
        return $this->getResources('orders', $params);
0 ignored issues
show
Bug introduced by
It seems like getResources() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

35
        return $this->/** @scrutinizer ignore-call */ getResources('orders', $params);
Loading history...
36
    }
37
38
    public function getOrder($orderId): OrderResource
39
    {
40
        return $this->getResource('orders', $orderId);
0 ignored issues
show
Bug introduced by
It seems like getResource() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

40
        return $this->/** @scrutinizer ignore-call */ getResource('orders', $orderId);
Loading history...
41
    }
42
43
    public function updateOrder($orderId, $data): OrderResource
44
    {
45
        return $this->updateResource('orders', $orderId, $data);
0 ignored issues
show
Bug introduced by
It seems like updateResource() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

45
        return $this->/** @scrutinizer ignore-call */ updateResource('orders', $orderId, $data);
Loading history...
46
    }
47
48
    public function deleteOrder($orderId): void
49
    {
50
        $this->deleteResource('orders', $orderId);
0 ignored issues
show
Bug introduced by
It seems like deleteResource() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

50
        $this->/** @scrutinizer ignore-call */ 
51
               deleteResource('orders', $orderId);
Loading history...
51
    }
52
53
    public function closeOrder($orderId): OrderResource
54
    {
55
        $response = $this->post("orders/{$orderId}/close.json");
0 ignored issues
show
Bug introduced by
It seems like post() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

55
        /** @scrutinizer ignore-call */ 
56
        $response = $this->post("orders/{$orderId}/close.json");
Loading history...
56
57
        return new OrderResource($response['order'], $this);
58
    }
59
60
    public function openOrder($orderId): OrderResource
61
    {
62
        $response = $this->post("orders/{$orderId}/open.json");
63
64
        return new OrderResource($response['order'], $this);
65
    }
66
67
    public function cancelOrder($orderId): OrderResource
68
    {
69
        $response = $this->post("orders/{$orderId}/cancel.json");
70
71
        return new OrderResource($response['order'], $this);
72
    }
73
74
    public function createOrderRisk($orderId, array $data): RiskResource
75
    {
76
        return $this->createResource('risks', $data, ['orders', $orderId]);
77
    }
78
79
    public function getOrderRisks($orderId, array $params = []): Collection
80
    {
81
        return $this->getResources('risks', $params, ['orders', $orderId]);
82
    }
83
84
    public function getOrderRisk($orderId, $riskId): Collection
85
    {
86
        return $this->getResource('risks', $riskId, ['orders', $orderId]);
87
    }
88
89
    public function updateOrderRisk($orderId, $riskId, array $data): RiskResource
90
    {
91
        return $this->updateResource('risks', $riskId, $data, ['orders', $orderId]);
92
    }
93
94
    public function deleteOrderRisk($orderId, $riskId): void
95
    {
96
        $this->deleteResource('risks', $riskId, ['orders', $orderId]);
97
    }
98
99
    public function createOrderRefund($orderId, array $data): RefundResource
100
    {
101
        return $this->createResource('refunds', $data, ['orders', $orderId]);
102
    }
103
104
    public function getOrderRefunds($orderId, array $params = []): Collection
105
    {
106
        return $this->getResources('refunds', $params, ['orders', $orderId]);
107
    }
108
109
    public function getOrderRefund($orderId, $refundId): RefundResource
110
    {
111
        return $this->getResource('refunds', $refundId, ['orders', $orderId]);
112
    }
113
114
    public function calculateOrderRefund($orderId, array $data): RefundResource
115
    {
116
        $response = $this->post("orders/{$orderId}/refunds/calculate.json", ['refund' => $data]);
117
118
        return new RefundResource($response['refund'], $this);
119
    }
120
121
    public function getOrderTransactionsCount($orderId, array $params = []): Collection
122
    {
123
        return $this->getResourceCount('transactions', $params, ['orders', $orderId]);
124
    }
125
126
    public function getOrderTransactions($orderId, array $params = []): Collection
127
    {
128
        return $this->getResources('transactions', $params, ['orders', $orderId]);
129
    }
130
131
    public function createOrderTransaction($orderId, array $data): TransactionResource
132
    {
133
        return $this->createResource('transactions', $data, ['orders', $orderId]);
134
    }
135
136
    public function createDraftOrder(array $data): DraftOrderResource
137
    {
138
        return $this->createResource('draft_orders', $data);
139
    }
140
141
    public function getDraftOrdersCount(array $params = []): int
142
    {
143
        return $this->getResourceCount('draft_orders', $params);
144
    }
145
146
    public function paginateDraftOrders(array $params = []): Cursor
147
    {
148
        return $this->cursor($this->getDraftOrders($params));
149
    }
150
151
    public function getDraftOrders(array $params = []): Collection
152
    {
153
        return $this->getResources('draft_orders', $params);
154
    }
155
156
    public function getDraftOrder($orderId): DraftOrderResource
157
    {
158
        return $this->getResource('draft_orders', $orderId);
159
    }
160
161
    public function updateDraftOrder($orderId, $data): DraftOrderResource
162
    {
163
        return $this->updateResource('draft_orders', $orderId, $data);
164
    }
165
166
    public function deleteDraftOrder($orderId): void
167
    {
168
        $this->deleteResource('draft_orders', $orderId);
169
    }
170
171
    public function sendDraftOrderInvoice($orderId, array $data): ApiResource
172
    {
173
        $response = $this->post("draft_orders/{$orderId}/send_invoice.json", ['draft_order_invoice' => $data]);
174
175
        return new ApiResource($response['draft_order_invoice'], $this);
176
    }
177
178
    public function completeDraftOrder($orderId, bool $paymentPending = false): DraftOrderResource
179
    {
180
        $response = $this->put("draft_orders/{$orderId}/complete.json", ['payment_pending' => $paymentPending]);
0 ignored issues
show
Bug introduced by
It seems like put() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

180
        /** @scrutinizer ignore-call */ 
181
        $response = $this->put("draft_orders/{$orderId}/complete.json", ['payment_pending' => $paymentPending]);
Loading history...
181
182
        return new DraftOrderResource($response['draft_order'], $this);
183
    }
184
185
    public function getCheckoutsCount(array $params = []): int
186
    {
187
        return $this->getResourceCount('checkouts', $params);
188
    }
189
190
    public function getCheckouts(array $params = []): Collection
191
    {
192
        return $this->getResources('checkouts', $params);
193
    }
194
}
195