Test Failed
Push — develop ( 99d0ad...a91eee )
by Jens
47:28 queued 25:36
created

CartsActionBuilder::setKey()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 2
dl 0
loc 4
ccs 2
cts 2
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\Carts\Command\CartAddCustomLineItemAction;
8
use Commercetools\Core\Request\Carts\Command\CartAddDiscountCodeAction;
9
use Commercetools\Core\Request\Carts\Command\CartAddItemShippingAddressAction;
10
use Commercetools\Core\Request\Carts\Command\CartAddLineItemAction;
11
use Commercetools\Core\Request\Carts\Command\CartAddPaymentAction;
12
use Commercetools\Core\Request\Carts\Command\CartAddShoppingListAction;
13
use Commercetools\Core\Request\Carts\Command\CartApplyDeltaToCustomLineItemShippingDetailsTargetsAction;
14
use Commercetools\Core\Request\Carts\Command\CartApplyDeltaToLineItemShippingDetailsTargetsAction;
15
use Commercetools\Core\Request\Carts\Command\CartChangeCustomLineItemMoneyAction;
16
use Commercetools\Core\Request\Carts\Command\CartChangeCustomLineItemQuantityAction;
17
use Commercetools\Core\Request\Carts\Command\CartChangeLineItemQuantityAction;
18
use Commercetools\Core\Request\Carts\Command\CartChangeTaxCalculationModeAction;
19
use Commercetools\Core\Request\Carts\Command\CartChangeTaxModeAction;
20
use Commercetools\Core\Request\Carts\Command\CartChangeTaxRoundingModeAction;
21
use Commercetools\Core\Request\Carts\Command\CartRecalculateAction;
22
use Commercetools\Core\Request\Carts\Command\CartRemoveCustomLineItemAction;
23
use Commercetools\Core\Request\Carts\Command\CartRemoveDiscountCodeAction;
24
use Commercetools\Core\Request\Carts\Command\CartRemoveItemShippingAddressAction;
25
use Commercetools\Core\Request\Carts\Command\CartRemoveLineItemAction;
26
use Commercetools\Core\Request\Carts\Command\CartRemovePaymentAction;
27
use Commercetools\Core\Request\Carts\Command\CartSetAnonymousIdAction;
28
use Commercetools\Core\Request\Carts\Command\CartSetBillingAddressAction;
29
use Commercetools\Core\Request\Carts\Command\CartSetBillingAddressCustomFieldAction;
30
use Commercetools\Core\Request\Carts\Command\CartSetBillingAddressCustomTypeAction;
31
use Commercetools\Core\Request\Carts\Command\CartSetCartTotalTaxAction;
32
use Commercetools\Core\Request\Carts\Command\CartSetCountryAction;
33
use Commercetools\Core\Request\Carts\Command\CartSetCustomFieldAction;
34
use Commercetools\Core\Request\Carts\Command\CartSetCustomLineItemCustomFieldAction;
35
use Commercetools\Core\Request\Carts\Command\CartSetCustomLineItemCustomTypeAction;
36
use Commercetools\Core\Request\Carts\Command\CartSetCustomLineItemShippingDetailsAction;
37
use Commercetools\Core\Request\Carts\Command\CartSetCustomLineItemTaxAmountAction;
38
use Commercetools\Core\Request\Carts\Command\CartSetCustomLineItemTaxRateAction;
39
use Commercetools\Core\Request\Carts\Command\CartSetCustomShippingMethodAction;
40
use Commercetools\Core\Request\Carts\Command\CartSetCustomTypeAction;
41
use Commercetools\Core\Request\Carts\Command\CartSetCustomerEmailAction;
42
use Commercetools\Core\Request\Carts\Command\CartSetCustomerGroupAction;
43
use Commercetools\Core\Request\Carts\Command\CartSetCustomerIdAction;
44
use Commercetools\Core\Request\Carts\Command\CartSetDeleteDaysAfterLastModificationAction;
45
use Commercetools\Core\Request\Carts\Command\CartSetItemShippingAddressCustomFieldAction;
46
use Commercetools\Core\Request\Carts\Command\CartSetItemShippingAddressCustomTypeAction;
47
use Commercetools\Core\Request\Carts\Command\CartSetKeyAction;
48
use Commercetools\Core\Request\Carts\Command\CartSetLineItemCustomFieldAction;
49
use Commercetools\Core\Request\Carts\Command\CartSetLineItemCustomTypeAction;
50
use Commercetools\Core\Request\Carts\Command\CartSetLineItemDistributionChannelAction;
51
use Commercetools\Core\Request\Carts\Command\CartSetLineItemPriceAction;
52
use Commercetools\Core\Request\Carts\Command\CartSetLineItemShippingDetailsAction;
53
use Commercetools\Core\Request\Carts\Command\CartSetLineItemTaxAmountAction;
54
use Commercetools\Core\Request\Carts\Command\CartSetLineItemTaxRateAction;
55
use Commercetools\Core\Request\Carts\Command\CartSetLineItemTotalPriceAction;
56
use Commercetools\Core\Request\Carts\Command\CartSetLocaleAction;
57
use Commercetools\Core\Request\Carts\Command\CartSetShippingAddressAction;
58
use Commercetools\Core\Request\Carts\Command\CartSetShippingAddressCustomFieldAction;
59
use Commercetools\Core\Request\Carts\Command\CartSetShippingAddressCustomTypeAction;
60
use Commercetools\Core\Request\Carts\Command\CartSetShippingMethodAction;
61
use Commercetools\Core\Request\Carts\Command\CartSetShippingMethodTaxAmountAction;
62
use Commercetools\Core\Request\Carts\Command\CartSetShippingMethodTaxRateAction;
63
use Commercetools\Core\Request\Carts\Command\CartSetShippingRateInputAction;
64
use Commercetools\Core\Request\Carts\Command\CartUpdateItemShippingAddressAction;
65
66
class CartsActionBuilder
67
{
68
    private $actions = [];
69
70
    /**
71
     * @link https://docs.commercetools.com/http-api-projects-carts.html#add-customlineitem
72
     * @param CartAddCustomLineItemAction|callable $action
73 1
     * @return $this
74
     */
75 1
    public function addCustomLineItem($action = null)
76 1
    {
77
        $this->addAction($this->resolveAction(CartAddCustomLineItemAction::class, $action));
78
        return $this;
79
    }
80
81
    /**
82
     * @link https://docs.commercetools.com/http-api-projects-carts.html#add-discountcode
83
     * @param CartAddDiscountCodeAction|callable $action
84 1
     * @return $this
85
     */
86 1
    public function addDiscountCode($action = null)
87 1
    {
88
        $this->addAction($this->resolveAction(CartAddDiscountCodeAction::class, $action));
89
        return $this;
90
    }
91
92
    /**
93
     * @link https://docs.commercetools.com/http-api-projects-carts.html#add-itemshippingaddress
94
     * @param CartAddItemShippingAddressAction|callable $action
95 1
     * @return $this
96
     */
97 1
    public function addItemShippingAddress($action = null)
98 1
    {
99
        $this->addAction($this->resolveAction(CartAddItemShippingAddressAction::class, $action));
100
        return $this;
101
    }
102
103
    /**
104
     * @link https://docs.commercetools.com/http-api-projects-carts.html#add-lineitem
105
     * @param CartAddLineItemAction|callable $action
106 1
     * @return $this
107
     */
108 1
    public function addLineItem($action = null)
109 1
    {
110
        $this->addAction($this->resolveAction(CartAddLineItemAction::class, $action));
111
        return $this;
112
    }
113
114
    /**
115
     * @link https://docs.commercetools.com/http-api-projects-carts.html#add-payment
116
     * @param CartAddPaymentAction|callable $action
117 1
     * @return $this
118
     */
119 1
    public function addPayment($action = null)
120 1
    {
121
        $this->addAction($this->resolveAction(CartAddPaymentAction::class, $action));
122
        return $this;
123
    }
124
125
    /**
126
     * @link https://docs.commercetools.com/http-api-projects-carts.html#add-shoppinglist
127
     * @param CartAddShoppingListAction|callable $action
128 1
     * @return $this
129
     */
130 1
    public function addShoppingList($action = null)
131 1
    {
132
        $this->addAction($this->resolveAction(CartAddShoppingListAction::class, $action));
133
        return $this;
134
    }
135
136
    /**
137
     * @link https://docs.commercetools.com/http-api-projects-carts.html#apply-deltatocustomlineitemshippingdetailstargets
138
     * @param CartApplyDeltaToCustomLineItemShippingDetailsTargetsAction|callable $action
139 1
     * @return $this
140
     */
141
    public function applyDeltaToCustomLineItemShippingDetailsTargets($action = null)
142 1
    {
143 1
        // phpcs:ignore
144
        $this->addAction($this->resolveAction(CartApplyDeltaToCustomLineItemShippingDetailsTargetsAction::class, $action));
145
        return $this;
146
    }
147
148
    /**
149
     * @link https://docs.commercetools.com/http-api-projects-carts.html#apply-deltatolineitemshippingdetailstargets
150
     * @param CartApplyDeltaToLineItemShippingDetailsTargetsAction|callable $action
151 1
     * @return $this
152
     */
153 1
    public function applyDeltaToLineItemShippingDetailsTargets($action = null)
154 1
    {
155
        $this->addAction($this->resolveAction(CartApplyDeltaToLineItemShippingDetailsTargetsAction::class, $action));
156
        return $this;
157
    }
158
159
    /**
160
     * @link https://docs.commercetools.com/http-api-projects-carts.html#change-customlineitem-money
161
     * @param CartChangeCustomLineItemMoneyAction|callable $action
162 1
     * @return $this
163
     */
164 1
    public function changeCustomLineItemMoney($action = null)
165 1
    {
166
        $this->addAction($this->resolveAction(CartChangeCustomLineItemMoneyAction::class, $action));
167
        return $this;
168
    }
169
170
    /**
171
     * @link https://docs.commercetools.com/http-api-projects-carts.html#change-customlineitem-quantity
172
     * @param CartChangeCustomLineItemQuantityAction|callable $action
173 1
     * @return $this
174
     */
175 1
    public function changeCustomLineItemQuantity($action = null)
176 1
    {
177
        $this->addAction($this->resolveAction(CartChangeCustomLineItemQuantityAction::class, $action));
178
        return $this;
179
    }
180
181
    /**
182
     * @link https://docs.commercetools.com/http-api-projects-carts.html#change-lineitem-quantity
183
     * @param CartChangeLineItemQuantityAction|callable $action
184 1
     * @return $this
185
     */
186 1
    public function changeLineItemQuantity($action = null)
187 1
    {
188
        $this->addAction($this->resolveAction(CartChangeLineItemQuantityAction::class, $action));
189
        return $this;
190
    }
191
192
    /**
193
     * @link https://docs.commercetools.com/http-api-projects-carts.html#change-tax-calculationmode
194
     * @param CartChangeTaxCalculationModeAction|callable $action
195 1
     * @return $this
196
     */
197 1
    public function changeTaxCalculationMode($action = null)
198 1
    {
199
        $this->addAction($this->resolveAction(CartChangeTaxCalculationModeAction::class, $action));
200
        return $this;
201
    }
202
203
    /**
204
     * @link https://docs.commercetools.com/http-api-projects-carts.html#change-taxmode
205
     * @param CartChangeTaxModeAction|callable $action
206 1
     * @return $this
207
     */
208 1
    public function changeTaxMode($action = null)
209 1
    {
210
        $this->addAction($this->resolveAction(CartChangeTaxModeAction::class, $action));
211
        return $this;
212
    }
213
214
    /**
215
     * @link https://docs.commercetools.com/http-api-projects-carts.html#change-tax-roundingmode
216
     * @param CartChangeTaxRoundingModeAction|callable $action
217 1
     * @return $this
218
     */
219 1
    public function changeTaxRoundingMode($action = null)
220 1
    {
221
        $this->addAction($this->resolveAction(CartChangeTaxRoundingModeAction::class, $action));
222
        return $this;
223
    }
224
225
    /**
226
     * @link https://docs.commercetools.com/http-api-projects-carts.html#recalculate
227
     * @param CartRecalculateAction|callable $action
228 1
     * @return $this
229
     */
230 1
    public function recalculate($action = null)
231 1
    {
232
        $this->addAction($this->resolveAction(CartRecalculateAction::class, $action));
233
        return $this;
234
    }
235
236
    /**
237
     * @link https://docs.commercetools.com/http-api-projects-carts.html#remove-customlineitem
238
     * @param CartRemoveCustomLineItemAction|callable $action
239 1
     * @return $this
240
     */
241 1
    public function removeCustomLineItem($action = null)
242 1
    {
243
        $this->addAction($this->resolveAction(CartRemoveCustomLineItemAction::class, $action));
244
        return $this;
245
    }
246
247
    /**
248
     * @link https://docs.commercetools.com/http-api-projects-carts.html#remove-discountcode
249
     * @param CartRemoveDiscountCodeAction|callable $action
250 1
     * @return $this
251
     */
252 1
    public function removeDiscountCode($action = null)
253 1
    {
254
        $this->addAction($this->resolveAction(CartRemoveDiscountCodeAction::class, $action));
255
        return $this;
256
    }
257
258
    /**
259
     * @link https://docs.commercetools.com/http-api-projects-carts.html#remove-itemshippingaddress
260
     * @param CartRemoveItemShippingAddressAction|callable $action
261 1
     * @return $this
262
     */
263 1
    public function removeItemShippingAddress($action = null)
264 1
    {
265
        $this->addAction($this->resolveAction(CartRemoveItemShippingAddressAction::class, $action));
266
        return $this;
267
    }
268
269
    /**
270
     * @link https://docs.commercetools.com/http-api-projects-carts.html#remove-lineitem
271
     * @param CartRemoveLineItemAction|callable $action
272 1
     * @return $this
273
     */
274 1
    public function removeLineItem($action = null)
275 1
    {
276
        $this->addAction($this->resolveAction(CartRemoveLineItemAction::class, $action));
277
        return $this;
278
    }
279
280
    /**
281
     * @link https://docs.commercetools.com/http-api-projects-carts.html#remove-payment
282
     * @param CartRemovePaymentAction|callable $action
283 1
     * @return $this
284
     */
285 1
    public function removePayment($action = null)
286 1
    {
287
        $this->addAction($this->resolveAction(CartRemovePaymentAction::class, $action));
288
        return $this;
289
    }
290
291
    /**
292
     * @link https://docs.commercetools.com/http-api-projects-carts.html#set-anonymous-id
293
     * @param CartSetAnonymousIdAction|callable $action
294 1
     * @return $this
295
     */
296 1
    public function setAnonymousId($action = null)
297 1
    {
298
        $this->addAction($this->resolveAction(CartSetAnonymousIdAction::class, $action));
299
        return $this;
300
    }
301
302
    /**
303
     * @link https://docs.commercetools.com/http-api-projects-carts.html#set-billing-address
304
     * @param CartSetBillingAddressAction|callable $action
305 1
     * @return $this
306
     */
307 1
    public function setBillingAddress($action = null)
308 1
    {
309
        $this->addAction($this->resolveAction(CartSetBillingAddressAction::class, $action));
310
        return $this;
311
    }
312
313
    /**
314
     *
315
     * @param CartSetBillingAddressCustomFieldAction|callable $action
316 1
     * @return $this
317
     */
318 1
    public function setBillingAddressCustomField($action = null)
319 1
    {
320
        $this->addAction($this->resolveAction(CartSetBillingAddressCustomFieldAction::class, $action));
321
        return $this;
322
    }
323
324
    /**
325
     *
326
     * @param CartSetBillingAddressCustomTypeAction|callable $action
327 1
     * @return $this
328
     */
329 1
    public function setBillingAddressCustomType($action = null)
330 1
    {
331
        $this->addAction($this->resolveAction(CartSetBillingAddressCustomTypeAction::class, $action));
332
        return $this;
333
    }
334
335
    /**
336
     * @link https://docs.commercetools.com/http-api-projects-carts.html#set-cart-total-tax
337
     * @param CartSetCartTotalTaxAction|callable $action
338 1
     * @return $this
339
     */
340 1
    public function setCartTotalTax($action = null)
341 1
    {
342
        $this->addAction($this->resolveAction(CartSetCartTotalTaxAction::class, $action));
343
        return $this;
344
    }
345
346
    /**
347
     * @link https://docs.commercetools.com/http-api-projects-carts.html#set-country
348
     * @param CartSetCountryAction|callable $action
349 1
     * @return $this
350
     */
351 1
    public function setCountry($action = null)
352 1
    {
353
        $this->addAction($this->resolveAction(CartSetCountryAction::class, $action));
354
        return $this;
355
    }
356
357
    /**
358
     *
359
     * @param CartSetCustomFieldAction|callable $action
360 1
     * @return $this
361
     */
362 1
    public function setCustomField($action = null)
363 1
    {
364
        $this->addAction($this->resolveAction(CartSetCustomFieldAction::class, $action));
365
        return $this;
366
    }
367
368
    /**
369
     * @link https://docs.commercetools.com/http-api-projects-carts.html#set-customlineitem-customfield
370
     * @param CartSetCustomLineItemCustomFieldAction|callable $action
371 1
     * @return $this
372
     */
373 1
    public function setCustomLineItemCustomField($action = null)
374 1
    {
375
        $this->addAction($this->resolveAction(CartSetCustomLineItemCustomFieldAction::class, $action));
376
        return $this;
377
    }
378
379
    /**
380
     * @link https://docs.commercetools.com/http-api-projects-carts.html#set-customlineitem-custom-type
381
     * @param CartSetCustomLineItemCustomTypeAction|callable $action
382 1
     * @return $this
383
     */
384 1
    public function setCustomLineItemCustomType($action = null)
385 1
    {
386
        $this->addAction($this->resolveAction(CartSetCustomLineItemCustomTypeAction::class, $action));
387
        return $this;
388
    }
389
390
    /**
391
     * @link https://docs.commercetools.com/http-api-projects-carts.html#set-customlineitemshippingdetails
392
     * @param CartSetCustomLineItemShippingDetailsAction|callable $action
393 1
     * @return $this
394
     */
395 1
    public function setCustomLineItemShippingDetails($action = null)
396 1
    {
397
        $this->addAction($this->resolveAction(CartSetCustomLineItemShippingDetailsAction::class, $action));
398
        return $this;
399
    }
400
401
    /**
402
     * @link https://docs.commercetools.com/http-api-projects-carts.html#set-customlineitem-taxamount
403
     * @param CartSetCustomLineItemTaxAmountAction|callable $action
404 1
     * @return $this
405
     */
406 1
    public function setCustomLineItemTaxAmount($action = null)
407 1
    {
408
        $this->addAction($this->resolveAction(CartSetCustomLineItemTaxAmountAction::class, $action));
409
        return $this;
410
    }
411
412
    /**
413
     * @link https://docs.commercetools.com/http-api-projects-carts.html#set-customlineitem-taxrate
414
     * @param CartSetCustomLineItemTaxRateAction|callable $action
415 1
     * @return $this
416
     */
417 1
    public function setCustomLineItemTaxRate($action = null)
418 1
    {
419
        $this->addAction($this->resolveAction(CartSetCustomLineItemTaxRateAction::class, $action));
420
        return $this;
421
    }
422
423
    /**
424
     * @link https://docs.commercetools.com/http-api-projects-carts.html#set-custom-shippingmethod
425
     * @param CartSetCustomShippingMethodAction|callable $action
426 1
     * @return $this
427
     */
428 1
    public function setCustomShippingMethod($action = null)
429 1
    {
430
        $this->addAction($this->resolveAction(CartSetCustomShippingMethodAction::class, $action));
431
        return $this;
432
    }
433
434
    /**
435
     *
436
     * @param CartSetCustomTypeAction|callable $action
437 1
     * @return $this
438
     */
439 1
    public function setCustomType($action = null)
440 1
    {
441
        $this->addAction($this->resolveAction(CartSetCustomTypeAction::class, $action));
442
        return $this;
443
    }
444
445
    /**
446
     * @link https://docs.commercetools.com/http-api-projects-carts.html#set-customer-email
447
     * @param CartSetCustomerEmailAction|callable $action
448 1
     * @return $this
449
     */
450 1
    public function setCustomerEmail($action = null)
451 1
    {
452
        $this->addAction($this->resolveAction(CartSetCustomerEmailAction::class, $action));
453
        return $this;
454
    }
455
456
    /**
457
     * @link https://docs.commercetools.com/http-api-projects-carts.html#set-customer-group
458
     * @param CartSetCustomerGroupAction|callable $action
459 1
     * @return $this
460
     */
461 1
    public function setCustomerGroup($action = null)
462 1
    {
463
        $this->addAction($this->resolveAction(CartSetCustomerGroupAction::class, $action));
464
        return $this;
465
    }
466
467
    /**
468
     * @link https://docs.commercetools.com/http-api-projects-carts.html#set-customer-id
469
     * @param CartSetCustomerIdAction|callable $action
470 1
     * @return $this
471
     */
472 1
    public function setCustomerId($action = null)
473 1
    {
474
        $this->addAction($this->resolveAction(CartSetCustomerIdAction::class, $action));
475
        return $this;
476
    }
477
478
    /**
479
     * @link https://docs.commercetools.com/http-api-projects-carts.html#set-deletedaysafterlastmodification-beta
480
     * @param CartSetDeleteDaysAfterLastModificationAction|callable $action
481 1
     * @return $this
482
     */
483 1
    public function setDeleteDaysAfterLastModification($action = null)
484 1
    {
485
        $this->addAction($this->resolveAction(CartSetDeleteDaysAfterLastModificationAction::class, $action));
486
        return $this;
487
    }
488
489
    /**
490
     *
491
     * @param CartSetItemShippingAddressCustomFieldAction|callable $action
492 1
     * @return $this
493
     */
494 1
    public function setItemShippingAddressCustomField($action = null)
495 1
    {
496
        $this->addAction($this->resolveAction(CartSetItemShippingAddressCustomFieldAction::class, $action));
497
        return $this;
498
    }
499
500
    /**
501
     *
502
     * @param CartSetItemShippingAddressCustomTypeAction|callable $action
503 1
     * @return $this
504
     */
505 1
    public function setItemShippingAddressCustomType($action = null)
506 1
    {
507
        $this->addAction($this->resolveAction(CartSetItemShippingAddressCustomTypeAction::class, $action));
508
        return $this;
509
    }
510
511
    /**
512
     * @link https://docs.commercetools.com/api/projects/carts#set-key-
513
     * @param CartSetKeyAction|callable $action
514 1
     * @return $this
515
     */
516 1
    public function setKey($action = null)
517 1
    {
518
        $this->addAction($this->resolveAction(CartSetKeyAction::class, $action));
519
        return $this;
520
    }
521
522
    /**
523
     * @link https://docs.commercetools.com/http-api-projects-carts.html#set-lineitem-customfield
524
     * @param CartSetLineItemCustomFieldAction|callable $action
525 1
     * @return $this
526
     */
527 1
    public function setLineItemCustomField($action = null)
528 1
    {
529
        $this->addAction($this->resolveAction(CartSetLineItemCustomFieldAction::class, $action));
530
        return $this;
531
    }
532
533
    /**
534
     * @link https://docs.commercetools.com/http-api-projects-carts.html#set-customlineitem-custom-type
535
     * @param CartSetLineItemCustomTypeAction|callable $action
536 1
     * @return $this
537
     */
538 1
    public function setLineItemCustomType($action = null)
539 1
    {
540
        $this->addAction($this->resolveAction(CartSetLineItemCustomTypeAction::class, $action));
541
        return $this;
542
    }
543
544
    /**
545
     *
546
     * @param CartSetLineItemDistributionChannelAction|callable $action
547 1
     * @return $this
548
     */
549 1
    public function setLineItemDistributionChannel($action = null)
550 1
    {
551
        $this->addAction($this->resolveAction(CartSetLineItemDistributionChannelAction::class, $action));
552
        return $this;
553
    }
554
555
    /**
556
     * @link https://docs.commercetools.com/http-api-projects-carts.html#set-lineitem-totalprice
557
     * @param CartSetLineItemPriceAction|callable $action
558 1
     * @return $this
559
     */
560 1
    public function setLineItemPrice($action = null)
561 1
    {
562
        $this->addAction($this->resolveAction(CartSetLineItemPriceAction::class, $action));
563
        return $this;
564
    }
565
566
    /**
567
     * @link https://docs.commercetools.com/http-api-projects-carts.html#set-lineitem-totalprice
568
     * @param CartSetLineItemShippingDetailsAction|callable $action
569 1
     * @return $this
570
     */
571 1
    public function setLineItemShippingDetails($action = null)
572 1
    {
573
        $this->addAction($this->resolveAction(CartSetLineItemShippingDetailsAction::class, $action));
574
        return $this;
575
    }
576
577
    /**
578
     * @link https://docs.commercetools.com/http-api-projects-carts.html#set-lineitem-taxamount
579
     * @param CartSetLineItemTaxAmountAction|callable $action
580 1
     * @return $this
581
     */
582 1
    public function setLineItemTaxAmount($action = null)
583 1
    {
584
        $this->addAction($this->resolveAction(CartSetLineItemTaxAmountAction::class, $action));
585
        return $this;
586
    }
587
588
    /**
589
     * @link https://docs.commercetools.com/http-api-projects-carts.html#set-lineitem-taxrate
590
     * @param CartSetLineItemTaxRateAction|callable $action
591 1
     * @return $this
592
     */
593 1
    public function setLineItemTaxRate($action = null)
594 1
    {
595
        $this->addAction($this->resolveAction(CartSetLineItemTaxRateAction::class, $action));
596
        return $this;
597
    }
598
599
    /**
600
     * @link https://docs.commercetools.com/http-api-projects-carts.html#set-lineitem-totalprice
601
     * @param CartSetLineItemTotalPriceAction|callable $action
602 1
     * @return $this
603
     */
604 1
    public function setLineItemTotalPrice($action = null)
605 1
    {
606
        $this->addAction($this->resolveAction(CartSetLineItemTotalPriceAction::class, $action));
607
        return $this;
608
    }
609
610
    /**
611
     * @link https://docs.commercetools.com/http-api-projects-carts.html#set-locale
612
     * @param CartSetLocaleAction|callable $action
613 1
     * @return $this
614
     */
615 1
    public function setLocale($action = null)
616 1
    {
617
        $this->addAction($this->resolveAction(CartSetLocaleAction::class, $action));
618
        return $this;
619
    }
620
621
    /**
622
     * @link https://docs.commercetools.com/http-api-projects-carts.html#set-shipping-address
623
     * @param CartSetShippingAddressAction|callable $action
624 1
     * @return $this
625
     */
626 1
    public function setShippingAddress($action = null)
627 1
    {
628
        $this->addAction($this->resolveAction(CartSetShippingAddressAction::class, $action));
629
        return $this;
630
    }
631
632
    /**
633
     *
634
     * @param CartSetShippingAddressCustomFieldAction|callable $action
635 1
     * @return $this
636
     */
637 1
    public function setShippingAddressCustomField($action = null)
638 1
    {
639
        $this->addAction($this->resolveAction(CartSetShippingAddressCustomFieldAction::class, $action));
640
        return $this;
641
    }
642
643
    /**
644
     *
645
     * @param CartSetShippingAddressCustomTypeAction|callable $action
646 1
     * @return $this
647
     */
648 1
    public function setShippingAddressCustomType($action = null)
649 1
    {
650
        $this->addAction($this->resolveAction(CartSetShippingAddressCustomTypeAction::class, $action));
651
        return $this;
652
    }
653
654
    /**
655
     * @link https://docs.commercetools.com/http-api-projects-carts.html#set-shippingmethod
656
     * @param CartSetShippingMethodAction|callable $action
657 1
     * @return $this
658
     */
659 1
    public function setShippingMethod($action = null)
660 1
    {
661
        $this->addAction($this->resolveAction(CartSetShippingMethodAction::class, $action));
662
        return $this;
663
    }
664
665
    /**
666
     * @link https://docs.commercetools.com/http-api-projects-carts.html#set-shippingmethod-taxamount
667
     * @param CartSetShippingMethodTaxAmountAction|callable $action
668
     * @return $this
669 1
     */
670
    public function setShippingMethodTaxAmount($action = null)
671 1
    {
672 1
        $this->addAction($this->resolveAction(CartSetShippingMethodTaxAmountAction::class, $action));
673
        return $this;
674
    }
675
676
    /**
677
     * @link https://docs.commercetools.com/http-api-projects-carts.html#set-shippingmethod-taxrate
678
     * @param CartSetShippingMethodTaxRateAction|callable $action
679
     * @return $this
680 1
     */
681
    public function setShippingMethodTaxRate($action = null)
682 1
    {
683 1
        $this->addAction($this->resolveAction(CartSetShippingMethodTaxRateAction::class, $action));
684
        return $this;
685
    }
686
687
    /**
688
     * @link https://dev.commercetools.com/http-api-projects-carts.html#set-shippingrateinput
689
     * @link https://docs.commercetools.com/http-api-projects-carts.html#set-shippingrateinput
690
     * @param CartSetShippingRateInputAction|callable $action
691
     * @return $this
692
     */
693
    public function setShippingRateInput($action = null)
694
    {
695
        $this->addAction($this->resolveAction(CartSetShippingRateInputAction::class, $action));
696
        return $this;
697
    }
698
699
    /**
700 56
     * @link https://docs.commercetools.com/http-api-projects-carts.html#update-itemshippingaddress
701
     * @param CartUpdateItemShippingAddressAction|callable $action
702 56
     * @return $this
703 56
     */
704 56
    public function updateItemShippingAddress($action = null)
705 56
    {
706
        $this->addAction($this->resolveAction(CartUpdateItemShippingAddressAction::class, $action));
707 56
        return $this;
708 56
    }
709
710
    /**
711
     * @return CartsActionBuilder
712
     */
713
    public static function of()
714
    {
715
        return new self();
716
    }
717
718
    /**
719
     * @param $class
720 56
     * @param $action
721
     * @return AbstractAction
722 56
     * @throws InvalidArgumentException
723
     */
724
    private function resolveAction($class, $action = null)
725 56
    {
726
        if (is_null($action) || is_callable($action)) {
727
            $callback = $action;
728
            $emptyAction = $class::of();
729
            $action = $this->callback($emptyAction, $callback);
730
        }
731
        if ($action instanceof $class) {
732 56
            return $action;
733
        }
734 56
        throw new InvalidArgumentException(
735 56
            sprintf('Expected method to be called with or callable to return %s', $class)
736
        );
737
    }
738
739
    /**
740
     * @param $action
741 56
     * @param callable $callback
742
     * @return AbstractAction
743 56
     */
744
    private function callback($action, callable $callback = null)
745
    {
746
        if (!is_null($callback)) {
747
            $action = $callback($action);
748
        }
749
        return $action;
750
    }
751
752
    /**
753
     * @param AbstractAction $action
754
     * @return $this;
755
     */
756
    public function addAction(AbstractAction $action)
757
    {
758
        $this->actions[] = $action;
759
        return $this;
760
    }
761
762
    /**
763
     * @return array
764
     */
765
    public function getActions()
766
    {
767
        return $this->actions;
768
    }
769
770
771
    /**
772
     * @param array $actions
773
     * @return $this
774
     */
775
    public function setActions(array $actions)
776
    {
777
        $this->actions = $actions;
778
        return $this;
779
    }
780
}
781