StagedOrderActionBuilder   F
last analyzed

Complexity

Total Complexity 94

Size/Duplication

Total Lines 993
Duplicated Lines 0 %

Test Coverage

Coverage 96.09%

Importance

Changes 1
Bugs 1 Features 0
Metric Value
wmc 94
eloc 186
c 1
b 1
f 0
dl 0
loc 993
ccs 246
cts 256
cp 0.9609
rs 2

90 Methods

Rating   Name   Duplication   Size   Complexity  
A removeDiscountCode() 0 4 1
A changeLineItemQuantity() 0 4 1
A setDeliveryAddressCustomType() 0 4 1
A setCustomLineItemCustomField() 0 4 1
A setParcelCustomType() 0 4 1
A setShippingAddress() 0 4 1
A addShoppingList() 0 4 1
A setParcelCustomField() 0 4 1
A changePaymentState() 0 4 1
A changeTaxMode() 0 4 1
A importLineItemState() 0 4 1
A setShippingAddressCustomField() 0 4 1
A setBillingAddressCustomField() 0 4 1
A setShippingAddressAndShippingMethod() 0 4 1
A addParcelToDelivery() 0 4 1
A setOrderNumber() 0 4 1
A setCustomerId() 0 4 1
A setLineItemDistributionChannel() 0 4 1
A changeTaxRoundingMode() 0 4 1
A setCustomerGroup() 0 4 1
A removeParcelFromDelivery() 0 4 1
A changeShipmentState() 0 4 1
A setItemShippingAddressCustomField() 0 4 1
A callback() 0 6 2
A setCustomLineItemTaxRate() 0 4 1
A removeCustomLineItem() 0 4 1
A setLineItemTotalPrice() 0 4 1
A removePayment() 0 4 1
A setShippingMethodTaxAmount() 0 4 1
A addLineItem() 0 4 1
A addAction() 0 4 1
A addReturnInfo() 0 4 1
A setCustomField() 0 4 1
A setParcelItems() 0 4 1
A setShippingMethod() 0 4 1
A setDeliveryItems() 0 4 1
A setReturnItemCustomField() 0 4 1
A addDiscountCode() 0 4 1
A setCustomShippingMethod() 0 4 1
A changeTaxCalculationMode() 0 4 1
A getActions() 0 3 1
A changeOrderState() 0 4 1
A removeItemShippingAddress() 0 4 1
A setBillingAddress() 0 4 1
A resolveAction() 0 12 4
A setCustomType() 0 4 1
A updateItemShippingAddress() 0 4 1
A setParcelTrackingData() 0 4 1
A setActions() 0 4 1
A setLineItemCustomType() 0 4 1
A transitionState() 0 4 1
A setCustomerEmail() 0 4 1
A setLineItemTaxRate() 0 4 1
A setLineItemShippingDetails() 0 4 1
A setLineItemPrice() 0 4 1
A transitionCustomLineItemState() 0 4 1
A setLineItemTaxAmount() 0 4 1
A updateSyncInfo() 0 4 1
A setOrderTotalTax() 0 4 1
A setCustomLineItemShippingDetails() 0 4 1
A setLineItemCustomField() 0 4 1
A setShippingMethodTaxRate() 0 4 1
A setCustomLineItemCustomType() 0 4 1
A setLocale() 0 4 1
A addDelivery() 0 4 1
A setShippingAddressAndCustomShippingMethod() 0 5 1
A setReturnInfo() 0 4 1
A changeCustomLineItemQuantity() 0 4 1
A setBillingAddressCustomType() 0 4 1
A setDeliveryAddressCustomField() 0 4 1
A setItemShippingAddressCustomType() 0 4 1
A importCustomLineItemState() 0 4 1
A changeCustomLineItemMoney() 0 4 1
A setParcelMeasurements() 0 4 1
A setReturnPaymentState() 0 4 1
A addCustomLineItem() 0 4 1
A removeLineItem() 0 4 1
A transitionLineItemState() 0 4 1
A removeDelivery() 0 4 1
A addItemShippingAddress() 0 4 1
A setReturnItemCustomType() 0 4 1
A setCustomLineItemTaxAmount() 0 4 1
A setDeliveryAddress() 0 4 1
A setShippingAddressCustomType() 0 4 1
A setReturnShipmentState() 0 4 1
A of() 0 3 1
A getActionsCollection() 0 3 1
A setCountry() 0 4 1
A setShippingRateInput() 0 4 1
A addPayment() 0 4 1

How to fix   Complexity   

Complex Class

Complex classes like StagedOrderActionBuilder 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.

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 StagedOrderActionBuilder, and based on these observations, apply Extract Interface, too.

1
<?php
2
3
namespace Commercetools\Core\Builder\Update;
4
5
use Commercetools\Core\Error\InvalidArgumentException;
6
use Commercetools\Core\Request\AbstractAction;
7
use Commercetools\Core\Request\OrderEdits\StagedOrder\Command\StagedOrderAddCustomLineItemAction;
8
use Commercetools\Core\Request\OrderEdits\StagedOrder\Command\StagedOrderAddDeliveryAction;
9
use Commercetools\Core\Request\OrderEdits\StagedOrder\Command\StagedOrderAddDiscountCodeAction;
10
use Commercetools\Core\Request\OrderEdits\StagedOrder\Command\StagedOrderAddItemShippingAddressAction;
11
use Commercetools\Core\Request\OrderEdits\StagedOrder\Command\StagedOrderAddLineItemAction;
12
use Commercetools\Core\Request\OrderEdits\StagedOrder\Command\StagedOrderAddParcelToDeliveryAction;
13
use Commercetools\Core\Request\OrderEdits\StagedOrder\Command\StagedOrderAddPaymentAction;
14
use Commercetools\Core\Request\OrderEdits\StagedOrder\Command\StagedOrderAddReturnInfoAction;
15
use Commercetools\Core\Request\OrderEdits\StagedOrder\Command\StagedOrderAddShoppingListAction;
16
use Commercetools\Core\Request\OrderEdits\StagedOrder\Command\StagedOrderChangeCustomLineItemMoneyAction;
17
use Commercetools\Core\Request\OrderEdits\StagedOrder\Command\StagedOrderChangeCustomLineItemQuantityAction;
18
use Commercetools\Core\Request\OrderEdits\StagedOrder\Command\StagedOrderChangeLineItemQuantityAction;
19
use Commercetools\Core\Request\OrderEdits\StagedOrder\Command\StagedOrderChangeOrderStateAction;
20
use Commercetools\Core\Request\OrderEdits\StagedOrder\Command\StagedOrderChangePaymentStateAction;
21
use Commercetools\Core\Request\OrderEdits\StagedOrder\Command\StagedOrderChangeShipmentStateAction;
22
use Commercetools\Core\Request\OrderEdits\StagedOrder\Command\StagedOrderChangeTaxCalculationModeAction;
23
use Commercetools\Core\Request\OrderEdits\StagedOrder\Command\StagedOrderChangeTaxModeAction;
24
use Commercetools\Core\Request\OrderEdits\StagedOrder\Command\StagedOrderChangeTaxRoundingModeAction;
25
use Commercetools\Core\Request\OrderEdits\StagedOrder\Command\StagedOrderImportCustomLineItemStateAction;
26
use Commercetools\Core\Request\OrderEdits\StagedOrder\Command\StagedOrderImportLineItemStateAction;
27
use Commercetools\Core\Request\OrderEdits\StagedOrder\Command\StagedOrderRemoveCustomLineItemAction;
28
use Commercetools\Core\Request\OrderEdits\StagedOrder\Command\StagedOrderRemoveDeliveryAction;
29
use Commercetools\Core\Request\OrderEdits\StagedOrder\Command\StagedOrderRemoveDiscountCodeAction;
30
use Commercetools\Core\Request\OrderEdits\StagedOrder\Command\StagedOrderRemoveItemShippingAddressAction;
31
use Commercetools\Core\Request\OrderEdits\StagedOrder\Command\StagedOrderRemoveLineItemAction;
32
use Commercetools\Core\Request\OrderEdits\StagedOrder\Command\StagedOrderRemoveParcelFromDeliveryAction;
33
use Commercetools\Core\Request\OrderEdits\StagedOrder\Command\StagedOrderRemovePaymentAction;
34
use Commercetools\Core\Request\OrderEdits\StagedOrder\Command\StagedOrderSetBillingAddressAction;
35
use Commercetools\Core\Request\OrderEdits\StagedOrder\Command\StagedOrderSetBillingAddressCustomFieldAction;
36
use Commercetools\Core\Request\OrderEdits\StagedOrder\Command\StagedOrderSetBillingAddressCustomTypeAction;
37
use Commercetools\Core\Request\OrderEdits\StagedOrder\Command\StagedOrderSetCountryAction;
38
use Commercetools\Core\Request\OrderEdits\StagedOrder\Command\StagedOrderSetCustomFieldAction;
39
use Commercetools\Core\Request\OrderEdits\StagedOrder\Command\StagedOrderSetCustomLineItemCustomFieldAction;
40
use Commercetools\Core\Request\OrderEdits\StagedOrder\Command\StagedOrderSetCustomLineItemCustomTypeAction;
41
use Commercetools\Core\Request\OrderEdits\StagedOrder\Command\StagedOrderSetCustomLineItemShippingDetailsAction;
42
use Commercetools\Core\Request\OrderEdits\StagedOrder\Command\StagedOrderSetCustomLineItemTaxAmountAction;
43
use Commercetools\Core\Request\OrderEdits\StagedOrder\Command\StagedOrderSetCustomLineItemTaxRateAction;
44
use Commercetools\Core\Request\OrderEdits\StagedOrder\Command\StagedOrderSetCustomShippingMethodAction;
45
use Commercetools\Core\Request\OrderEdits\StagedOrder\Command\StagedOrderSetCustomTypeAction;
46
use Commercetools\Core\Request\OrderEdits\StagedOrder\Command\StagedOrderSetCustomerEmailAction;
47
use Commercetools\Core\Request\OrderEdits\StagedOrder\Command\StagedOrderSetCustomerGroupAction;
48
use Commercetools\Core\Request\OrderEdits\StagedOrder\Command\StagedOrderSetCustomerIdAction;
49
use Commercetools\Core\Request\OrderEdits\StagedOrder\Command\StagedOrderSetDeliveryAddressAction;
50
use Commercetools\Core\Request\OrderEdits\StagedOrder\Command\StagedOrderSetDeliveryAddressCustomFieldAction;
51
use Commercetools\Core\Request\OrderEdits\StagedOrder\Command\StagedOrderSetDeliveryAddressCustomTypeAction;
52
use Commercetools\Core\Request\OrderEdits\StagedOrder\Command\StagedOrderSetDeliveryItemsAction;
53
use Commercetools\Core\Request\OrderEdits\StagedOrder\Command\StagedOrderSetItemShippingAddressCustomFieldAction;
54
use Commercetools\Core\Request\OrderEdits\StagedOrder\Command\StagedOrderSetItemShippingAddressCustomTypeAction;
55
use Commercetools\Core\Request\OrderEdits\StagedOrder\Command\StagedOrderSetLineItemCustomFieldAction;
56
use Commercetools\Core\Request\OrderEdits\StagedOrder\Command\StagedOrderSetLineItemCustomTypeAction;
57
use Commercetools\Core\Request\OrderEdits\StagedOrder\Command\StagedOrderSetLineItemDistributionChannelAction;
58
use Commercetools\Core\Request\OrderEdits\StagedOrder\Command\StagedOrderSetLineItemPriceAction;
59
use Commercetools\Core\Request\OrderEdits\StagedOrder\Command\StagedOrderSetLineItemShippingDetailsAction;
60
use Commercetools\Core\Request\OrderEdits\StagedOrder\Command\StagedOrderSetLineItemTaxAmountAction;
61
use Commercetools\Core\Request\OrderEdits\StagedOrder\Command\StagedOrderSetLineItemTaxRateAction;
62
use Commercetools\Core\Request\OrderEdits\StagedOrder\Command\StagedOrderSetLineItemTotalPriceAction;
63
use Commercetools\Core\Request\OrderEdits\StagedOrder\Command\StagedOrderSetLocaleAction;
64
use Commercetools\Core\Request\OrderEdits\StagedOrder\Command\StagedOrderSetOrderNumberAction;
65
use Commercetools\Core\Request\OrderEdits\StagedOrder\Command\StagedOrderSetOrderTotalTaxAction;
66
use Commercetools\Core\Request\OrderEdits\StagedOrder\Command\StagedOrderSetParcelCustomFieldAction;
67
use Commercetools\Core\Request\OrderEdits\StagedOrder\Command\StagedOrderSetParcelCustomTypeAction;
68
use Commercetools\Core\Request\OrderEdits\StagedOrder\Command\StagedOrderSetParcelItemsAction;
69
use Commercetools\Core\Request\OrderEdits\StagedOrder\Command\StagedOrderSetParcelMeasurementsAction;
70
use Commercetools\Core\Request\OrderEdits\StagedOrder\Command\StagedOrderSetParcelTrackingDataAction;
71
use Commercetools\Core\Request\OrderEdits\StagedOrder\Command\StagedOrderSetReturnInfoAction;
72
use Commercetools\Core\Request\OrderEdits\StagedOrder\Command\StagedOrderSetReturnItemCustomFieldAction;
73
use Commercetools\Core\Request\OrderEdits\StagedOrder\Command\StagedOrderSetReturnItemCustomTypeAction;
74
use Commercetools\Core\Request\OrderEdits\StagedOrder\Command\StagedOrderSetReturnPaymentStateAction;
75
use Commercetools\Core\Request\OrderEdits\StagedOrder\Command\StagedOrderSetReturnShipmentStateAction;
76
use Commercetools\Core\Request\OrderEdits\StagedOrder\Command\StagedOrderSetShippingAddressAction;
77
// phpcs:ignore
78
use Commercetools\Core\Request\OrderEdits\StagedOrder\Command\StagedOrderSetShippingAddressAndCustomShippingMethodAction;
79
use Commercetools\Core\Request\OrderEdits\StagedOrder\Command\StagedOrderSetShippingAddressAndShippingMethodAction;
80
use Commercetools\Core\Request\OrderEdits\StagedOrder\Command\StagedOrderSetShippingAddressCustomFieldAction;
81
use Commercetools\Core\Request\OrderEdits\StagedOrder\Command\StagedOrderSetShippingAddressCustomTypeAction;
82
use Commercetools\Core\Request\OrderEdits\StagedOrder\Command\StagedOrderSetShippingMethodAction;
83
use Commercetools\Core\Request\OrderEdits\StagedOrder\Command\StagedOrderSetShippingMethodTaxAmountAction;
84
use Commercetools\Core\Request\OrderEdits\StagedOrder\Command\StagedOrderSetShippingMethodTaxRateAction;
85
use Commercetools\Core\Request\OrderEdits\StagedOrder\Command\StagedOrderSetShippingRateInputAction;
86
use Commercetools\Core\Request\OrderEdits\StagedOrder\Command\StagedOrderTransitionCustomLineItemStateAction;
87
use Commercetools\Core\Request\OrderEdits\StagedOrder\Command\StagedOrderTransitionLineItemStateAction;
88
use Commercetools\Core\Request\OrderEdits\StagedOrder\Command\StagedOrderTransitionStateAction;
89
use Commercetools\Core\Request\OrderEdits\StagedOrder\Command\StagedOrderUpdateItemShippingAddressAction;
90
use Commercetools\Core\Request\OrderEdits\StagedOrder\Command\StagedOrderUpdateSyncInfoAction;
91
use Commercetools\Core\Request\OrderEdits\StagedOrder\Command\StagedOrderUpdateActionCollection;
92
93
class StagedOrderActionBuilder
94
{
95
    private $actions = [];
96 1
97
    /**
98 1
     *
99 1
     * @param StagedOrderAddCustomLineItemAction|callable $action
100
     * @return $this
101
     */
102
    public function addCustomLineItem($action = null)
103
    {
104
        $this->addAction($this->resolveAction(StagedOrderAddCustomLineItemAction::class, $action));
105
        return $this;
106
    }
107 1
108
    /**
109 1
     *
110 1
     * @param StagedOrderAddDeliveryAction|callable $action
111
     * @return $this
112
     */
113
    public function addDelivery($action = null)
114
    {
115
        $this->addAction($this->resolveAction(StagedOrderAddDeliveryAction::class, $action));
116
        return $this;
117
    }
118 1
119
    /**
120 1
     *
121 1
     * @param StagedOrderAddDiscountCodeAction|callable $action
122
     * @return $this
123
     */
124
    public function addDiscountCode($action = null)
125
    {
126
        $this->addAction($this->resolveAction(StagedOrderAddDiscountCodeAction::class, $action));
127
        return $this;
128
    }
129 1
130
    /**
131 1
     *
132 1
     * @param StagedOrderAddItemShippingAddressAction|callable $action
133
     * @return $this
134
     */
135
    public function addItemShippingAddress($action = null)
136
    {
137
        $this->addAction($this->resolveAction(StagedOrderAddItemShippingAddressAction::class, $action));
138
        return $this;
139
    }
140 1
141
    /**
142 1
     *
143 1
     * @param StagedOrderAddLineItemAction|callable $action
144
     * @return $this
145
     */
146
    public function addLineItem($action = null)
147
    {
148
        $this->addAction($this->resolveAction(StagedOrderAddLineItemAction::class, $action));
149
        return $this;
150
    }
151 1
152
    /**
153 1
     *
154 1
     * @param StagedOrderAddParcelToDeliveryAction|callable $action
155
     * @return $this
156
     */
157
    public function addParcelToDelivery($action = null)
158
    {
159
        $this->addAction($this->resolveAction(StagedOrderAddParcelToDeliveryAction::class, $action));
160
        return $this;
161
    }
162 1
163
    /**
164 1
     *
165 1
     * @param StagedOrderAddPaymentAction|callable $action
166
     * @return $this
167
     */
168
    public function addPayment($action = null)
169
    {
170
        $this->addAction($this->resolveAction(StagedOrderAddPaymentAction::class, $action));
171
        return $this;
172
    }
173 1
174
    /**
175 1
     *
176 1
     * @param StagedOrderAddReturnInfoAction|callable $action
177
     * @return $this
178
     */
179
    public function addReturnInfo($action = null)
180
    {
181
        $this->addAction($this->resolveAction(StagedOrderAddReturnInfoAction::class, $action));
182
        return $this;
183
    }
184 1
185
    /**
186 1
     *
187 1
     * @param StagedOrderAddShoppingListAction|callable $action
188
     * @return $this
189
     */
190
    public function addShoppingList($action = null)
191
    {
192
        $this->addAction($this->resolveAction(StagedOrderAddShoppingListAction::class, $action));
193
        return $this;
194
    }
195 1
196
    /**
197 1
     *
198 1
     * @param StagedOrderChangeCustomLineItemMoneyAction|callable $action
199
     * @return $this
200
     */
201
    public function changeCustomLineItemMoney($action = null)
202
    {
203
        $this->addAction($this->resolveAction(StagedOrderChangeCustomLineItemMoneyAction::class, $action));
204
        return $this;
205
    }
206 1
207
    /**
208 1
     *
209 1
     * @param StagedOrderChangeCustomLineItemQuantityAction|callable $action
210
     * @return $this
211
     */
212
    public function changeCustomLineItemQuantity($action = null)
213
    {
214
        $this->addAction($this->resolveAction(StagedOrderChangeCustomLineItemQuantityAction::class, $action));
215
        return $this;
216
    }
217 1
218
    /**
219 1
     *
220 1
     * @param StagedOrderChangeLineItemQuantityAction|callable $action
221
     * @return $this
222
     */
223
    public function changeLineItemQuantity($action = null)
224
    {
225
        $this->addAction($this->resolveAction(StagedOrderChangeLineItemQuantityAction::class, $action));
226
        return $this;
227
    }
228 1
229
    /**
230 1
     *
231 1
     * @param StagedOrderChangeOrderStateAction|callable $action
232
     * @return $this
233
     */
234
    public function changeOrderState($action = null)
235
    {
236
        $this->addAction($this->resolveAction(StagedOrderChangeOrderStateAction::class, $action));
237
        return $this;
238
    }
239 1
240
    /**
241 1
     *
242 1
     * @param StagedOrderChangePaymentStateAction|callable $action
243
     * @return $this
244
     */
245
    public function changePaymentState($action = null)
246
    {
247
        $this->addAction($this->resolveAction(StagedOrderChangePaymentStateAction::class, $action));
248
        return $this;
249
    }
250 1
251
    /**
252 1
     *
253 1
     * @param StagedOrderChangeShipmentStateAction|callable $action
254
     * @return $this
255
     */
256
    public function changeShipmentState($action = null)
257
    {
258
        $this->addAction($this->resolveAction(StagedOrderChangeShipmentStateAction::class, $action));
259
        return $this;
260
    }
261 1
262
    /**
263 1
     *
264 1
     * @param StagedOrderChangeTaxCalculationModeAction|callable $action
265
     * @return $this
266
     */
267
    public function changeTaxCalculationMode($action = null)
268
    {
269
        $this->addAction($this->resolveAction(StagedOrderChangeTaxCalculationModeAction::class, $action));
270
        return $this;
271
    }
272 1
273
    /**
274 1
     *
275 1
     * @param StagedOrderChangeTaxModeAction|callable $action
276
     * @return $this
277
     */
278
    public function changeTaxMode($action = null)
279
    {
280
        $this->addAction($this->resolveAction(StagedOrderChangeTaxModeAction::class, $action));
281
        return $this;
282
    }
283 1
284
    /**
285 1
     *
286 1
     * @param StagedOrderChangeTaxRoundingModeAction|callable $action
287
     * @return $this
288
     */
289
    public function changeTaxRoundingMode($action = null)
290
    {
291
        $this->addAction($this->resolveAction(StagedOrderChangeTaxRoundingModeAction::class, $action));
292
        return $this;
293
    }
294 1
295
    /**
296 1
     *
297 1
     * @param StagedOrderImportCustomLineItemStateAction|callable $action
298
     * @return $this
299
     */
300
    public function importCustomLineItemState($action = null)
301
    {
302
        $this->addAction($this->resolveAction(StagedOrderImportCustomLineItemStateAction::class, $action));
303
        return $this;
304
    }
305 1
306
    /**
307 1
     *
308 1
     * @param StagedOrderImportLineItemStateAction|callable $action
309
     * @return $this
310
     */
311
    public function importLineItemState($action = null)
312
    {
313
        $this->addAction($this->resolveAction(StagedOrderImportLineItemStateAction::class, $action));
314
        return $this;
315
    }
316 1
317
    /**
318 1
     *
319 1
     * @param StagedOrderRemoveCustomLineItemAction|callable $action
320
     * @return $this
321
     */
322
    public function removeCustomLineItem($action = null)
323
    {
324
        $this->addAction($this->resolveAction(StagedOrderRemoveCustomLineItemAction::class, $action));
325
        return $this;
326
    }
327 1
328
    /**
329 1
     *
330 1
     * @param StagedOrderRemoveDeliveryAction|callable $action
331
     * @return $this
332
     */
333
    public function removeDelivery($action = null)
334
    {
335
        $this->addAction($this->resolveAction(StagedOrderRemoveDeliveryAction::class, $action));
336
        return $this;
337
    }
338 1
339
    /**
340 1
     *
341 1
     * @param StagedOrderRemoveDiscountCodeAction|callable $action
342
     * @return $this
343
     */
344
    public function removeDiscountCode($action = null)
345
    {
346
        $this->addAction($this->resolveAction(StagedOrderRemoveDiscountCodeAction::class, $action));
347
        return $this;
348
    }
349 1
350
    /**
351 1
     *
352 1
     * @param StagedOrderRemoveItemShippingAddressAction|callable $action
353
     * @return $this
354
     */
355
    public function removeItemShippingAddress($action = null)
356
    {
357
        $this->addAction($this->resolveAction(StagedOrderRemoveItemShippingAddressAction::class, $action));
358
        return $this;
359
    }
360 1
361
    /**
362 1
     *
363 1
     * @param StagedOrderRemoveLineItemAction|callable $action
364
     * @return $this
365
     */
366
    public function removeLineItem($action = null)
367
    {
368
        $this->addAction($this->resolveAction(StagedOrderRemoveLineItemAction::class, $action));
369
        return $this;
370
    }
371 1
372
    /**
373 1
     *
374 1
     * @param StagedOrderRemoveParcelFromDeliveryAction|callable $action
375
     * @return $this
376
     */
377
    public function removeParcelFromDelivery($action = null)
378
    {
379
        $this->addAction($this->resolveAction(StagedOrderRemoveParcelFromDeliveryAction::class, $action));
380
        return $this;
381
    }
382 1
383
    /**
384 1
     *
385 1
     * @param StagedOrderRemovePaymentAction|callable $action
386
     * @return $this
387
     */
388
    public function removePayment($action = null)
389
    {
390
        $this->addAction($this->resolveAction(StagedOrderRemovePaymentAction::class, $action));
391
        return $this;
392
    }
393 1
394
    /**
395 1
     *
396 1
     * @param StagedOrderSetBillingAddressAction|callable $action
397
     * @return $this
398
     */
399
    public function setBillingAddress($action = null)
400
    {
401
        $this->addAction($this->resolveAction(StagedOrderSetBillingAddressAction::class, $action));
402
        return $this;
403
    }
404 1
405
    /**
406 1
     *
407 1
     * @param StagedOrderSetBillingAddressCustomFieldAction|callable $action
408
     * @return $this
409
     */
410
    public function setBillingAddressCustomField($action = null)
411
    {
412
        $this->addAction($this->resolveAction(StagedOrderSetBillingAddressCustomFieldAction::class, $action));
413
        return $this;
414
    }
415 1
416
    /**
417 1
     *
418 1
     * @param StagedOrderSetBillingAddressCustomTypeAction|callable $action
419
     * @return $this
420
     */
421
    public function setBillingAddressCustomType($action = null)
422
    {
423
        $this->addAction($this->resolveAction(StagedOrderSetBillingAddressCustomTypeAction::class, $action));
424
        return $this;
425
    }
426 1
427
    /**
428 1
     *
429 1
     * @param StagedOrderSetCountryAction|callable $action
430
     * @return $this
431
     */
432
    public function setCountry($action = null)
433
    {
434
        $this->addAction($this->resolveAction(StagedOrderSetCountryAction::class, $action));
435
        return $this;
436
    }
437 1
438
    /**
439 1
     *
440 1
     * @param StagedOrderSetCustomFieldAction|callable $action
441
     * @return $this
442
     */
443
    public function setCustomField($action = null)
444
    {
445
        $this->addAction($this->resolveAction(StagedOrderSetCustomFieldAction::class, $action));
446
        return $this;
447
    }
448 1
449
    /**
450 1
     *
451 1
     * @param StagedOrderSetCustomLineItemCustomFieldAction|callable $action
452
     * @return $this
453
     */
454
    public function setCustomLineItemCustomField($action = null)
455
    {
456
        $this->addAction($this->resolveAction(StagedOrderSetCustomLineItemCustomFieldAction::class, $action));
457
        return $this;
458
    }
459 1
460
    /**
461 1
     *
462 1
     * @param StagedOrderSetCustomLineItemCustomTypeAction|callable $action
463
     * @return $this
464
     */
465
    public function setCustomLineItemCustomType($action = null)
466
    {
467
        $this->addAction($this->resolveAction(StagedOrderSetCustomLineItemCustomTypeAction::class, $action));
468
        return $this;
469
    }
470 1
471
    /**
472 1
     *
473 1
     * @param StagedOrderSetCustomLineItemShippingDetailsAction|callable $action
474
     * @return $this
475
     */
476
    public function setCustomLineItemShippingDetails($action = null)
477
    {
478
        $this->addAction($this->resolveAction(StagedOrderSetCustomLineItemShippingDetailsAction::class, $action));
479
        return $this;
480
    }
481 1
482
    /**
483 1
     *
484 1
     * @param StagedOrderSetCustomLineItemTaxAmountAction|callable $action
485
     * @return $this
486
     */
487
    public function setCustomLineItemTaxAmount($action = null)
488
    {
489
        $this->addAction($this->resolveAction(StagedOrderSetCustomLineItemTaxAmountAction::class, $action));
490
        return $this;
491
    }
492 1
493
    /**
494 1
     *
495 1
     * @param StagedOrderSetCustomLineItemTaxRateAction|callable $action
496
     * @return $this
497
     */
498
    public function setCustomLineItemTaxRate($action = null)
499
    {
500
        $this->addAction($this->resolveAction(StagedOrderSetCustomLineItemTaxRateAction::class, $action));
501
        return $this;
502
    }
503 1
504
    /**
505 1
     *
506 1
     * @param StagedOrderSetCustomShippingMethodAction|callable $action
507
     * @return $this
508
     */
509
    public function setCustomShippingMethod($action = null)
510
    {
511
        $this->addAction($this->resolveAction(StagedOrderSetCustomShippingMethodAction::class, $action));
512
        return $this;
513
    }
514 1
515
    /**
516 1
     *
517 1
     * @param StagedOrderSetCustomTypeAction|callable $action
518
     * @return $this
519
     */
520
    public function setCustomType($action = null)
521
    {
522
        $this->addAction($this->resolveAction(StagedOrderSetCustomTypeAction::class, $action));
523
        return $this;
524
    }
525 1
526
    /**
527 1
     *
528 1
     * @param StagedOrderSetCustomerEmailAction|callable $action
529
     * @return $this
530
     */
531
    public function setCustomerEmail($action = null)
532
    {
533
        $this->addAction($this->resolveAction(StagedOrderSetCustomerEmailAction::class, $action));
534
        return $this;
535
    }
536 1
537
    /**
538 1
     *
539 1
     * @param StagedOrderSetCustomerGroupAction|callable $action
540
     * @return $this
541
     */
542
    public function setCustomerGroup($action = null)
543
    {
544
        $this->addAction($this->resolveAction(StagedOrderSetCustomerGroupAction::class, $action));
545
        return $this;
546
    }
547 1
548
    /**
549 1
     *
550 1
     * @param StagedOrderSetCustomerIdAction|callable $action
551
     * @return $this
552
     */
553
    public function setCustomerId($action = null)
554
    {
555
        $this->addAction($this->resolveAction(StagedOrderSetCustomerIdAction::class, $action));
556
        return $this;
557
    }
558 1
559
    /**
560 1
     *
561 1
     * @param StagedOrderSetDeliveryAddressAction|callable $action
562
     * @return $this
563
     */
564
    public function setDeliveryAddress($action = null)
565
    {
566
        $this->addAction($this->resolveAction(StagedOrderSetDeliveryAddressAction::class, $action));
567
        return $this;
568
    }
569 1
570
    /**
571 1
     *
572 1
     * @param StagedOrderSetDeliveryAddressCustomFieldAction|callable $action
573
     * @return $this
574
     */
575
    public function setDeliveryAddressCustomField($action = null)
576
    {
577
        $this->addAction($this->resolveAction(StagedOrderSetDeliveryAddressCustomFieldAction::class, $action));
578
        return $this;
579
    }
580 1
581
    /**
582 1
     *
583 1
     * @param StagedOrderSetDeliveryAddressCustomTypeAction|callable $action
584
     * @return $this
585
     */
586
    public function setDeliveryAddressCustomType($action = null)
587
    {
588
        $this->addAction($this->resolveAction(StagedOrderSetDeliveryAddressCustomTypeAction::class, $action));
589
        return $this;
590
    }
591 1
592
    /**
593 1
     *
594 1
     * @param StagedOrderSetDeliveryItemsAction|callable $action
595
     * @return $this
596
     */
597
    public function setDeliveryItems($action = null)
598
    {
599
        $this->addAction($this->resolveAction(StagedOrderSetDeliveryItemsAction::class, $action));
600
        return $this;
601
    }
602 1
603
    /**
604 1
     *
605 1
     * @param StagedOrderSetItemShippingAddressCustomFieldAction|callable $action
606
     * @return $this
607
     */
608
    public function setItemShippingAddressCustomField($action = null)
609
    {
610
        $this->addAction($this->resolveAction(StagedOrderSetItemShippingAddressCustomFieldAction::class, $action));
611
        return $this;
612
    }
613 1
614
    /**
615 1
     *
616 1
     * @param StagedOrderSetItemShippingAddressCustomTypeAction|callable $action
617
     * @return $this
618
     */
619
    public function setItemShippingAddressCustomType($action = null)
620
    {
621
        $this->addAction($this->resolveAction(StagedOrderSetItemShippingAddressCustomTypeAction::class, $action));
622
        return $this;
623
    }
624 1
625
    /**
626 1
     *
627 1
     * @param StagedOrderSetLineItemCustomFieldAction|callable $action
628
     * @return $this
629
     */
630
    public function setLineItemCustomField($action = null)
631
    {
632
        $this->addAction($this->resolveAction(StagedOrderSetLineItemCustomFieldAction::class, $action));
633
        return $this;
634
    }
635 1
636
    /**
637 1
     *
638 1
     * @param StagedOrderSetLineItemCustomTypeAction|callable $action
639
     * @return $this
640
     */
641
    public function setLineItemCustomType($action = null)
642
    {
643
        $this->addAction($this->resolveAction(StagedOrderSetLineItemCustomTypeAction::class, $action));
644
        return $this;
645
    }
646 1
647
    /**
648 1
     *
649 1
     * @param StagedOrderSetLineItemDistributionChannelAction|callable $action
650
     * @return $this
651
     */
652
    public function setLineItemDistributionChannel($action = null)
653
    {
654
        $this->addAction($this->resolveAction(StagedOrderSetLineItemDistributionChannelAction::class, $action));
655
        return $this;
656
    }
657 1
658
    /**
659 1
     *
660 1
     * @param StagedOrderSetLineItemPriceAction|callable $action
661
     * @return $this
662
     */
663
    public function setLineItemPrice($action = null)
664
    {
665
        $this->addAction($this->resolveAction(StagedOrderSetLineItemPriceAction::class, $action));
666
        return $this;
667
    }
668 1
669
    /**
670 1
     *
671 1
     * @param StagedOrderSetLineItemShippingDetailsAction|callable $action
672
     * @return $this
673
     */
674
    public function setLineItemShippingDetails($action = null)
675
    {
676
        $this->addAction($this->resolveAction(StagedOrderSetLineItemShippingDetailsAction::class, $action));
677
        return $this;
678
    }
679 1
680
    /**
681 1
     *
682 1
     * @param StagedOrderSetLineItemTaxAmountAction|callable $action
683
     * @return $this
684
     */
685
    public function setLineItemTaxAmount($action = null)
686
    {
687
        $this->addAction($this->resolveAction(StagedOrderSetLineItemTaxAmountAction::class, $action));
688
        return $this;
689
    }
690 1
691
    /**
692 1
     *
693 1
     * @param StagedOrderSetLineItemTaxRateAction|callable $action
694
     * @return $this
695
     */
696
    public function setLineItemTaxRate($action = null)
697
    {
698
        $this->addAction($this->resolveAction(StagedOrderSetLineItemTaxRateAction::class, $action));
699
        return $this;
700
    }
701 1
702
    /**
703 1
     *
704 1
     * @param StagedOrderSetLineItemTotalPriceAction|callable $action
705
     * @return $this
706
     */
707
    public function setLineItemTotalPrice($action = null)
708
    {
709
        $this->addAction($this->resolveAction(StagedOrderSetLineItemTotalPriceAction::class, $action));
710
        return $this;
711
    }
712 1
713
    /**
714 1
     *
715 1
     * @param StagedOrderSetLocaleAction|callable $action
716
     * @return $this
717
     */
718
    public function setLocale($action = null)
719
    {
720
        $this->addAction($this->resolveAction(StagedOrderSetLocaleAction::class, $action));
721
        return $this;
722
    }
723 1
724
    /**
725 1
     *
726 1
     * @param StagedOrderSetOrderNumberAction|callable $action
727
     * @return $this
728
     */
729
    public function setOrderNumber($action = null)
730
    {
731
        $this->addAction($this->resolveAction(StagedOrderSetOrderNumberAction::class, $action));
732
        return $this;
733
    }
734 1
735
    /**
736 1
     *
737 1
     * @param StagedOrderSetOrderTotalTaxAction|callable $action
738
     * @return $this
739
     */
740
    public function setOrderTotalTax($action = null)
741
    {
742
        $this->addAction($this->resolveAction(StagedOrderSetOrderTotalTaxAction::class, $action));
743
        return $this;
744
    }
745 1
746
    /**
747 1
     *
748 1
     * @param StagedOrderSetParcelCustomFieldAction|callable $action
749
     * @return $this
750
     */
751
    public function setParcelCustomField($action = null)
752
    {
753
        $this->addAction($this->resolveAction(StagedOrderSetParcelCustomFieldAction::class, $action));
754
        return $this;
755
    }
756 1
757
    /**
758 1
     *
759 1
     * @param StagedOrderSetParcelCustomTypeAction|callable $action
760
     * @return $this
761
     */
762
    public function setParcelCustomType($action = null)
763
    {
764
        $this->addAction($this->resolveAction(StagedOrderSetParcelCustomTypeAction::class, $action));
765
        return $this;
766
    }
767 1
768
    /**
769 1
     *
770 1
     * @param StagedOrderSetParcelItemsAction|callable $action
771
     * @return $this
772
     */
773
    public function setParcelItems($action = null)
774
    {
775
        $this->addAction($this->resolveAction(StagedOrderSetParcelItemsAction::class, $action));
776
        return $this;
777
    }
778 1
779
    /**
780 1
     *
781 1
     * @param StagedOrderSetParcelMeasurementsAction|callable $action
782
     * @return $this
783
     */
784
    public function setParcelMeasurements($action = null)
785
    {
786
        $this->addAction($this->resolveAction(StagedOrderSetParcelMeasurementsAction::class, $action));
787
        return $this;
788
    }
789 1
790
    /**
791 1
     *
792 1
     * @param StagedOrderSetParcelTrackingDataAction|callable $action
793
     * @return $this
794
     */
795
    public function setParcelTrackingData($action = null)
796
    {
797
        $this->addAction($this->resolveAction(StagedOrderSetParcelTrackingDataAction::class, $action));
798
        return $this;
799
    }
800 1
801
    /**
802
     *
803 1
     * @param StagedOrderSetReturnInfoAction|callable $action
804 1
     * @return $this
805
     */
806
    public function setReturnInfo($action = null)
807
    {
808
        $this->addAction($this->resolveAction(StagedOrderSetReturnInfoAction::class, $action));
809
        return $this;
810
    }
811
812 1
    /**
813
     *
814 1
     * @param StagedOrderSetReturnItemCustomFieldAction|callable $action
815 1
     * @return $this
816
     */
817
    public function setReturnItemCustomField($action = null)
818
    {
819
        $this->addAction($this->resolveAction(StagedOrderSetReturnItemCustomFieldAction::class, $action));
820
        return $this;
821
    }
822
823 1
    /**
824
     *
825 1
     * @param StagedOrderSetReturnItemCustomTypeAction|callable $action
826 1
     * @return $this
827
     */
828
    public function setReturnItemCustomType($action = null)
829
    {
830
        $this->addAction($this->resolveAction(StagedOrderSetReturnItemCustomTypeAction::class, $action));
831
        return $this;
832
    }
833
834 1
    /**
835
     *
836 1
     * @param StagedOrderSetReturnPaymentStateAction|callable $action
837 1
     * @return $this
838
     */
839
    public function setReturnPaymentState($action = null)
840
    {
841
        $this->addAction($this->resolveAction(StagedOrderSetReturnPaymentStateAction::class, $action));
842
        return $this;
843
    }
844
845 1
    /**
846
     *
847 1
     * @param StagedOrderSetReturnShipmentStateAction|callable $action
848 1
     * @return $this
849
     */
850
    public function setReturnShipmentState($action = null)
851
    {
852
        $this->addAction($this->resolveAction(StagedOrderSetReturnShipmentStateAction::class, $action));
853
        return $this;
854
    }
855
856 1
    /**
857
     *
858 1
     * @param StagedOrderSetShippingAddressAction|callable $action
859 1
     * @return $this
860
     */
861
    public function setShippingAddress($action = null)
862
    {
863
        $this->addAction($this->resolveAction(StagedOrderSetShippingAddressAction::class, $action));
864
        return $this;
865
    }
866
867 1
    /**
868
     *
869 1
     * @param StagedOrderSetShippingAddressAndCustomShippingMethodAction|callable $action
870 1
     * @return $this
871
     */
872
    public function setShippingAddressAndCustomShippingMethod($action = null)
873
    {
874
        // phpcs:ignore
875
        $this->addAction($this->resolveAction(StagedOrderSetShippingAddressAndCustomShippingMethodAction::class, $action));
876
        return $this;
877
    }
878 1
879
    /**
880 1
     *
881 1
     * @param StagedOrderSetShippingAddressAndShippingMethodAction|callable $action
882
     * @return $this
883
     */
884
    public function setShippingAddressAndShippingMethod($action = null)
885
    {
886
        $this->addAction($this->resolveAction(StagedOrderSetShippingAddressAndShippingMethodAction::class, $action));
887
        return $this;
888
    }
889 1
890
    /**
891 1
     *
892 1
     * @param StagedOrderSetShippingAddressCustomFieldAction|callable $action
893
     * @return $this
894
     */
895
    public function setShippingAddressCustomField($action = null)
896
    {
897
        $this->addAction($this->resolveAction(StagedOrderSetShippingAddressCustomFieldAction::class, $action));
898
        return $this;
899
    }
900 1
901
    /**
902 1
     *
903 1
     * @param StagedOrderSetShippingAddressCustomTypeAction|callable $action
904
     * @return $this
905
     */
906
    public function setShippingAddressCustomType($action = null)
907
    {
908
        $this->addAction($this->resolveAction(StagedOrderSetShippingAddressCustomTypeAction::class, $action));
909
        return $this;
910
    }
911 1
912
    /**
913 1
     *
914 1
     * @param StagedOrderSetShippingMethodAction|callable $action
915
     * @return $this
916
     */
917
    public function setShippingMethod($action = null)
918
    {
919
        $this->addAction($this->resolveAction(StagedOrderSetShippingMethodAction::class, $action));
920
        return $this;
921
    }
922 1
923
    /**
924 1
     *
925 1
     * @param StagedOrderSetShippingMethodTaxAmountAction|callable $action
926
     * @return $this
927
     */
928
    public function setShippingMethodTaxAmount($action = null)
929
    {
930
        $this->addAction($this->resolveAction(StagedOrderSetShippingMethodTaxAmountAction::class, $action));
931
        return $this;
932
    }
933 1
934
    /**
935 1
     *
936 1
     * @param StagedOrderSetShippingMethodTaxRateAction|callable $action
937
     * @return $this
938
     */
939
    public function setShippingMethodTaxRate($action = null)
940
    {
941
        $this->addAction($this->resolveAction(StagedOrderSetShippingMethodTaxRateAction::class, $action));
942
        return $this;
943
    }
944
945
    /**
946
     *
947
     * @param StagedOrderSetShippingRateInputAction|callable $action
948
     * @return $this
949
     */
950
    public function setShippingRateInput($action = null)
951
    {
952
        $this->addAction($this->resolveAction(StagedOrderSetShippingRateInputAction::class, $action));
953 77
        return $this;
954
    }
955 77
956 77
    /**
957 77
     *
958 77
     * @param StagedOrderTransitionCustomLineItemStateAction|callable $action
959
     * @return $this
960 77
     */
961 77
    public function transitionCustomLineItemState($action = null)
962
    {
963
        $this->addAction($this->resolveAction(StagedOrderTransitionCustomLineItemStateAction::class, $action));
964
        return $this;
965
    }
966
967
    /**
968
     *
969
     * @param StagedOrderTransitionLineItemStateAction|callable $action
970
     * @return $this
971
     */
972
    public function transitionLineItemState($action = null)
973 77
    {
974
        $this->addAction($this->resolveAction(StagedOrderTransitionLineItemStateAction::class, $action));
975 77
        return $this;
976
    }
977
978 77
    /**
979
     *
980
     * @param StagedOrderTransitionStateAction|callable $action
981
     * @return $this
982
     */
983
    public function transitionState($action = null)
984
    {
985 77
        $this->addAction($this->resolveAction(StagedOrderTransitionStateAction::class, $action));
986
        return $this;
987 77
    }
988 77
989
    /**
990
     *
991
     * @param StagedOrderUpdateItemShippingAddressAction|callable $action
992
     * @return $this
993
     */
994 77
    public function updateItemShippingAddress($action = null)
995
    {
996 77
        $this->addAction($this->resolveAction(StagedOrderUpdateItemShippingAddressAction::class, $action));
997
        return $this;
998
    }
999
1000
    /**
1001
     *
1002
     * @param StagedOrderUpdateSyncInfoAction|callable $action
1003
     * @return $this
1004
     */
1005
    public function updateSyncInfo($action = null)
1006
    {
1007
        $this->addAction($this->resolveAction(StagedOrderUpdateSyncInfoAction::class, $action));
1008
        return $this;
1009
    }
1010
1011
    /**
1012
     * @return StagedOrderActionBuilder
1013
     */
1014
    public static function of()
1015
    {
1016
        return new self();
1017
    }
1018
1019
    /**
1020
     * @param $class
1021
     * @param $action
1022
     * @return AbstractAction
1023
     * @throws InvalidArgumentException
1024
     */
1025
    private function resolveAction($class, $action = null)
1026
    {
1027
        if (is_null($action) || is_callable($action)) {
1028
            $callback = $action;
1029
            $emptyAction = $class::of();
1030
            $action = $this->callback($emptyAction, $callback);
1031
        }
1032
        if ($action instanceof $class) {
1033
            return $action;
1034
        }
1035
        throw new InvalidArgumentException(
1036
            sprintf('Expected method to be called with or callable to return %s', $class)
1037
        );
1038
    }
1039
1040
    /**
1041
     * @param $action
1042
     * @param callable $callback
1043
     * @return AbstractAction
1044
     */
1045
    private function callback($action, callable $callback = null)
1046
    {
1047
        if (!is_null($callback)) {
1048
            $action = $callback($action);
1049
        }
1050
        return $action;
1051
    }
1052
1053
    /**
1054
     * @param AbstractAction $action
1055
     * @return $this;
1056
     */
1057
    public function addAction(AbstractAction $action)
1058
    {
1059
        $this->actions[] = $action;
1060
        return $this;
1061
    }
1062
1063
    /**
1064
     * @return array
1065
     */
1066
    public function getActions()
1067
    {
1068
        return $this->actions;
1069
    }
1070
1071
    /**
1072
     * @return StagedOrderUpdateActionCollection
1073
     */
1074
    public function getActionsCollection()
1075
    {
1076
        return StagedOrderUpdateActionCollection::fromArray($this->actions);
1077
    }
1078
    /**
1079
     * @param array $actions
1080
     * @return $this
1081
     */
1082
    public function setActions(array $actions)
1083
    {
1084
        $this->actions = $actions;
1085
        return $this;
1086
    }
1087
}
1088