Completed
Branch master (9c37c7)
by Jens
07:29
created

PriceDraft::ofMoney()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1
Metric Value
dl 0
loc 5
ccs 3
cts 3
cp 1
rs 9.4285
cc 1
eloc 3
nc 1
nop 2
crap 1
1
<?php
2
/**
3
 * @author @jayS-de <[email protected]>
4
 */
5
6
namespace Commercetools\Core\Model\Common;
7
8
use Commercetools\Core\Model\CustomerGroup\CustomerGroupReference;
9
use Commercetools\Core\Model\Channel\ChannelReference;
10
use Commercetools\Core\Model\CustomField\CustomFieldObject;
11
12
/**
13
 * @package Commercetools\Core\Model\Common
14
 * @link https://dev.commercetools.com/http-api-projects-products.html#new-product-price
15
 * @method Money getValue()
16
 * @method PriceDraft setValue(Money $value = null)
17
 * @method string getCountry()
18
 * @method PriceDraft setCountry(string $country = null)
19
 * @method CustomerGroupReference getCustomerGroup()
20
 * @method PriceDraft setCustomerGroup(CustomerGroupReference $customerGroup = null)
21
 * @method ChannelReference getChannel()
22
 * @method PriceDraft setChannel(ChannelReference $channel = null)
23
 * @method DateTimeDecorator getValidFrom()
24
 * @method PriceDraft setValidFrom(\DateTime $validFrom = null)
25
 * @method DateTimeDecorator getValidUntil()
26
 * @method PriceDraft setValidUntil(\DateTime $validUntil = null)
27
 * @method CustomFieldObject getCustom()
28
 * @method PriceDraft setCustom(CustomFieldObject $custom = null)
29
 */
30
class PriceDraft extends JsonObject
31
{
32
    const VALUE = 'value';
33
    const COUNTRY = 'country';
34
    const CUSTOMER_GROUP = 'customerGroup';
35
    const CHANNEL = 'channel';
36
    const VALID_FROM = 'validFrom';
37
    const VALID_UNTIL = 'validUntil';
38
    const DISCOUNTED = 'discounted';
39
    const CUSTOM = 'custom';
40
41 32
    public function fieldDefinitions()
42
    {
43
        return [
44 32
            static::VALUE => [self::TYPE => '\Commercetools\Core\Model\Common\Money'],
45 32
            static::COUNTRY => [self::TYPE => 'string'],
46 32
            static::CUSTOMER_GROUP => [self::TYPE => '\Commercetools\Core\Model\CustomerGroup\CustomerGroupReference'],
47 32
            static::CHANNEL => [self::TYPE => '\Commercetools\Core\Model\Channel\ChannelReference'],
48 32
            static::VALID_FROM => [
49 32
                self::TYPE => '\DateTime',
50 32
                self::DECORATOR => '\Commercetools\Core\Model\Common\DateTimeDecorator'
51
            ],
52 32
            static::VALID_UNTIL => [
53 32
                self::TYPE => '\DateTime',
54 32
                self::DECORATOR => '\Commercetools\Core\Model\Common\DateTimeDecorator'
55
            ],
56 32
            static::CUSTOM => [static::TYPE => '\Commercetools\Core\Model\CustomField\CustomFieldObject'],
57
        ];
58
    }
59
60
    /**
61
     * @param Money $money
62
     * @param Context|callable $context
63
     * @return PriceDraft
64
     */
65 32
    public static function ofMoney(Money $money, $context = null)
66
    {
67 32
        $price = static::of($context);
68 32
        return $price->setValue($money);
69
    }
70
71
    /**
72
     * @return string
73
     */
74
    public function __toString()
75
    {
76
        return $this->getValue()->__toString();
77
    }
78
}
79