MoneyHydrator   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Test Coverage

Coverage 42.86%

Importance

Changes 2
Bugs 0 Features 1
Metric Value
wmc 2
eloc 6
c 2
b 0
f 1
dl 0
loc 18
ccs 3
cts 7
cp 0.4286
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A hydrate() 0 5 1
A extract() 0 5 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 [
38
            'currency'  => $object->getCurrency()->getCode(),
39
            'amount'    => $object->getAmount(),
40
        ];
41
    }
42
}
43