Completed
Push — develop ( e4c10e...940e90 )
by Jens
08:29
created

CartAddCustomLineItemAction   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 67
Duplicated Lines 19.4 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
c 1
b 0
f 0
lcom 1
cbo 1
dl 13
loc 67
ccs 27
cts 27
cp 1
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A fieldDefinitions() 13 13 1
A __construct() 0 5 1
A ofNameQuantityMoneySlugAndTaxCategory() 0 15 1
A ofNameQuantityMoneySlugAndExternalTaxRate() 0 15 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
/**
3
 * @author @jayS-de <[email protected]>
4
 */
5
6
namespace Commercetools\Core\Request\Carts\Command;
7
8
use Commercetools\Core\Model\Common\Context;
9
use Commercetools\Core\Model\Common\LocalizedString;
10
use Commercetools\Core\Model\Common\Money;
11
use Commercetools\Core\Model\TaxCategory\TaxCategory;
12
use Commercetools\Core\Request\AbstractAction;
13
use Commercetools\Core\Model\TaxCategory\TaxCategoryReference;
14
use Commercetools\Core\Model\CustomField\CustomFieldObjectDraft;
15
use Commercetools\Core\Model\TaxCategory\ExternalTaxRateDraft;
16
17
/**
18
 * @package Commercetools\Core\Request\Carts\Command
19
 * @link https://dev.commercetools.com/http-api-projects-carts.html#add-custom-line-item
20
 * @method string getAction()
21
 * @method CartAddCustomLineItemAction setAction(string $action = null)
22
 * @method LocalizedString getName()
23
 * @method CartAddCustomLineItemAction setName(LocalizedString $name = null)
24
 * @method int getQuantity()
25
 * @method CartAddCustomLineItemAction setQuantity(int $quantity = null)
26
 * @method Money getMoney()
27
 * @method CartAddCustomLineItemAction setMoney(Money $money = null)
28
 * @method string getSlug()
29
 * @method CartAddCustomLineItemAction setSlug(string $slug = null)
30
 * @method TaxCategoryReference getTaxCategory()
31
 * @method CartAddCustomLineItemAction setTaxCategory(TaxCategoryReference $taxCategory = null)
32
 * @method CustomFieldObjectDraft getCustom()
33
 * @method CartAddCustomLineItemAction setCustom(CustomFieldObjectDraft $custom = null)
34
 * @method ExternalTaxRateDraft getExternalTaxRate()
35
 * @method CartAddCustomLineItemAction setExternalTaxRate(ExternalTaxRateDraft $externalTaxRate = null)
36
 */
37
class CartAddCustomLineItemAction extends AbstractAction
38
{
39 11 View Code Duplication
    public function fieldDefinitions()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
40
    {
41
        return [
42 11
            'action' => [static::TYPE => 'string'],
43 11
            'name' => [static::TYPE => '\Commercetools\Core\Model\Common\LocalizedString'],
44 11
            'quantity' => [static::TYPE => 'int'],
45 11
            'money' => [static::TYPE => '\Commercetools\Core\Model\Common\Money'],
46 11
            'slug' => [static::TYPE => 'string'],
47 11
            'taxCategory' => [static::TYPE => '\Commercetools\Core\Model\TaxCategory\TaxCategoryReference'],
48 11
            'custom' => [static::TYPE => '\Commercetools\Core\Model\CustomField\CustomFieldObjectDraft'],
49 11
            'externalTaxRate' => [static::TYPE => '\Commercetools\Core\Model\TaxCategory\ExternalTaxRateDraft'],
50
        ];
51
    }
52
53
    /**
54
     * @param array $data
55
     * @param Context|callable $context
56
     */
57 9
    public function __construct(array $data = [], $context = null)
58
    {
59 9
        parent::__construct($data, $context);
60 9
        $this->setAction('addCustomLineItem');
61 9
    }
62
63
    /**
64
     * @param LocalizedString $name
65
     * @param int $quantity
66
     * @param Money $money
67
     * @param string $slug
68
     * @param TaxCategoryReference $taxCategory
69
     * @param Context|callable $context
70
     * @return CartAddCustomLineItemAction
71
     */
72 4
    public static function ofNameQuantityMoneySlugAndTaxCategory(
73
        LocalizedString $name,
74
        $quantity,
75
        Money $money,
76
        $slug,
77
        TaxCategoryReference $taxCategory,
78
        $context = null
79
    ) {
80 4
        return static::of($context)
81 4
            ->setName($name)
82 4
            ->setQuantity($quantity)
83 4
            ->setMoney($money)
84 4
            ->setSlug($slug)
85 4
            ->setTaxCategory($taxCategory);
86
    }
87
88 5
    public static function ofNameQuantityMoneySlugAndExternalTaxRate(
89
        LocalizedString $name,
90
        $quantity,
91
        Money $money,
92
        $slug,
93
        ExternalTaxRateDraft $externalTaxRate,
94
        $context = null
95
    ) {
96 5
        return static::of($context)
97 5
            ->setName($name)
98 5
            ->setQuantity($quantity)
99 5
            ->setMoney($money)
100 5
            ->setSlug($slug)
101 5
            ->setExternalTaxRate($externalTaxRate);
102
    }
103
}
104