Completed
Push — master ( 44676f...b7bc18 )
by Jens
13:18
created

LineItemDraft   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 82.35%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 1
dl 0
loc 40
ccs 14
cts 17
cp 0.8235
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A fieldDefinitions() 0 15 1
A ofProductId() 0 5 1
A ofSku() 0 5 1
1
<?php
2
/**
3
 * @author @jayS-de <[email protected]>
4
 */
5
6
namespace Commercetools\Core\Model\Cart;
7
8
use Commercetools\Core\Model\Channel\ChannelReference;
9
use Commercetools\Core\Model\Common\Context;
10
use Commercetools\Core\Model\Common\JsonObject;
11
use Commercetools\Core\Model\Common\LocalizedString;
12
use Commercetools\Core\Model\Common\Money;
13
use Commercetools\Core\Model\Common\Price;
14
use Commercetools\Core\Model\Order\ItemState;
15
use Commercetools\Core\Model\Order\ItemStateCollection;
16
use Commercetools\Core\Model\Product\ProductVariant;
17
use Commercetools\Core\Model\TaxCategory\TaxRate;
18
use Commercetools\Core\Model\CustomField\CustomFieldObject;
19
use Commercetools\Core\Model\TaxCategory\ExternalTaxRateDraft;
20
21
/**
22
 * @package Commercetools\Core\Model\Cart
23
 * @link https://dev.commercetools.com/http-api-projects-carts.html#lineitemdraft
24
 * @method string getProductId()
25
 * @method LineItemDraft setProductId(string $productId = null)
26
 * @method int getVariantId()
27
 * @method LineItemDraft setVariantId(int $variantId = null)
28
 * @method int getQuantity()
29
 * @method LineItemDraft setQuantity(int $quantity = null)
30
 * @method ChannelReference getSupplyChannel()
31
 * @method LineItemDraft setSupplyChannel(ChannelReference $supplyChannel = null)
32
 * @method ChannelReference getDistributionChannel()
33
 * @method LineItemDraft setDistributionChannel(ChannelReference $distributionChannel = null)
34
 * @method CustomFieldObject getCustom()
35
 * @method LineItemDraft setCustom(CustomFieldObject $custom = null)
36
 * @method ExternalTaxRateDraft getExternalTaxRate()
37
 * @method LineItemDraft setExternalTaxRate(ExternalTaxRateDraft $externalTaxRate = null)
38
 * @method Money getExternalPrice()
39
 * @method LineItemDraft setExternalPrice(Money $externalPrice = null)
40
 * @method ExternalLineItemTotalPrice getExternalTotalPrice()
41
 * @method LineItemDraft setExternalTotalPrice(ExternalLineItemTotalPrice $externalTotalPrice = null)
42
 * @method string getSku()
43
 * @method LineItemDraft setSku(string $sku = null)
44
 */
45
class LineItemDraft extends JsonObject
46
{
47 36
    public function fieldDefinitions()
48
    {
49
        return [
50 36
            'productId' => [static::TYPE => 'string'],
51 36
            'variantId' => [static::TYPE => 'int'],
52 36
            'quantity' => [static::TYPE => 'int'],
53 36
            'supplyChannel' => [static::TYPE => ChannelReference::class],
54 36
            'distributionChannel' => [static::TYPE => ChannelReference::class],
55 36
            'externalTaxRate' => [static::TYPE => ExternalTaxRateDraft::class],
56 36
            'externalPrice' => [static::TYPE => Money::class],
57 36
            'externalTotalPrice' => [static::TYPE => ExternalLineItemTotalPrice::class],
58 36
            'custom' => [static::TYPE => CustomFieldObject::class],
59 36
            'sku' => [static::TYPE => 'string'],
60
        ];
61
    }
62
63
    /**
64
     * @param string $productId
65
     * @param Context|callable $context
66
     * @return LineItemDraft
67
     */
68
    public static function ofProductId($productId, $context = null)
69
    {
70
        $draft = static::of($context);
71
        return $draft->setProductId($productId);
72
    }
73
74
    /**
75
     * @param string $sku
76
     * @param Context|callable $context
77
     * @return LineItemDraft
78
     */
79 3
    public static function ofSku($sku, $context = null)
80
    {
81 3
        $draft = static::of($context);
82 3
        return $draft->setSku($sku);
83
    }
84
}
85