Completed
Push — master ( 9c7fd0...afc45c )
by Andrii
10:58
created

CustomerHydrator   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 3
dl 0
loc 35
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A hydrate() 0 8 2
A extract() 0 10 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, HiQDev (http://hiqdev.com/)
9
 */
10
11
namespace hiqdev\billing\hiapi\customer;
12
13
use hiqdev\php\billing\customer\Customer;
14
use hiqdev\yii\DataMapper\hydrator\GeneratedHydratorTrait;
15
use hiqdev\yii\DataMapper\hydrator\RootHydratorAwareTrait;
16
use Zend\Hydrator\HydratorInterface;
17
18
/**
19
 * Class CustomerHydrator.
20
 *
21
 * @author Andrii Vasyliev <[email protected]>
22
 */
23
class CustomerHydrator implements HydratorInterface
24
{
25
    use RootHydratorAwareTrait;
26
    use GeneratedHydratorTrait {
27
        hydrate as generatedHydrate;
28
    }
29
30
    /**
31
     * {@inheritdoc}
32
     * @param object|Customer $object
33
     */
34
    public function hydrate(array $data, $object)
35
    {
36
        if (!empty($data['seller'])) {
37
            $data['seller'] = $this->hydrator->hydrate($data['seller'], Customer::class);
38
        }
39
40
        return $this->generatedHydrate($data, $object);
41
    }
42
43
    /**
44
     * {@inheritdoc}
45
     * @param object|Customer $object
46
     */
47
    public function extract($object)
48
    {
49
        $result = array_filter([
50
            'id'            => $object->getId(),
51
            'login'         => $object->getLogin(),
52
            'seller_id'     => $object->seller->getid(),
53
        ]);
54
55
        return $result;
56
    }
57
}
58