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

SaleHydrator   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 27
Duplicated Lines 37.04 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 2
dl 10
loc 27
ccs 0
cts 18
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A hydrate() 0 9 1
A extract() 10 10 2

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\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