Completed
Push — master ( d098fa...a2fd0b )
by Andrii
06:55
created

CustomerHydrator   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 40%

Importance

Changes 0
Metric Value
wmc 3
c 0
b 0
f 0
lcom 0
cbo 0
dl 0
loc 30
ccs 4
cts 10
cp 0.4
rs 10

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-2018, 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\GeneratedHydrator;
15
16
/**
17
 * Class CustomerHydrator.
18
 *
19
 * @author Andrii Vasyliev <[email protected]>
20
 */
21
class CustomerHydrator extends GeneratedHydrator
22
{
23
    /**
24
     * {@inheritdoc}
25
     * @param object|Customer $object
26
     */
27 2
    public function hydrate(array $data, $object)
28
    {
29 2
        if (!empty($data['seller'])) {
30 2
            $data['seller'] = $this->hydrator->hydrate($data['seller'], Customer::class);
31
        }
32
33 2
        return parent::hydrate($data, $object);
34
    }
35
36
    /**
37
     * {@inheritdoc}
38
     * @param object|Customer $object
39
     */
40
    public function extract($object)
41
    {
42
        $result = array_filter([
43
            'id'            => $object->getId(),
44
            'login'         => $object->getLogin(),
45
            'seller_id'     => $object->seller->getid(),
46
        ]);
47
48
        return $result;
49
    }
50
}
51