Passed
Push — develop ( c4e85b...c7e5d1 )
by Jens
09:06
created

CentPrecisionMoney::fieldDefinitions()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 5
dl 0
loc 7
ccs 5
cts 5
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 1
1
<?php
2
/**
3
 */
4
5
namespace Commercetools\Core\Model\Common;
6
7
/**
8
 * @package Commercetools\Core\Model\Common
9
 *
10
 * @method string getCurrencyCode()
11
 * @method CentPrecisionMoney setCurrencyCode(string $currencyCode = null)
12
 * @method int getCentAmount()
13
 * @method CentPrecisionMoney setCentAmount(int $centAmount = null)
14
 * @method string getType()
15
 * @method CentPrecisionMoney setType(string $type = null)
16
 * @method string getFractionDigits()
17
 * @method CentPrecisionMoney setFractionDigits(string $fractionDigits = null)
18
 */
19
class CentPrecisionMoney extends Money
20
{
21
    /**
22
     * @inheritDoc
23
     */
24 42
    public function __construct(array $data = [], $context = null)
25
    {
26 42
        $data[static::TYPE] = static::TYPE_CENT_PRECISION;
27 42
        parent::__construct($data, $context);
28 42
    }
29
30 41
    public function fieldDefinitions()
31
    {
32
        return [
33 41
            static::CURRENCY_CODE => [self::TYPE => 'string'],
34 41
            static::CENT_AMOUNT => [self::TYPE => 'int'],
35 41
            static::TYPE => [self::TYPE => 'string'],
36 41
            static::FRACTION_DIGITS => [self::TYPE => 'string']
37
        ];
38
    }
39
40
    /**
41
     * @param $currencyCode
42
     * @param $centAmount
43
     * @param Context|callable $context
44
     * @return Money
45
     */
46
    public static function ofCurrencyAndAmount($currencyCode, $centAmount, $context = null)
47
    {
48
        $money = static::of($context);
49
        return $money->setCurrencyCode($currencyCode)
50
            ->setCentAmount($centAmount);
51
    }
52
}
53