CustomerHydrator   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Test Coverage

Coverage 50%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
eloc 8
c 1
b 0
f 0
dl 0
loc 25
ccs 4
cts 8
cp 0.5
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A extract() 0 6 2
A hydrate() 0 7 2
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);
0 ignored issues
show
Bug introduced by
hiqdev\php\billing\customer\Customer::class of type string is incompatible with the type object expected by parameter $object of Zend\Hydrator\HydrationInterface::hydrate(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

30
            $data['seller'] = $this->hydrator->hydrate($data['seller'], /** @scrutinizer ignore-type */ Customer::class);
Loading history...
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
        return [
43
            'id'            => $object->getId(),
44
            'login'         => $object->getLogin(),
45
            'seller'        => $object->getSeller() ? $this->hydrator->extract($object->getSeller()) : null,
46
        ];
47
    }
48
}
49