Passed
Pull Request — develop (#423)
by nikos
09:13
created

OrdersActionBuilder::removeItemShippingAddress()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 2
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 1
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\OrderSetCustomFieldAction;
23
use Commercetools\Core\Request\Orders\Command\OrderSetCustomLineItemCustomFieldAction;
24
use Commercetools\Core\Request\Orders\Command\OrderSetCustomLineItemCustomTypeAction;
25
use Commercetools\Core\Request\Orders\Command\OrderSetCustomLineItemShippingDetailsAction;
26
use Commercetools\Core\Request\Orders\Command\OrderSetCustomTypeAction;
27
use Commercetools\Core\Request\Orders\Command\OrderSetCustomerEmail;
28
use Commercetools\Core\Request\Orders\Command\OrderSetDeliveryAddressAction;
29
use Commercetools\Core\Request\Orders\Command\OrderSetDeliveryItemsAction;
30
use Commercetools\Core\Request\Orders\Command\OrderSetLineItemCustomFieldAction;
31
use Commercetools\Core\Request\Orders\Command\OrderSetLineItemCustomTypeAction;
32
use Commercetools\Core\Request\Orders\Command\OrderSetLineItemShippingDetailsAction;
33
use Commercetools\Core\Request\Orders\Command\OrderSetLocaleAction;
34
use Commercetools\Core\Request\Orders\Command\OrderSetOrderNumberAction;
35
use Commercetools\Core\Request\Orders\Command\OrderSetParcelItemsAction;
36
use Commercetools\Core\Request\Orders\Command\OrderSetParcelMeasurementsAction;
37
use Commercetools\Core\Request\Orders\Command\OrderSetParcelTrackingDataAction;
38
use Commercetools\Core\Request\Orders\Command\OrderSetReturnPaymentStateAction;
39
use Commercetools\Core\Request\Orders\Command\OrderSetReturnShipmentStateAction;
40
use Commercetools\Core\Request\Orders\Command\OrderSetShippingAddress;
41
use Commercetools\Core\Request\Orders\Command\OrderTransitionCustomLineItemStateAction;
42
use Commercetools\Core\Request\Orders\Command\OrderTransitionLineItemStateAction;
43
use Commercetools\Core\Request\Orders\Command\OrderTransitionStateAction;
44
use Commercetools\Core\Request\Orders\Command\OrderUpdateItemShippingAddressAction;
45
use Commercetools\Core\Request\Orders\Command\OrderUpdateSyncInfoAction;
46
47
class OrdersActionBuilder
48
{
49
    private $actions = [];
50
51
    /**
52
     * @link https://docs.commercetools.com/http-api-projects-orders.html#add-delivery
53
     * @param OrderAddDeliveryAction|callable $action
54
     * @return $this
55
     */
56 1
    public function addDelivery($action = null)
57
    {
58 1
        $this->addAction($this->resolveAction(OrderAddDeliveryAction::class, $action));
59 1
        return $this;
60
    }
61
62
    /**
63
     * @link https://docs.commercetools.com/http-api-projects-orders.html#add-itemshippingaddress
64
     * @param OrderAddItemShippingAddressAction|callable $action
65
     * @return $this
66
     */
67 1
    public function addItemShippingAddress($action = null)
68
    {
69 1
        $this->addAction($this->resolveAction(OrderAddItemShippingAddressAction::class, $action));
70 1
        return $this;
71
    }
72
73
    /**
74
     * @link https://docs.commercetools.com/http-api-projects-orders.html#add-parcel
75
     * @param OrderAddParcelToDeliveryAction|callable $action
76
     * @return $this
77
     */
78 1
    public function addParcelToDelivery($action = null)
79
    {
80 1
        $this->addAction($this->resolveAction(OrderAddParcelToDeliveryAction::class, $action));
81 1
        return $this;
82
    }
83
84
    /**
85
     * @link https://docs.commercetools.com/http-api-projects-orders.html#add-payment
86
     * @param OrderAddPaymentAction|callable $action
87
     * @return $this
88
     */
89 1
    public function addPayment($action = null)
90
    {
91 1
        $this->addAction($this->resolveAction(OrderAddPaymentAction::class, $action));
92 1
        return $this;
93
    }
94
95
    /**
96
     * @link https://docs.commercetools.com/http-api-projects-orders.html#addreturninfo
97
     * @param OrderAddReturnInfoAction|callable $action
98
     * @return $this
99
     */
100 1
    public function addReturnInfo($action = null)
101
    {
102 1
        $this->addAction($this->resolveAction(OrderAddReturnInfoAction::class, $action));
103 1
        return $this;
104
    }
105
106
    /**
107
     * @link https://docs.commercetools.com/http-api-projects-orders.html#change-orderstate
108
     * @param OrderChangeOrderStateAction|callable $action
109
     * @return $this
110
     */
111 1
    public function changeOrderState($action = null)
112
    {
113 1
        $this->addAction($this->resolveAction(OrderChangeOrderStateAction::class, $action));
114 1
        return $this;
115
    }
116
117
    /**
118
     * @link https://docs.commercetools.com/http-api-projects-orders.html#change-paymentstate
119
     * @param OrderChangePaymentStateAction|callable $action
120
     * @return $this
121
     */
122 1
    public function changePaymentState($action = null)
123
    {
124 1
        $this->addAction($this->resolveAction(OrderChangePaymentStateAction::class, $action));
125 1
        return $this;
126
    }
127
128
    /**
129
     * @link https://docs.commercetools.com/http-api-projects-orders.html#change-shipmentstate
130
     * @param OrderChangeShipmentStateAction|callable $action
131
     * @return $this
132
     */
133 1
    public function changeShipmentState($action = null)
134
    {
135 1
        $this->addAction($this->resolveAction(OrderChangeShipmentStateAction::class, $action));
136 1
        return $this;
137
    }
138
139
    /**
140
     * @link https://docs.commercetools.com/http-api-projects-orders.html#import-state-for-customlineitems
141
     * @param OrderImportCustomLineItemStateAction|callable $action
142
     * @return $this
143
     */
144 1
    public function importCustomLineItemState($action = null)
145
    {
146 1
        $this->addAction($this->resolveAction(OrderImportCustomLineItemStateAction::class, $action));
147 1
        return $this;
148
    }
149
150
    /**
151
     * @link https://docs.commercetools.com/http-api-projects-orders.html#import-state-for-lineitems
152
     * @param OrderImportLineItemStateAction|callable $action
153
     * @return $this
154
     */
155 1
    public function importLineItemState($action = null)
156
    {
157 1
        $this->addAction($this->resolveAction(OrderImportLineItemStateAction::class, $action));
158 1
        return $this;
159
    }
160
161
    /**
162
     * @link https://docs.commercetools.com/http-api-projects-orders.html#remove-delivery
163
     * @param OrderRemoveDeliveryAction|callable $action
164
     * @return $this
165
     */
166 1
    public function removeDelivery($action = null)
167
    {
168 1
        $this->addAction($this->resolveAction(OrderRemoveDeliveryAction::class, $action));
169 1
        return $this;
170
    }
171
172
    /**
173
     * @link https://docs.commercetools.com/http-api-projects-orders.html#remove-itemshippingaddress
174
     * @param OrderRemoveItemShippingAddressAction|callable $action
175
     * @return $this
176
     */
177 1
    public function removeItemShippingAddress($action = null)
178
    {
179 1
        $this->addAction($this->resolveAction(OrderRemoveItemShippingAddressAction::class, $action));
180 1
        return $this;
181
    }
182
183
    /**
184
     * @link https://docs.commercetools.com/http-api-projects-orders.html#remove-parcel-from-delivery
185
     * @param OrderRemoveParcelFromDeliveryAction|callable $action
186
     * @return $this
187
     */
188 1
    public function removeParcelFromDelivery($action = null)
189
    {
190 1
        $this->addAction($this->resolveAction(OrderRemoveParcelFromDeliveryAction::class, $action));
191 1
        return $this;
192
    }
193
194
    /**
195
     * @link https://docs.commercetools.com/http-api-projects-orders.html#remove-payment
196
     * @param OrderRemovePaymentAction|callable $action
197
     * @return $this
198
     */
199 1
    public function removePayment($action = null)
200
    {
201 1
        $this->addAction($this->resolveAction(OrderRemovePaymentAction::class, $action));
202 1
        return $this;
203
    }
204
205
    /**
206
     * @link https://docs.commercetools.com/http-api-projects-orders.html#set-billing-address
207
     * @param OrderSetBillingAddress|callable $action
208
     * @return $this
209
     */
210 1
    public function setBillingAddress($action = null)
211
    {
212 1
        $this->addAction($this->resolveAction(OrderSetBillingAddress::class, $action));
213 1
        return $this;
214
    }
215
216
    /**
217
     *
218
     * @param OrderSetCustomFieldAction|callable $action
219
     * @return $this
220
     */
221 1
    public function setCustomField($action = null)
222
    {
223 1
        $this->addAction($this->resolveAction(OrderSetCustomFieldAction::class, $action));
224 1
        return $this;
225
    }
226
227
    /**
228
     *
229
     * @param OrderSetCustomLineItemCustomFieldAction|callable $action
230
     * @return $this
231
     */
232 1
    public function setCustomLineItemCustomField($action = null)
233
    {
234 1
        $this->addAction($this->resolveAction(OrderSetCustomLineItemCustomFieldAction::class, $action));
235 1
        return $this;
236
    }
237
238
    /**
239
     *
240
     * @param OrderSetCustomLineItemCustomTypeAction|callable $action
241
     * @return $this
242
     */
243 1
    public function setCustomLineItemCustomType($action = null)
244
    {
245 1
        $this->addAction($this->resolveAction(OrderSetCustomLineItemCustomTypeAction::class, $action));
246 1
        return $this;
247
    }
248
249
    /**
250
     * @link https://docs.commercetools.com/http-api-projects-orders.html#set-customlineitemshippingdetails
251
     * @param OrderSetCustomLineItemShippingDetailsAction|callable $action
252
     * @return $this
253
     */
254 1
    public function setCustomLineItemShippingDetails($action = null)
255
    {
256 1
        $this->addAction($this->resolveAction(OrderSetCustomLineItemShippingDetailsAction::class, $action));
257 1
        return $this;
258
    }
259
260
    /**
261
     *
262
     * @param OrderSetCustomTypeAction|callable $action
263
     * @return $this
264
     */
265 1
    public function setCustomType($action = null)
266
    {
267 1
        $this->addAction($this->resolveAction(OrderSetCustomTypeAction::class, $action));
268 1
        return $this;
269
    }
270
271
    /**
272
     * @link https://docs.commercetools.com/http-api-projects-orders.html#set-customer-email
273
     * @param OrderSetCustomerEmail|callable $action
274
     * @return $this
275
     */
276 1
    public function setCustomerEmail($action = null)
277
    {
278 1
        $this->addAction($this->resolveAction(OrderSetCustomerEmail::class, $action));
279 1
        return $this;
280
    }
281
282
    /**
283
     * @link https://docs.commercetools.com/http-api-projects-orders.html#set-delivery-address
284
     * @param OrderSetDeliveryAddressAction|callable $action
285
     * @return $this
286
     */
287 1
    public function setDeliveryAddress($action = null)
288
    {
289 1
        $this->addAction($this->resolveAction(OrderSetDeliveryAddressAction::class, $action));
290 1
        return $this;
291
    }
292
293
    /**
294
     * @link https://docs.commercetools.com/http-api-projects-orders.html#set-delivery-items
295
     * @param OrderSetDeliveryItemsAction|callable $action
296
     * @return $this
297
     */
298 1
    public function setDeliveryItems($action = null)
299
    {
300 1
        $this->addAction($this->resolveAction(OrderSetDeliveryItemsAction::class, $action));
301 1
        return $this;
302
    }
303
304
    /**
305
     *
306
     * @param OrderSetLineItemCustomFieldAction|callable $action
307
     * @return $this
308
     */
309 1
    public function setLineItemCustomField($action = null)
310
    {
311 1
        $this->addAction($this->resolveAction(OrderSetLineItemCustomFieldAction::class, $action));
312 1
        return $this;
313
    }
314
315
    /**
316
     *
317
     * @param OrderSetLineItemCustomTypeAction|callable $action
318
     * @return $this
319
     */
320 1
    public function setLineItemCustomType($action = null)
321
    {
322 1
        $this->addAction($this->resolveAction(OrderSetLineItemCustomTypeAction::class, $action));
323 1
        return $this;
324
    }
325
326
    /**
327
     * @link https://docs.commercetools.com/http-api-projects-orders.html#set-lineitemshippingdetails
328
     * @param OrderSetLineItemShippingDetailsAction|callable $action
329
     * @return $this
330
     */
331 1
    public function setLineItemShippingDetails($action = null)
332
    {
333 1
        $this->addAction($this->resolveAction(OrderSetLineItemShippingDetailsAction::class, $action));
334 1
        return $this;
335
    }
336
337
    /**
338
     * @link https://docs.commercetools.com/http-api-projects-orders.html#set-locale
339
     * @param OrderSetLocaleAction|callable $action
340
     * @return $this
341
     */
342 1
    public function setLocale($action = null)
343
    {
344 1
        $this->addAction($this->resolveAction(OrderSetLocaleAction::class, $action));
345 1
        return $this;
346
    }
347
348
    /**
349
     * @link https://docs.commercetools.com/http-api-projects-orders.html#set-order-number
350
     * @param OrderSetOrderNumberAction|callable $action
351
     * @return $this
352
     */
353 1
    public function setOrderNumber($action = null)
354
    {
355 1
        $this->addAction($this->resolveAction(OrderSetOrderNumberAction::class, $action));
356 1
        return $this;
357
    }
358
359
    /**
360
     * @link https://docs.commercetools.com/http-api-projects-orders.html#set-parcel-items
361
     * @param OrderSetParcelItemsAction|callable $action
362
     * @return $this
363
     */
364 1
    public function setParcelItems($action = null)
365
    {
366 1
        $this->addAction($this->resolveAction(OrderSetParcelItemsAction::class, $action));
367 1
        return $this;
368
    }
369
370
    /**
371
     * @link https://docs.commercetools.com/http-api-projects-orders.html#set-parcel-measurements
372
     * @param OrderSetParcelMeasurementsAction|callable $action
373
     * @return $this
374
     */
375 1
    public function setParcelMeasurements($action = null)
376
    {
377 1
        $this->addAction($this->resolveAction(OrderSetParcelMeasurementsAction::class, $action));
378 1
        return $this;
379
    }
380
381
    /**
382
     * @link https://docs.commercetools.com/http-api-projects-orders.html#set-parcel-tracking-data
383
     * @param OrderSetParcelTrackingDataAction|callable $action
384
     * @return $this
385
     */
386 1
    public function setParcelTrackingData($action = null)
387
    {
388 1
        $this->addAction($this->resolveAction(OrderSetParcelTrackingDataAction::class, $action));
389 1
        return $this;
390
    }
391
392
    /**
393
     * @link https://docs.commercetools.com/http-api-projects-orders.html#set-returnpaymentstate
394
     * @param OrderSetReturnPaymentStateAction|callable $action
395
     * @return $this
396
     */
397 1
    public function setReturnPaymentState($action = null)
398
    {
399 1
        $this->addAction($this->resolveAction(OrderSetReturnPaymentStateAction::class, $action));
400 1
        return $this;
401
    }
402
403
    /**
404
     * @link https://docs.commercetools.com/http-api-projects-orders.html#set-returnshipmentstate
405
     * @param OrderSetReturnShipmentStateAction|callable $action
406
     * @return $this
407
     */
408 1
    public function setReturnShipmentState($action = null)
409
    {
410 1
        $this->addAction($this->resolveAction(OrderSetReturnShipmentStateAction::class, $action));
411 1
        return $this;
412
    }
413
414
    /**
415
     * @link https://docs.commercetools.com/http-api-projects-orders.html#set-shipping-address
416
     * @param OrderSetShippingAddress|callable $action
417
     * @return $this
418
     */
419 1
    public function setShippingAddress($action = null)
420
    {
421 1
        $this->addAction($this->resolveAction(OrderSetShippingAddress::class, $action));
422 1
        return $this;
423
    }
424
425
    /**
426
     * @link https://docs.commercetools.com/http-api-projects-orders.html#change-the-state-of-customlineitem-according-to-allowed-transitions
427
     * @param OrderTransitionCustomLineItemStateAction|callable $action
428
     * @return $this
429
     */
430 1
    public function transitionCustomLineItemState($action = null)
431
    {
432 1
        $this->addAction($this->resolveAction(OrderTransitionCustomLineItemStateAction::class, $action));
433 1
        return $this;
434
    }
435
436
    /**
437
     * @link https://docs.commercetools.com/http-api-projects-orders.html#change-the-state-of-lineitem-according-to-allowed-transitions
438
     * @param OrderTransitionLineItemStateAction|callable $action
439
     * @return $this
440
     */
441 1
    public function transitionLineItemState($action = null)
442
    {
443 1
        $this->addAction($this->resolveAction(OrderTransitionLineItemStateAction::class, $action));
444 1
        return $this;
445
    }
446
447
    /**
448
     * @link https://docs.commercetools.com/http-api-projects-orders.html#transition-state
449
     * @param OrderTransitionStateAction|callable $action
450
     * @return $this
451
     */
452 1
    public function transitionState($action = null)
453
    {
454 1
        $this->addAction($this->resolveAction(OrderTransitionStateAction::class, $action));
455 1
        return $this;
456
    }
457
458
    /**
459
     * @link https://docs.commercetools.com/http-api-projects-orders.html#update-itemshippingaddress
460
     * @param OrderUpdateItemShippingAddressAction|callable $action
461
     * @return $this
462
     */
463 1
    public function updateItemShippingAddress($action = null)
464
    {
465 1
        $this->addAction($this->resolveAction(OrderUpdateItemShippingAddressAction::class, $action));
466 1
        return $this;
467
    }
468
469
    /**
470
     * @link https://docs.commercetools.com/http-api-projects-orders.html#update-syncinfo
471
     * @param OrderUpdateSyncInfoAction|callable $action
472
     * @return $this
473
     */
474 1
    public function updateSyncInfo($action = null)
475
    {
476 1
        $this->addAction($this->resolveAction(OrderUpdateSyncInfoAction::class, $action));
477 1
        return $this;
478
    }
479
480
    /**
481
     * @return OrdersActionBuilder
482
     */
483
    public function of()
484
    {
485
        return new self();
486
    }
487
488
    /**
489
     * @param $class
490
     * @param $action
491
     * @return AbstractAction
492
     * @throws InvalidArgumentException
493
     */
494 39
    private function resolveAction($class, $action = null)
495
    {
496 39
        if (is_null($action) || is_callable($action)) {
497 39
            $callback = $action;
498 39
            $emptyAction = $class::of();
499 39
            $action = $this->callback($emptyAction, $callback);
500
        }
501 39
        if ($action instanceof $class) {
502 39
            return $action;
503
        }
504
        throw new InvalidArgumentException(
505
            sprintf('Expected method to be called with or callable to return %s', $class)
506
        );
507
    }
508
509
    /**
510
     * @param $action
511
     * @param callable $callback
512
     * @return AbstractAction
513
     */
514 39
    private function callback($action, callable $callback = null)
515
    {
516 39
        if (!is_null($callback)) {
517
            $action = $callback($action);
518
        }
519 39
        return $action;
520
    }
521
522
    /**
523
     * @param AbstractAction $action
524
     * @return $this;
525
     */
526 39
    public function addAction(AbstractAction $action)
527
    {
528 39
        $this->actions[] = $action;
529 39
        return $this;
530
    }
531
532
    /**
533
     * @return array
534
     */
535 39
    public function getActions()
536
    {
537 39
        return $this->actions;
538
    }
539
540
    /**
541
     * @param array $actions
542
     * @return $this
543
     */
544
    public function setActions(array $actions)
545
    {
546
        $this->actions = $actions;
547
        return $this;
548
    }
549
}
550