Test Failed
Push — develop ( a91eee...f77bbc )
by Jens
17:10 queued 15s
created

OrdersActionBuilder   F

Complexity

Total Complexity 60

Size/Duplication

Total Lines 623
Duplicated Lines 0 %

Test Coverage

Coverage 95.29%

Importance

Changes 0
Metric Value
wmc 60
eloc 119
c 0
b 0
f 0
dl 0
loc 623
rs 3.6
ccs 162
cts 170
cp 0.9529

56 Methods

Rating   Name   Duplication   Size   Complexity  
A setLineItemCustomField() 0 4 1
A setDeliveryAddressCustomField() 0 4 1
A getActions() 0 3 1
A resolveAction() 0 12 4
A addItemShippingAddress() 0 4 1
A changeShipmentState() 0 4 1
A setOrderNumber() 0 4 1
A setLineItemCustomType() 0 4 1
A setItemShippingAddressCustomField() 0 4 1
A updateItemShippingAddress() 0 4 1
A importLineItemState() 0 4 1
A removeItemShippingAddress() 0 4 1
A addDelivery() 0 4 1
A setDeliveryAddress() 0 4 1
A setCustomerId() 0 4 1
A setShippingAddress() 0 4 1
A transitionState() 0 4 1
A setLineItemShippingDetails() 0 4 1
A setShippingAddressCustomField() 0 4 1
A setReturnPaymentState() 0 4 1
A setParcelItems() 0 4 1
A setCustomField() 0 4 1
A updateSyncInfo() 0 4 1
A setActions() 0 4 1
A callback() 0 6 2
A setBillingAddressCustomField() 0 4 1
A removePayment() 0 4 1
A setLocale() 0 4 1
A importCustomLineItemState() 0 4 1
A setReturnInfo() 0 4 1
A setBillingAddress() 0 4 1
A removeDelivery() 0 4 1
A transitionCustomLineItemState() 0 4 1
A addParcelToDelivery() 0 4 1
A transitionLineItemState() 0 4 1
A changeOrderState() 0 4 1
A setStore() 0 4 1
A setCustomType() 0 4 1
A setCustomLineItemShippingDetails() 0 4 1
A addReturnInfo() 0 4 1
A setDeliveryItems() 0 4 1
A setBillingAddressCustomType() 0 4 1
A setCustomLineItemCustomField() 0 4 1
A setCustomLineItemCustomType() 0 4 1
A changePaymentState() 0 4 1
A setParcelMeasurements() 0 4 1
A setParcelTrackingData() 0 4 1
A setCustomerEmail() 0 4 1
A setDeliveryAddressCustomType() 0 4 1
A addAction() 0 4 1
A removeParcelFromDelivery() 0 4 1
A setShippingAddressCustomType() 0 4 1
A setItemShippingAddressCustomType() 0 4 1
A addPayment() 0 4 1
A of() 0 3 1
A setReturnShipmentState() 0 4 1

How to fix   Complexity   

Complex Class

Complex classes like OrdersActionBuilder 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 OrdersActionBuilder, 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\Orders\Command\OrderAddDeliveryAction;
8
use Commercetools\Core\Request\Orders\Command\OrderAddItemShippingAddressAction;
9
use Commercetools\Core\Request\Orders\Command\OrderAddParcelToDeliveryAction;
10
use Commercetools\Core\Request\Orders\Command\OrderAddPaymentAction;
11
use Commercetools\Core\Request\Orders\Command\OrderAddReturnInfoAction;
12
use Commercetools\Core\Request\Orders\Command\OrderChangeOrderStateAction;
13
use Commercetools\Core\Request\Orders\Command\OrderChangePaymentStateAction;
14
use Commercetools\Core\Request\Orders\Command\OrderChangeShipmentStateAction;
15
use Commercetools\Core\Request\Orders\Command\OrderImportCustomLineItemStateAction;
16
use Commercetools\Core\Request\Orders\Command\OrderImportLineItemStateAction;
17
use Commercetools\Core\Request\Orders\Command\OrderRemoveDeliveryAction;
18
use Commercetools\Core\Request\Orders\Command\OrderRemoveItemShippingAddressAction;
19
use Commercetools\Core\Request\Orders\Command\OrderRemoveParcelFromDeliveryAction;
20
use Commercetools\Core\Request\Orders\Command\OrderRemovePaymentAction;
21
use Commercetools\Core\Request\Orders\Command\OrderSetBillingAddress;
22
use Commercetools\Core\Request\Orders\Command\OrderSetBillingAddressCustomFieldAction;
23
use Commercetools\Core\Request\Orders\Command\OrderSetBillingAddressCustomTypeAction;
24
use Commercetools\Core\Request\Orders\Command\OrderSetCustomFieldAction;
25
use Commercetools\Core\Request\Orders\Command\OrderSetCustomLineItemCustomFieldAction;
26
use Commercetools\Core\Request\Orders\Command\OrderSetCustomLineItemCustomTypeAction;
27
use Commercetools\Core\Request\Orders\Command\OrderSetCustomLineItemShippingDetailsAction;
28
use Commercetools\Core\Request\Orders\Command\OrderSetCustomTypeAction;
29
use Commercetools\Core\Request\Orders\Command\OrderSetCustomerEmail;
30
use Commercetools\Core\Request\Orders\Command\OrderSetCustomerIdAction;
31
use Commercetools\Core\Request\Orders\Command\OrderSetDeliveryAddressAction;
32
use Commercetools\Core\Request\Orders\Command\OrderSetDeliveryAddressCustomFieldAction;
33
use Commercetools\Core\Request\Orders\Command\OrderSetDeliveryAddressCustomTypeAction;
34
use Commercetools\Core\Request\Orders\Command\OrderSetDeliveryItemsAction;
35
use Commercetools\Core\Request\Orders\Command\OrderSetItemShippingAddressCustomFieldAction;
36
use Commercetools\Core\Request\Orders\Command\OrderSetItemShippingAddressCustomTypeAction;
37
use Commercetools\Core\Request\Orders\Command\OrderSetLineItemCustomFieldAction;
38
use Commercetools\Core\Request\Orders\Command\OrderSetLineItemCustomTypeAction;
39
use Commercetools\Core\Request\Orders\Command\OrderSetLineItemShippingDetailsAction;
40
use Commercetools\Core\Request\Orders\Command\OrderSetLocaleAction;
41
use Commercetools\Core\Request\Orders\Command\OrderSetOrderNumberAction;
42
use Commercetools\Core\Request\Orders\Command\OrderSetParcelItemsAction;
43
use Commercetools\Core\Request\Orders\Command\OrderSetParcelMeasurementsAction;
44
use Commercetools\Core\Request\Orders\Command\OrderSetParcelTrackingDataAction;
45
use Commercetools\Core\Request\Orders\Command\OrderSetReturnInfoAction;
46
use Commercetools\Core\Request\Orders\Command\OrderSetReturnPaymentStateAction;
47
use Commercetools\Core\Request\Orders\Command\OrderSetReturnShipmentStateAction;
48
use Commercetools\Core\Request\Orders\Command\OrderSetShippingAddress;
49
use Commercetools\Core\Request\Orders\Command\OrderSetShippingAddressCustomFieldAction;
50
use Commercetools\Core\Request\Orders\Command\OrderSetShippingAddressCustomTypeAction;
51
use Commercetools\Core\Request\Orders\Command\OrderSetStoreAction;
52
use Commercetools\Core\Request\Orders\Command\OrderTransitionCustomLineItemStateAction;
53
use Commercetools\Core\Request\Orders\Command\OrderTransitionLineItemStateAction;
54
use Commercetools\Core\Request\Orders\Command\OrderTransitionStateAction;
55
use Commercetools\Core\Request\Orders\Command\OrderUpdateItemShippingAddressAction;
56
use Commercetools\Core\Request\Orders\Command\OrderUpdateSyncInfoAction;
57
58
class OrdersActionBuilder
59
{
60
    private $actions = [];
61
62
    /**
63
     * @link https://docs.commercetools.com/http-api-projects-orders.html#add-delivery
64
     * @param OrderAddDeliveryAction|callable $action
65
     * @return $this
66 1
     */
67
    public function addDelivery($action = null)
68 1
    {
69 1
        $this->addAction($this->resolveAction(OrderAddDeliveryAction::class, $action));
70
        return $this;
71
    }
72
73
    /**
74
     * @link https://docs.commercetools.com/http-api-projects-orders.html#add-itemshippingaddress
75
     * @param OrderAddItemShippingAddressAction|callable $action
76
     * @return $this
77 1
     */
78
    public function addItemShippingAddress($action = null)
79 1
    {
80 1
        $this->addAction($this->resolveAction(OrderAddItemShippingAddressAction::class, $action));
81
        return $this;
82
    }
83
84
    /**
85
     * @link https://docs.commercetools.com/http-api-projects-orders.html#add-parcel
86
     * @param OrderAddParcelToDeliveryAction|callable $action
87
     * @return $this
88 1
     */
89
    public function addParcelToDelivery($action = null)
90 1
    {
91 1
        $this->addAction($this->resolveAction(OrderAddParcelToDeliveryAction::class, $action));
92
        return $this;
93
    }
94
95
    /**
96
     * @link https://docs.commercetools.com/http-api-projects-orders.html#add-payment
97
     * @param OrderAddPaymentAction|callable $action
98
     * @return $this
99 1
     */
100
    public function addPayment($action = null)
101 1
    {
102 1
        $this->addAction($this->resolveAction(OrderAddPaymentAction::class, $action));
103
        return $this;
104
    }
105
106
    /**
107
     * @link https://docs.commercetools.com/http-api-projects-orders.html#addreturninfo
108
     * @param OrderAddReturnInfoAction|callable $action
109
     * @return $this
110 1
     */
111
    public function addReturnInfo($action = null)
112 1
    {
113 1
        $this->addAction($this->resolveAction(OrderAddReturnInfoAction::class, $action));
114
        return $this;
115
    }
116
117
    /**
118
     * @link https://docs.commercetools.com/http-api-projects-orders.html#change-orderstate
119
     * @param OrderChangeOrderStateAction|callable $action
120
     * @return $this
121 1
     */
122
    public function changeOrderState($action = null)
123 1
    {
124 1
        $this->addAction($this->resolveAction(OrderChangeOrderStateAction::class, $action));
125
        return $this;
126
    }
127
128
    /**
129
     * @link https://docs.commercetools.com/http-api-projects-orders.html#change-paymentstate
130
     * @param OrderChangePaymentStateAction|callable $action
131
     * @return $this
132 1
     */
133
    public function changePaymentState($action = null)
134 1
    {
135 1
        $this->addAction($this->resolveAction(OrderChangePaymentStateAction::class, $action));
136
        return $this;
137
    }
138
139
    /**
140
     * @link https://docs.commercetools.com/http-api-projects-orders.html#change-shipmentstate
141
     * @param OrderChangeShipmentStateAction|callable $action
142
     * @return $this
143 1
     */
144
    public function changeShipmentState($action = null)
145 1
    {
146 1
        $this->addAction($this->resolveAction(OrderChangeShipmentStateAction::class, $action));
147
        return $this;
148
    }
149
150
    /**
151
     * @link https://docs.commercetools.com/http-api-projects-orders.html#import-state-for-customlineitems
152
     * @param OrderImportCustomLineItemStateAction|callable $action
153
     * @return $this
154 1
     */
155
    public function importCustomLineItemState($action = null)
156 1
    {
157 1
        $this->addAction($this->resolveAction(OrderImportCustomLineItemStateAction::class, $action));
158
        return $this;
159
    }
160
161
    /**
162
     * @link https://docs.commercetools.com/http-api-projects-orders.html#import-state-for-lineitems
163
     * @param OrderImportLineItemStateAction|callable $action
164
     * @return $this
165 1
     */
166
    public function importLineItemState($action = null)
167 1
    {
168 1
        $this->addAction($this->resolveAction(OrderImportLineItemStateAction::class, $action));
169
        return $this;
170
    }
171
172
    /**
173
     * @link https://docs.commercetools.com/http-api-projects-orders.html#remove-delivery
174
     * @param OrderRemoveDeliveryAction|callable $action
175
     * @return $this
176 1
     */
177
    public function removeDelivery($action = null)
178 1
    {
179 1
        $this->addAction($this->resolveAction(OrderRemoveDeliveryAction::class, $action));
180
        return $this;
181
    }
182
183
    /**
184
     * @link https://docs.commercetools.com/http-api-projects-orders.html#remove-itemshippingaddress
185
     * @param OrderRemoveItemShippingAddressAction|callable $action
186
     * @return $this
187 1
     */
188
    public function removeItemShippingAddress($action = null)
189 1
    {
190 1
        $this->addAction($this->resolveAction(OrderRemoveItemShippingAddressAction::class, $action));
191
        return $this;
192
    }
193
194
    /**
195
     * @link https://docs.commercetools.com/http-api-projects-orders.html#remove-parcel-from-delivery
196
     * @param OrderRemoveParcelFromDeliveryAction|callable $action
197
     * @return $this
198 1
     */
199
    public function removeParcelFromDelivery($action = null)
200 1
    {
201 1
        $this->addAction($this->resolveAction(OrderRemoveParcelFromDeliveryAction::class, $action));
202
        return $this;
203
    }
204
205
    /**
206
     * @link https://docs.commercetools.com/http-api-projects-orders.html#remove-payment
207
     * @param OrderRemovePaymentAction|callable $action
208
     * @return $this
209 1
     */
210
    public function removePayment($action = null)
211 1
    {
212 1
        $this->addAction($this->resolveAction(OrderRemovePaymentAction::class, $action));
213
        return $this;
214
    }
215
216
    /**
217
     * @link https://docs.commercetools.com/http-api-projects-orders.html#set-billing-address
218
     * @param OrderSetBillingAddress|callable $action
219
     * @return $this
220 1
     */
221
    public function setBillingAddress($action = null)
222 1
    {
223 1
        $this->addAction($this->resolveAction(OrderSetBillingAddress::class, $action));
224
        return $this;
225
    }
226
227
    /**
228
     *
229
     * @param OrderSetBillingAddressCustomFieldAction|callable $action
230
     * @return $this
231 1
     */
232
    public function setBillingAddressCustomField($action = null)
233 1
    {
234 1
        $this->addAction($this->resolveAction(OrderSetBillingAddressCustomFieldAction::class, $action));
235
        return $this;
236
    }
237
238
    /**
239
     *
240
     * @param OrderSetBillingAddressCustomTypeAction|callable $action
241
     * @return $this
242 1
     */
243
    public function setBillingAddressCustomType($action = null)
244 1
    {
245 1
        $this->addAction($this->resolveAction(OrderSetBillingAddressCustomTypeAction::class, $action));
246
        return $this;
247
    }
248
249
    /**
250
     *
251
     * @param OrderSetCustomFieldAction|callable $action
252
     * @return $this
253 1
     */
254
    public function setCustomField($action = null)
255 1
    {
256 1
        $this->addAction($this->resolveAction(OrderSetCustomFieldAction::class, $action));
257
        return $this;
258
    }
259
260
    /**
261
     *
262
     * @param OrderSetCustomLineItemCustomFieldAction|callable $action
263
     * @return $this
264 1
     */
265
    public function setCustomLineItemCustomField($action = null)
266 1
    {
267 1
        $this->addAction($this->resolveAction(OrderSetCustomLineItemCustomFieldAction::class, $action));
268
        return $this;
269
    }
270
271
    /**
272
     *
273
     * @param OrderSetCustomLineItemCustomTypeAction|callable $action
274
     * @return $this
275 1
     */
276
    public function setCustomLineItemCustomType($action = null)
277 1
    {
278 1
        $this->addAction($this->resolveAction(OrderSetCustomLineItemCustomTypeAction::class, $action));
279
        return $this;
280
    }
281
282
    /**
283
     * @link https://docs.commercetools.com/http-api-projects-orders.html#set-customlineitemshippingdetails
284
     * @param OrderSetCustomLineItemShippingDetailsAction|callable $action
285
     * @return $this
286 1
     */
287
    public function setCustomLineItemShippingDetails($action = null)
288 1
    {
289 1
        $this->addAction($this->resolveAction(OrderSetCustomLineItemShippingDetailsAction::class, $action));
290
        return $this;
291
    }
292
293
    /**
294
     *
295
     * @param OrderSetCustomTypeAction|callable $action
296
     * @return $this
297 1
     */
298
    public function setCustomType($action = null)
299 1
    {
300 1
        $this->addAction($this->resolveAction(OrderSetCustomTypeAction::class, $action));
301
        return $this;
302
    }
303
304
    /**
305
     * @link https://docs.commercetools.com/http-api-projects-orders.html#set-customer-email
306
     * @param OrderSetCustomerEmail|callable $action
307
     * @return $this
308 1
     */
309
    public function setCustomerEmail($action = null)
310 1
    {
311 1
        $this->addAction($this->resolveAction(OrderSetCustomerEmail::class, $action));
312
        return $this;
313
    }
314
315
    /**
316
     * @link https://docs.commercetools.com/http-api-projects-orders.html#set-customer-id
317
     * @param OrderSetCustomerIdAction|callable $action
318
     * @return $this
319 1
     */
320
    public function setCustomerId($action = null)
321 1
    {
322 1
        $this->addAction($this->resolveAction(OrderSetCustomerIdAction::class, $action));
323
        return $this;
324
    }
325
326
    /**
327
     * @link https://docs.commercetools.com/http-api-projects-orders.html#set-delivery-address
328
     * @param OrderSetDeliveryAddressAction|callable $action
329
     * @return $this
330 1
     */
331
    public function setDeliveryAddress($action = null)
332 1
    {
333 1
        $this->addAction($this->resolveAction(OrderSetDeliveryAddressAction::class, $action));
334
        return $this;
335
    }
336
337
    /**
338
     *
339
     * @param OrderSetDeliveryAddressCustomFieldAction|callable $action
340
     * @return $this
341 1
     */
342
    public function setDeliveryAddressCustomField($action = null)
343 1
    {
344 1
        $this->addAction($this->resolveAction(OrderSetDeliveryAddressCustomFieldAction::class, $action));
345
        return $this;
346
    }
347
348
    /**
349
     *
350
     * @param OrderSetDeliveryAddressCustomTypeAction|callable $action
351
     * @return $this
352 1
     */
353
    public function setDeliveryAddressCustomType($action = null)
354 1
    {
355 1
        $this->addAction($this->resolveAction(OrderSetDeliveryAddressCustomTypeAction::class, $action));
356
        return $this;
357
    }
358
359
    /**
360
     * @link https://docs.commercetools.com/http-api-projects-orders.html#set-delivery-items
361
     * @param OrderSetDeliveryItemsAction|callable $action
362
     * @return $this
363 1
     */
364
    public function setDeliveryItems($action = null)
365 1
    {
366 1
        $this->addAction($this->resolveAction(OrderSetDeliveryItemsAction::class, $action));
367
        return $this;
368
    }
369
370
    /**
371
     *
372
     * @param OrderSetItemShippingAddressCustomFieldAction|callable $action
373
     * @return $this
374 1
     */
375
    public function setItemShippingAddressCustomField($action = null)
376 1
    {
377 1
        $this->addAction($this->resolveAction(OrderSetItemShippingAddressCustomFieldAction::class, $action));
378
        return $this;
379
    }
380
381
    /**
382
     *
383
     * @param OrderSetItemShippingAddressCustomTypeAction|callable $action
384
     * @return $this
385 1
     */
386
    public function setItemShippingAddressCustomType($action = null)
387 1
    {
388 1
        $this->addAction($this->resolveAction(OrderSetItemShippingAddressCustomTypeAction::class, $action));
389
        return $this;
390
    }
391
392
    /**
393
     *
394
     * @param OrderSetLineItemCustomFieldAction|callable $action
395
     * @return $this
396 1
     */
397
    public function setLineItemCustomField($action = null)
398 1
    {
399 1
        $this->addAction($this->resolveAction(OrderSetLineItemCustomFieldAction::class, $action));
400
        return $this;
401
    }
402
403
    /**
404
     *
405
     * @param OrderSetLineItemCustomTypeAction|callable $action
406
     * @return $this
407 1
     */
408
    public function setLineItemCustomType($action = null)
409 1
    {
410 1
        $this->addAction($this->resolveAction(OrderSetLineItemCustomTypeAction::class, $action));
411
        return $this;
412
    }
413
414
    /**
415
     * @link https://docs.commercetools.com/http-api-projects-orders.html#set-lineitemshippingdetails
416
     * @param OrderSetLineItemShippingDetailsAction|callable $action
417
     * @return $this
418 1
     */
419
    public function setLineItemShippingDetails($action = null)
420 1
    {
421 1
        $this->addAction($this->resolveAction(OrderSetLineItemShippingDetailsAction::class, $action));
422
        return $this;
423
    }
424
425
    /**
426
     * @link https://docs.commercetools.com/http-api-projects-orders.html#set-locale
427
     * @param OrderSetLocaleAction|callable $action
428
     * @return $this
429 1
     */
430
    public function setLocale($action = null)
431 1
    {
432 1
        $this->addAction($this->resolveAction(OrderSetLocaleAction::class, $action));
433
        return $this;
434
    }
435
436
    /**
437
     * @link https://docs.commercetools.com/http-api-projects-orders.html#set-order-number
438
     * @param OrderSetOrderNumberAction|callable $action
439
     * @return $this
440 1
     */
441
    public function setOrderNumber($action = null)
442 1
    {
443 1
        $this->addAction($this->resolveAction(OrderSetOrderNumberAction::class, $action));
444
        return $this;
445
    }
446
447
    /**
448
     * @link https://docs.commercetools.com/http-api-projects-orders.html#set-parcel-items
449
     * @param OrderSetParcelItemsAction|callable $action
450
     * @return $this
451 1
     */
452
    public function setParcelItems($action = null)
453 1
    {
454 1
        $this->addAction($this->resolveAction(OrderSetParcelItemsAction::class, $action));
455
        return $this;
456
    }
457
458
    /**
459
     * @link https://docs.commercetools.com/http-api-projects-orders.html#set-parcel-measurements
460
     * @param OrderSetParcelMeasurementsAction|callable $action
461
     * @return $this
462 1
     */
463
    public function setParcelMeasurements($action = null)
464 1
    {
465 1
        $this->addAction($this->resolveAction(OrderSetParcelMeasurementsAction::class, $action));
466
        return $this;
467
    }
468
469
    /**
470
     * @link https://docs.commercetools.com/http-api-projects-orders.html#set-parcel-tracking-data
471
     * @param OrderSetParcelTrackingDataAction|callable $action
472
     * @return $this
473 1
     */
474
    public function setParcelTrackingData($action = null)
475 1
    {
476 1
        $this->addAction($this->resolveAction(OrderSetParcelTrackingDataAction::class, $action));
477
        return $this;
478
    }
479
480
    /**
481
     * @link https://docs.commercetools.com/http-api-projects-orders.html#set-delivery-items
482
     * @param OrderSetReturnInfoAction|callable $action
483
     * @return $this
484 1
     */
485
    public function setReturnInfo($action = null)
486 1
    {
487 1
        $this->addAction($this->resolveAction(OrderSetReturnInfoAction::class, $action));
488
        return $this;
489
    }
490
491
    /**
492
     * @link https://docs.commercetools.com/http-api-projects-orders.html#set-returnpaymentstate
493
     * @param OrderSetReturnPaymentStateAction|callable $action
494
     * @return $this
495 1
     */
496
    public function setReturnPaymentState($action = null)
497 1
    {
498 1
        $this->addAction($this->resolveAction(OrderSetReturnPaymentStateAction::class, $action));
499
        return $this;
500
    }
501
502
    /**
503
     * @link https://docs.commercetools.com/http-api-projects-orders.html#set-returnshipmentstate
504
     * @param OrderSetReturnShipmentStateAction|callable $action
505
     * @return $this
506 1
     */
507
    public function setReturnShipmentState($action = null)
508 1
    {
509 1
        $this->addAction($this->resolveAction(OrderSetReturnShipmentStateAction::class, $action));
510
        return $this;
511
    }
512
513
    /**
514
     * @link https://docs.commercetools.com/http-api-projects-orders.html#set-shipping-address
515
     * @param OrderSetShippingAddress|callable $action
516
     * @return $this
517 1
     */
518
    public function setShippingAddress($action = null)
519 1
    {
520 1
        $this->addAction($this->resolveAction(OrderSetShippingAddress::class, $action));
521
        return $this;
522
    }
523
524
    /**
525
     *
526
     * @param OrderSetShippingAddressCustomFieldAction|callable $action
527
     * @return $this
528 1
     */
529
    public function setShippingAddressCustomField($action = null)
530 1
    {
531 1
        $this->addAction($this->resolveAction(OrderSetShippingAddressCustomFieldAction::class, $action));
532
        return $this;
533
    }
534
535
    /**
536
     *
537
     * @param OrderSetShippingAddressCustomTypeAction|callable $action
538
     * @return $this
539 1
     */
540
    public function setShippingAddressCustomType($action = null)
541 1
    {
542 1
        $this->addAction($this->resolveAction(OrderSetShippingAddressCustomTypeAction::class, $action));
543
        return $this;
544
    }
545
546
    /**
547
     * @link https://docs.commercetools.com/http-api-projects-orders.html#set-store-beta
548
     * @param OrderSetStoreAction|callable $action
549
     * @return $this
550 1
     */
551
    public function setStore($action = null)
552 1
    {
553 1
        $this->addAction($this->resolveAction(OrderSetStoreAction::class, $action));
554
        return $this;
555
    }
556
557
    /**
558
     * @link https://docs.commercetools.com/http-api-projects-orders.html#change-the-state-of-customlineitem-according-to-allowed-transitions
559
     * @param OrderTransitionCustomLineItemStateAction|callable $action
560
     * @return $this
561 1
     */
562
    public function transitionCustomLineItemState($action = null)
563 1
    {
564 1
        $this->addAction($this->resolveAction(OrderTransitionCustomLineItemStateAction::class, $action));
565
        return $this;
566
    }
567
568
    /**
569
     * @link https://docs.commercetools.com/http-api-projects-orders.html#change-the-state-of-lineitem-according-to-allowed-transitions
570
     * @param OrderTransitionLineItemStateAction|callable $action
571
     * @return $this
572 1
     */
573
    public function transitionLineItemState($action = null)
574 1
    {
575 1
        $this->addAction($this->resolveAction(OrderTransitionLineItemStateAction::class, $action));
576
        return $this;
577
    }
578
579
    /**
580
     * @link https://docs.commercetools.com/http-api-projects-orders.html#transition-state
581
     * @param OrderTransitionStateAction|callable $action
582
     * @return $this
583 1
     */
584
    public function transitionState($action = null)
585 1
    {
586 1
        $this->addAction($this->resolveAction(OrderTransitionStateAction::class, $action));
587
        return $this;
588
    }
589
590
    /**
591
     * @link https://docs.commercetools.com/http-api-projects-orders.html#update-itemshippingaddress
592
     * @param OrderUpdateItemShippingAddressAction|callable $action
593
     * @return $this
594 1
     */
595
    public function updateItemShippingAddress($action = null)
596 1
    {
597 1
        $this->addAction($this->resolveAction(OrderUpdateItemShippingAddressAction::class, $action));
598
        return $this;
599
    }
600
601
    /**
602
     * @link https://docs.commercetools.com/http-api-projects-orders.html#update-syncinfo
603
     * @param OrderUpdateSyncInfoAction|callable $action
604
     * @return $this
605
     */
606
    public function updateSyncInfo($action = null)
607
    {
608
        $this->addAction($this->resolveAction(OrderUpdateSyncInfoAction::class, $action));
609
        return $this;
610
    }
611
612
    /**
613
     * @return OrdersActionBuilder
614 49
     */
615
    public static function of()
616 49
    {
617 49
        return new self();
618 49
    }
619 49
620
    /**
621 49
     * @param $class
622 49
     * @param $action
623
     * @return AbstractAction
624
     * @throws InvalidArgumentException
625
     */
626
    private function resolveAction($class, $action = null)
627
    {
628
        if (is_null($action) || is_callable($action)) {
629
            $callback = $action;
630
            $emptyAction = $class::of();
631
            $action = $this->callback($emptyAction, $callback);
632
        }
633
        if ($action instanceof $class) {
634 49
            return $action;
635
        }
636 49
        throw new InvalidArgumentException(
637
            sprintf('Expected method to be called with or callable to return %s', $class)
638
        );
639 49
    }
640
641
    /**
642
     * @param $action
643
     * @param callable $callback
644
     * @return AbstractAction
645
     */
646 49
    private function callback($action, callable $callback = null)
647
    {
648 49
        if (!is_null($callback)) {
649 49
            $action = $callback($action);
650
        }
651
        return $action;
652
    }
653
654
    /**
655 49
     * @param AbstractAction $action
656
     * @return $this;
657 49
     */
658
    public function addAction(AbstractAction $action)
659
    {
660
        $this->actions[] = $action;
661
        return $this;
662
    }
663
664
    /**
665
     * @return array
666
     */
667
    public function getActions()
668
    {
669
        return $this->actions;
670
    }
671
672
673
    /**
674
     * @param array $actions
675
     * @return $this
676
     */
677
    public function setActions(array $actions)
678
    {
679
        $this->actions = $actions;
680
        return $this;
681
    }
682
}
683