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

CartDiscountValue   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 88.89%

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 1
dl 0
loc 28
ccs 8
cts 9
cp 0.8889
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A fromArray() 0 10 3
A getClassByType() 0 5 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\DiscountValue;
10
use Commercetools\Core\Model\Common\MoneyCollection;
11
12
/**
13
 * @package Commercetools\Core\Model\CartDiscount
14
 * @link https://dev.commercetools.com/http-api-projects-cartDiscounts.html#cartdiscountvalue
15
 * @deprecated use RelativeCartDiscountValue, AbsoluteCartDiscountValue or GiftLineItemCartDiscountValue instead.
16
 * @method string getType()
17
 * @method CartDiscountValue setType(string $type = null)
18
 * @method int getPermyriad()
19
 * @method CartDiscountValue setPermyriad(int $permyriad = null)
20
 * @method MoneyCollection getMoney()
21
 * @method CartDiscountValue setMoney(MoneyCollection $money = null)
22
 */
23
class CartDiscountValue extends DiscountValue
24
{
25
    const TYPE_RELATIVE = 'relative';
26
    const TYPE_ABSOLUTE = 'absolute';
27
    const TYPE_GIFT_LINE_ITEM = 'giftLineItem';
28
29
    /**
30
     * @param array $data
31
     * @param Context|callable $context
32
     * @return static
33
     */
34 2
    public static function fromArray(array $data, $context = null)
35
    {
36 2
        if (isset($data['type'])) {
37 2
            $className = static::getClassByType($data['type']);
38 2
            if (class_exists($className)) {
39 2
                return new $className($data, $context);
40
            }
41
        }
42
        return new static($data, $context);
0 ignored issues
show
Deprecated Code introduced by
The class Commercetools\Core\Model...count\CartDiscountValue has been deprecated with message: use RelativeCartDiscountValue, AbsoluteCartDiscountValue or GiftLineItemCartDiscountValue instead.

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
43
    }
44
45 2
    protected static function getClassByType($type)
46
    {
47 2
        $className = '\Commercetools\Core\Model\CartDiscount\\' . ucfirst($type) . 'CartDiscountValue';
48 2
        return $className;
49
    }
50
}
51