CartsActionBuilder   F
last analyzed

Complexity

Total Complexity 69

Size/Duplication

Total Lines 724
Duplicated Lines 0 %

Test Coverage

Coverage 95.81%

Importance

Changes 0
Metric Value
wmc 69
eloc 137
dl 0
loc 724
ccs 183
cts 191
cp 0.9581
rs 2.88
c 0
b 0
f 0

65 Methods

Rating   Name   Duplication   Size   Complexity  
A changeTaxRoundingMode() 0 4 1
A removeLineItem() 0 4 1
A setCustomerGroup() 0 4 1
A removeItemShippingAddress() 0 4 1
A setShippingMethodTaxAmount() 0 4 1
A setCountry() 0 4 1
A addAction() 0 4 1
A of() 0 3 1
A setLineItemCustomType() 0 4 1
A setCustomLineItemCustomField() 0 4 1
A setDeleteDaysAfterLastModification() 0 4 1
A changeLineItemQuantity() 0 4 1
A changeCustomLineItemMoney() 0 4 1
A setShippingAddressCustomType() 0 4 1
A removePayment() 0 4 1
A setBillingAddressCustomField() 0 4 1
A setCustomShippingMethod() 0 4 1
A setItemShippingAddressCustomType() 0 4 1
A setBillingAddressCustomType() 0 4 1
A setLineItemTotalPrice() 0 4 1
A setCustomLineItemTaxRate() 0 4 1
A removeCustomLineItem() 0 4 1
A setCartTotalTax() 0 4 1
A setShippingAddressCustomField() 0 4 1
A setShippingMethodTaxRate() 0 4 1
A setLineItemDistributionChannel() 0 4 1
A changeTaxMode() 0 4 1
A setCustomLineItemShippingDetails() 0 4 1
A addItemShippingAddress() 0 4 1
A setShippingRateInput() 0 4 1
A applyDeltaToLineItemShippingDetailsTargets() 0 4 1
A setCustomLineItemCustomType() 0 4 1
A setLineItemTaxRate() 0 4 1
A setCustomerEmail() 0 4 1
A changeTaxCalculationMode() 0 4 1
A setActions() 0 4 1
A removeDiscountCode() 0 4 1
A setLineItemSupplyChannel() 0 4 1
A addPayment() 0 4 1
A setCustomType() 0 4 1
A setCustomField() 0 4 1
A setLineItemShippingDetails() 0 4 1
A setLineItemCustomField() 0 4 1
A applyDeltaToCustomLineItemShippingDetailsTargets() 0 5 1
A addLineItem() 0 4 1
A resolveAction() 0 12 4
A getActions() 0 3 1
A callback() 0 6 2
A addDiscountCode() 0 4 1
A setItemShippingAddressCustomField() 0 4 1
A updateItemShippingAddress() 0 4 1
A setShippingAddress() 0 4 1
A recalculate() 0 4 1
A setAnonymousId() 0 4 1
A setKey() 0 4 1
A setLineItemPrice() 0 4 1
A setLineItemTaxAmount() 0 4 1
A setCustomLineItemTaxAmount() 0 4 1
A changeCustomLineItemQuantity() 0 4 1
A setShippingMethod() 0 4 1
A setLocale() 0 4 1
A addCustomLineItem() 0 4 1
A addShoppingList() 0 4 1
A setBillingAddress() 0 4 1
A setCustomerId() 0 4 1

How to fix   Complexity   

Complex Class

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