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

RelativeCartDiscountValue::fieldDefinitions()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 8
Ratio 100 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 8
loc 8
ccs 0
cts 8
cp 0
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 5
nc 1
nop 0
crap 2
1
<?php
2
/**
3
 * @author @jayS-de <[email protected]>
4
 */
5
6
namespace Commercetools\Core\Model\CartDiscount;
7
8
use Commercetools\Core\Model\Common\MoneyCollection;
9
10
/**
11
 * @package Commercetools\Core\Model\CartDiscount
12
 * @method string getType()
13
 * @method RelativeCartDiscountValue setType(string $type = null)
14
 * @method int getPermyriad()
15
 * @method RelativeCartDiscountValue setPermyriad(int $permyriad = null)
16
 */
17 View Code Duplication
class RelativeCartDiscountValue extends CartDiscountValue
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...
Duplication introduced by
This class 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...
18
{
19
    /**
20
     * @inheritDoc
21
     */
22
    public function __construct(array $data = [], $context = null)
23
    {
24
        $data['type'] = static::TYPE_RELATIVE;
25
26
        parent::__construct($data, $context);
27
    }
28
29
    public function fieldDefinitions()
30
    {
31
        return [
32
            'type' => [static::TYPE => 'string'],
33
            'permyriad' => [static::TYPE => 'int'],
34
            'money' => [static::TYPE => MoneyCollection::class]
35
        ];
36
    }
37
38
    /**
39
     * @deprecated getMoney will be removed for relative cart discounts with v3.0
40
     * @return MoneyCollection
41
     */
42
    public function getMoney()
43
    {
44
        return parent::getMoney();
45
    }
46
47
    /**
48
     * @deprecated setMoney will be removed for relative cart discounts with v3.0
49
     * @param MoneyCollection|null $money
50
     * @return CartDiscountValue
51
     */
52
    public function setMoney(MoneyCollection $money = null)
53
    {
54
        return parent::setMoney($money);
0 ignored issues
show
Bug introduced by
It seems like $money defined by parameter $money on line 52 can be null; however, Commercetools\Core\Model...scountValue::setMoney() does not accept null, maybe add an additional type check?

It seems like you allow that null is being passed for a parameter, however the function which is called does not seem to accept null.

We recommend to add an additional type check (or disallow null for the parameter):

function notNullable(stdClass $x) { }

// Unsafe
function withoutCheck(stdClass $x = null) {
    notNullable($x);
}

// Safe - Alternative 1: Adding Additional Type-Check
function withCheck(stdClass $x = null) {
    if ($x instanceof stdClass) {
        notNullable($x);
    }
}

// Safe - Alternative 2: Changing Parameter
function withNonNullableParam(stdClass $x) {
    notNullable($x);
}
Loading history...
55
    }
56
}
57