QuantityHydrator   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 16
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 2
Bugs 0 Features 1
Metric Value
wmc 2
eloc 5
c 2
b 0
f 1
dl 0
loc 16
ccs 0
cts 9
cp 0
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A extract() 0 5 1
A hydrate() 0 3 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\php\units\Quantity;
14
use hiqdev\yii\DataMapper\hydrator\GeneratedHydrator;
15
16
/**
17
 * Quantity Hydrator.
18
 *
19
 * @author Andrii Vasyliev <[email protected]>
20
 */
21
class QuantityHydrator extends GeneratedHydrator
22
{
23
    public function hydrate(array $data, $object)
24
    {
25
        return Quantity::create($data['unit'], $data['quantity']);
26
    }
27
28
    /**
29
     * {@inheritdoc}
30
     * @param object|Quantity $object
31
     */
32
    public function extract($object)
33
    {
34
        return [
35
            'unit'      => $object->getUnit()->getName(),
36
            'quantity'  => $object->getQuantity(),
37
        ];
38
    }
39
}
40