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

MoneyHydrator   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 42.86%

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 2
dl 0
loc 21
ccs 3
cts 7
cp 0.4286
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A hydrate() 0 6 1
A extract() 0 7 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