Completed
Push — master ( cb4835...b23375 )
by Andrii
03:01
created

MoneyHydrator::hydrate()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 3
cts 3
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 2
crap 1
1
<?php
2
/**
3
 * API for Billing
4
 *
5
 * @link      https://github.com/hiqdev/billing-hiapi
6
 * @package   billing-hiapi
7
 * @license   BSD-3-Clause
8
 * @copyright Copyright (c) 2017-2018, HiQDev (http://hiqdev.com/)
9
 */
10
11
namespace hiqdev\billing\hiapi\vo;
12
13
use hiqdev\yii\DataMapper\hydrator\GeneratedHydrator;
14
use Money\Currency;
15
use Money\Money;
16
17
/**
18
 * Class MoneyHydrator.
19
 *
20
 * @author Andrii Vasyliev <[email protected]>
21
 */
22
class MoneyHydrator extends GeneratedHydrator
23
{
24 2
    public function hydrate(array $data, $object)
25
    {
26 2
        $currency = new Currency(strtoupper($data['currency']));
27
28 2
        return new Money($data['amount'], $currency);
29
    }
30
31
    /**
32
     * {@inheritdoc}
33
     * @param object|Money $object
34
     */
35
    public function extract($object)
36
    {
37
        return array_filter([
38
            'currency'  => $object->getCurrency(),
39
            'amount'    => $object->getAmount(),
40
        ]);
41
    }
42
}
43