CustomerHydrator::hydrate()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 3
c 1
b 0
f 0
dl 0
loc 7
ccs 4
cts 4
cp 1
rs 10
cc 2
nc 2
nop 2
crap 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