Passed
Push — develop ( c3a5bd...0fb661 )
by Jens
17:20
created

ScopedPrice::fieldDefinitions()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 21
Code Lines 16

Duplication

Lines 21
Ratio 100 %

Code Coverage

Tests 15
CRAP Score 1

Importance

Changes 0
Metric Value
dl 21
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 @jenschude <[email protected]>
4
 * @created: 04.02.15, 16:43
5
 */
6
7
namespace Commercetools\Core\Model\Common;
8
9
use Commercetools\Core\Model\Channel\ChannelReference;
10
use Commercetools\Core\Model\CustomerGroup\CustomerGroupReference;
11
use Commercetools\Core\Model\CustomField\CustomFieldObject;
12
use DateTime;
13
14
/**
15
 * @package Commercetools\Core\Model\Common
16
 * @link https://docs.commercetools.com/http-api-projects-products.html#scopedprice
17
 * @method Money getValue()
18
 * @method string getCountry()
19
 * @method CustomerGroupReference getCustomerGroup()
20
 * @method ChannelReference getChannel()
21
 * @method DiscountedPrice getDiscounted()
22
 * @method ScopedPrice setValue(Money $value = null)
23
 * @method ScopedPrice setCountry(string $country = null)
24
 * @method ScopedPrice setCustomerGroup(CustomerGroupReference $customerGroup = null)
25
 * @method ScopedPrice setChannel(ChannelReference $channel = null)
26
 * @method ScopedPrice setDiscounted(DiscountedPrice $discounted = null)
27
 * @method string getId()
28
 * @method ScopedPrice setId(string $id = null)
29
 * @method DateTimeDecorator getValidFrom()
30
 * @method ScopedPrice setValidFrom(DateTime $validFrom = null)
31
 * @method DateTimeDecorator getValidUntil()
32
 * @method ScopedPrice setValidUntil(DateTime $validUntil = null)
33
 * @method CustomFieldObject getCustom()
34
 * @method ScopedPrice setCustom(CustomFieldObject $custom = null)
35
 * @method Money getCurrentValue()
36
 * @method ScopedPrice setCurrentValue(Money $currentValue = null)
37
 */
38
class ScopedPrice extends JsonObject
39
{
40
    const ID = 'id';
41
    const VALUE = 'value';
42
    const CURRENT_VALUE = 'currentValue';
43
    const COUNTRY = 'country';
44
    const CUSTOMER_GROUP = 'customerGroup';
45
    const CHANNEL = 'channel';
46
    const VALID_FROM = 'validFrom';
47
    const VALID_UNTIL = 'validUntil';
48
    const DISCOUNTED = 'discounted';
49
    const CUSTOM = 'custom';
50
51 1 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...
52
    {
53
        return [
54 1
            static::ID => [static::TYPE => 'string'],
55 1
            static::VALUE => [self::TYPE => Money::class],
56 1
            static::CURRENT_VALUE => [static::TYPE => Money::class],
57 1
            static::COUNTRY => [self::TYPE => 'string'],
58 1
            static::CUSTOMER_GROUP => [self::TYPE => CustomerGroupReference::class],
59 1
            static::CHANNEL => [self::TYPE => ChannelReference::class],
60 1
            static::VALID_FROM => [
61 1
                self::TYPE => DateTime::class,
62 1
                self::DECORATOR => DateTimeDecorator::class
63
            ],
64 1
            static::VALID_UNTIL => [
65 1
                self::TYPE => DateTime::class,
66 1
                self::DECORATOR => DateTimeDecorator::class
67
            ],
68 1
            static::DISCOUNTED => [self::TYPE => DiscountedPrice::class],
69 1
            static::CUSTOM => [static::TYPE => CustomFieldObject::class],
70
        ];
71
    }
72
73
    /**
74
     * @param Money $money
75
     * @param Context|callable $context
76
     * @return ScopedPrice
77
     */
78
    public static function ofMoney(Money $money, $context = null)
79
    {
80
        $price = static::of($context);
81
        return $price->setValue($money);
82
    }
83
84
    public function __toString()
85
    {
86
        return $this->getCurrentValue()->__toString();
87
    }
88
}
89