Completed
Push — master ( c83831...4ba780 )
by Andrii
02:57
created

SaleHydrator::extract()   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 10
Code Lines 7

Duplication

Lines 10
Ratio 100 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 10
loc 10
ccs 0
cts 10
cp 0
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 7
nc 1
nop 1
crap 6
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\sale;
12
13
use DateTimeImmutable;
14
use hiqdev\php\billing\customer\Customer;
15
use hiqdev\php\billing\plan\Plan;
16
use hiqdev\php\billing\target\Target;
17
use hiqdev\yii\DataMapper\hydrator\GeneratedHydrator;
18
19
/**
20
 * Class SaleHydrator.
21
 *
22
 * @author Andrii Vasyliev <[email protected]>
23
 */
24
class SaleHydrator extends GeneratedHydrator
25
{
26
    public function hydrate(array $data, $object)
27
    {
28
        $data['target']     = $this->hydrator->hydrate($data['target'], Target::class);
29
        $data['customer']   = $this->hydrator->hydrate($data['customer'], Customer::class);
30
        $data['plan']       = $this->hydrator->hydrate($data['plan'], Plan::class);
31
        $data['time']       = $this->hydrator->hydrate((array) $data['time'], DateTimeImmutable::class);
32
33
        return parent::hydrate($data, $object);
34
    }
35
36
    /**
37
     * {@inheritdoc}
38
     * @param object|Sale $object
39
     */
40 View Code Duplication
    public function extract($object)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
41
    {
42
        return array_filter([
43
            'id'        => $object->getId(),
44
            'target'    => $this->hydrator->extract($object->getTarget()),
45
            'customer'  => $this->hydrator->extract($object->getCustomer()),
46
            'plan'      => $this->hydrator->extract($object->getPlan()),
47
            'time'      => $object->getTime() ? $this->hydrator->extract($object->getTime()) : null,
48
        ]);
49
    }
50
}
51