Completed
Push — develop ( c1c65f...ad5811 )
by Jens
08:43
created

CartDiscountDraft::fieldDefinitions()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 21
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 15
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 21
ccs 15
cts 15
cp 1
rs 9.3142
c 0
b 0
f 0
cc 1
eloc 16
nc 1
nop 0
crap 1
1
<?php
2
/**
3
 * @author @jayS-de <[email protected]>
4
 */
5
6
namespace Commercetools\Core\Model\CartDiscount;
7
8
use Commercetools\Core\Model\Common\Context;
9
use Commercetools\Core\Model\Common\JsonObject;
10
use Commercetools\Core\Model\Common\LocalizedString;
11
use Commercetools\Core\Model\Common\DateTimeDecorator;
12
use DateTime;
13
14
/**
15
 * @package Commercetools\Core\Model\CartDiscount
16
 * @link https://dev.commercetools.com/http-api-projects-cartDiscounts.html#cartdiscount
17
 * @method LocalizedString getName()
18
 * @method CartDiscountDraft setName(LocalizedString $name = null)
19
 * @method LocalizedString getDescription()
20
 * @method CartDiscountDraft setDescription(LocalizedString $description = null)
21
 * @method CartDiscountValue getValue()
22
 * @method CartDiscountDraft setValue(CartDiscountValue $value = null)
23
 * @method string getCartPredicate()
24
 * @method CartDiscountDraft setCartPredicate(string $cartPredicate = null)
25
 * @method CartDiscountTarget getTarget()
26
 * @method CartDiscountDraft setTarget(CartDiscountTarget $target = null)
27
 * @method string getSortOrder()
28
 * @method CartDiscountDraft setSortOrder(string $sortOrder = null)
29
 * @method bool getIsActive()
30
 * @method CartDiscountDraft setIsActive(bool $isActive = null)
31
 * @method DateTimeDecorator getValidFrom()
32
 * @method CartDiscountDraft setValidFrom(DateTime $validFrom = null)
33
 * @method DateTimeDecorator getValidUntil()
34
 * @method CartDiscountDraft setValidUntil(DateTime $validUntil = null)
35
 * @method bool getRequiresDiscountCode()
36
 * @method CartDiscountDraft setRequiresDiscountCode(bool $requiresDiscountCode = null)
37
 */
38
class CartDiscountDraft extends JsonObject
39
{
40
    const NAME = 'name';
41
    const DESCRIPTION = 'description';
42
    const VALUE = 'value';
43
    const CART_PREDICATE = 'cartPredicate';
44
    const TARGET = 'target';
45
    const SORT_ORDER = 'sortOrder';
46
    const IS_ACTIVE = 'isActive';
47
    const VALID_FROM = 'validFrom';
48
    const VALID_UNTIL = 'validUntil';
49
    const REQUIRES_DISCOUNT_CODE = 'requiresDiscountCode';
50
51 27
    public function fieldDefinitions()
52
    {
53
        return [
54 27
            static::NAME => [static::TYPE => LocalizedString::class],
55 27
            static::DESCRIPTION => [static::TYPE => LocalizedString::class],
56 27
            static::VALUE => [static::TYPE => CartDiscountValue::class],
57 27
            static::CART_PREDICATE => [static::TYPE => 'string'],
58 27
            static::TARGET => [static::TYPE => CartDiscountTarget::class],
59 27
            static::SORT_ORDER => [static::TYPE => 'string'],
60 27
            static::IS_ACTIVE => [static::TYPE => 'bool'],
61 27
            static::VALID_FROM => [
62 27
                static::TYPE => DateTime::class,
63 27
                static::DECORATOR => DateTimeDecorator::class
64
            ],
65 27
            static::VALID_UNTIL  => [
66 27
                static::TYPE => DateTime::class,
67 27
                static::DECORATOR => DateTimeDecorator::class
68
            ],
69 27
            static::REQUIRES_DISCOUNT_CODE => [static::TYPE => 'bool'],
70
        ];
71
    }
72
73
    /**
74
     * @param LocalizedString $name
75
     * @param CartDiscountValue $value
76
     * @param string $cartPredicate
77
     * @param CartDiscountTarget $target
78
     * @param string $sortOrder
79
     * @param bool $isActive
80
     * @param bool $requiresDiscountCode
81
     * @param Context|callable $context
82
     * @return CartDiscountDraft
83
     */
84 26 View Code Duplication
    public static function ofNameValuePredicateTargetOrderActiveAndDiscountCode(
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...
85
        LocalizedString $name,
86
        CartDiscountValue $value,
87
        $cartPredicate,
88
        CartDiscountTarget $target,
89
        $sortOrder,
90
        $isActive,
91
        $requiresDiscountCode,
92
        $context = null
93
    ) {
94 26
        $draft = static::of($context);
95 26
        return $draft->setName($name)
96 26
            ->setValue($value)
97 26
            ->setCartPredicate($cartPredicate)
98 26
            ->setTarget($target)
99 26
            ->setSortOrder($sortOrder)
100 26
            ->setIsActive($isActive)
101 26
            ->setRequiresDiscountCode($requiresDiscountCode);
102
    }
103
104
    /**
105
     * @param LocalizedString $name
106
     * @param CartDiscountValue $value
107
     * @param string $cartPredicate
108
     * @param string $sortOrder
109
     * @param bool $isActive
110
     * @param bool $requiresDiscountCode
111
     * @param Context|callable $context
112
     * @return CartDiscountDraft
113
     */
114 1 View Code Duplication
    public static function ofNameValuePredicateOrderActiveAndDiscountCode(
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...
115
        LocalizedString $name,
116
        CartDiscountValue $value,
117
        $cartPredicate,
118
        $sortOrder,
119
        $isActive,
120
        $requiresDiscountCode,
121
        $context = null
122
    ) {
123 1
        $draft = static::of($context);
124 1
        return $draft->setName($name)
125 1
            ->setValue($value)
126 1
            ->setCartPredicate($cartPredicate)
127 1
            ->setSortOrder($sortOrder)
128 1
            ->setIsActive($isActive)
129 1
            ->setRequiresDiscountCode($requiresDiscountCode);
130
    }
131
}
132