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

PlanHydrator::extract()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 7

Duplication

Lines 11
Ratio 100 %

Importance

Changes 0
Metric Value
dl 11
loc 11
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 7
nc 1
nop 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\plan;
12
13
use hiqdev\php\billing\customer\Customer;
14
use hiqdev\php\billing\price\PriceInterface;
15
use hiqdev\yii\DataMapper\hydrator\GeneratedHydratorTrait;
16
use hiqdev\yii\DataMapper\hydrator\RootHydratorAwareTrait;
17
use Zend\Hydrator\HydratorInterface;
18
19
/**
20
 * Class PlanHydrator.
21
 *
22
 * @author Andrii Vasyliev <[email protected]>
23
 */
24
class PlanHydrator implements HydratorInterface
25
{
26
    use RootHydratorAwareTrait;
27
28
    use GeneratedHydratorTrait {
29
        hydrate as generatedHydrate;
30
    }
31
32
    /**
33
     * {@inheritdoc}
34
     * @param object|Plan $object
35
     */
36
    public function hydrate(array $data, $object)
37
    {
38
        $data['seller'] = $this->hydrator->hydrate($data['seller'], Customer::class);
39
        $raw_prices = $data['prices'];
40
        unset($data['prices']);
41
42
        /** @var Plan $plan */
43
        $plan = $this->generatedHydrate($data, $object);
44
45
        if (is_array($raw_prices)) {
46
            $prices = [];
47
            foreach ($raw_prices as $key => $price) {
48
                $price['plan'] = $plan;
49
                $prices[$key] = $this->hydrator->hydrate($price, PriceInterface::class);
50
            }
51
            $plan->setPrices($prices);
52
        }
53
54
        return $plan;
55
    }
56
57
    /**
58
     * {@inheritdoc}
59
     * @param object|Plan $object
60
     */
61 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...
62
    {
63
        $result = array_filter([
64
            'id'            => $object->getId(),
65
            'name'          => $object->getName(),
66
            'parent_id'     => $object->parent->getid(),
67
            'seller_id'     => $object->seller->getid(),
68
        ]);
69
70
        return $result;
71
    }
72
}
73