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) |
|
|
|
|
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
|
|
|
|
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.