Completed
Push — master ( c82baa...ed63c5 )
by Andrii
06:43
created

BillHydrator   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 43
Duplicated Lines 37.21 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 2
dl 16
loc 43
ccs 0
cts 29
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A hydrate() 16 16 3
A extract() 0 14 3

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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\bill;
12
13
use DateTimeImmutable;
14
use hiqdev\billing\hiapi\models\Plan;
15
use hiqdev\php\billing\customer\Customer;
16
use hiqdev\php\billing\formula\FormulaInterface;
17
use hiqdev\php\billing\price\PriceFactoryInterface;
18
use hiqdev\php\billing\target\Target;
19
use hiqdev\php\billing\type\Type;
20
use hiqdev\php\units\Quantity;
21
use hiqdev\php\units\Unit;
22
use hiqdev\yii\DataMapper\hydrator\GeneratedHydrator;
23
use Money\Currency;
24
use Money\Money;
25
use yii\helpers\Json;
26
use Zend\Hydrator\HydratorInterface;
27
28
/**
29
 * Bill Hydrator.
30
 *
31
 * @author Andrii Vasyliev <[email protected]>
32
 */
33
class BillHydrator extends GeneratedHydrator
34
{
35
    /**
36
     * {@inheritdoc}
37
     * @param object|Plan $object
38
     */
39 View Code Duplication
    public function hydrate(array $row, $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...
40
    {
41
        $row['type']        = $this->hydrator->create($row['type'],     Type::class);
0 ignored issues
show
Bug introduced by
The method create() does not seem to exist on object<Zend\Hydrator\HydratorInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
42
        $row['time']        = $this->hydrator->create($row['time'],     DateTimeImmutable::class);
0 ignored issues
show
Bug introduced by
The method create() does not seem to exist on object<Zend\Hydrator\HydratorInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
43
        $row['sum']         = $this->hydrator->create($row['sum'],      Money::class);
0 ignored issues
show
Bug introduced by
The method create() does not seem to exist on object<Zend\Hydrator\HydratorInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
44
        $row['quantity']    = $this->hydrator->create($row['quantity'], Quantity::class);
0 ignored issues
show
Bug introduced by
The method create() does not seem to exist on object<Zend\Hydrator\HydratorInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
45
        $row['customer']    = $this->hydrator->create($row['customer'], Customer::class);
0 ignored issues
show
Bug introduced by
The method create() does not seem to exist on object<Zend\Hydrator\HydratorInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
46
        if (isset($row['target'])) {
47
            $row['target']  = $this->hydrator->create($row['target'],   Target::class);
0 ignored issues
show
Bug introduced by
The method create() does not seem to exist on object<Zend\Hydrator\HydratorInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
48
        }
49
        if (isset($row['plan'])) {
50
            $row['plan']    = $this->hydrator->create($row['plan'],     Plan::class);
0 ignored issues
show
Bug introduced by
The method create() does not seem to exist on object<Zend\Hydrator\HydratorInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
51
        }
52
53
        return parent::hydrate($row, $object);
54
    }
55
56
    /**
57
     * {@inheritdoc}
58
     * @param object|Plan $object
59
     */
60
    public function extract($object)
61
    {
62
        return array_filter([
63
            'id'            => $object->getId(),
64
            'type'          => $this->hydrator->extract($object->getType()),
65
            'time'          => $this->hydrator->extract($object->getTime()),
66
            'sum'           => $this->hydrator->extract($object->getSum()),
67
            'quantity'      => $this->hydrator->extract($object->getQuantity()),
68
            'customer'      => $this->hydrator->extract($object->getCustomer()),
69
            'target'        => $object->getTarget() ? $this->hydrator->extract($object->getTarget()) : null,
70
            'plan'          => $object->getPlan() ? $this->hydrator->extract($object->getPlan()) : null,
71
            'charges'       => $this->hydrator->extractMultiple($object->getCharges()),
0 ignored issues
show
Bug introduced by
The method extractMultiple() does not exist on Zend\Hydrator\HydratorInterface. Did you maybe mean extract()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
72
        ]);
73
    }
74
75
}
76