Passed
Push — develop ( 75f654...c9f5c5 )
by Jens
09:18 queued 12s
created

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