Completed
Push — master ( 104946...6683dc )
by Dmitry
02:26
created

BillStateHydrator   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 14
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 2
eloc 3
dl 0
loc 14
ccs 0
cts 7
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A hydrate() 0 3 1
A extract() 0 3 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-2018, HiQDev (http://hiqdev.com/)
9
 */
10
11
namespace hiqdev\billing\hiapi\bill;
12
13
use hiqdev\php\billing\bill\BillState;
14
use hiqdev\yii\DataMapper\hydrator\GeneratedHydrator;
15
16
/**
17
 * BillState Hydrator.
18
 *
19
 * @author Andrii Vasyliev <[email protected]>
20
 */
21
class BillStateHydrator extends GeneratedHydrator
22
{
23
    public function hydrate(array $data, $object)
24
    {
25
        return BillState::fromString($data['state'] ?? reset($data));
26
    }
27
28
    /**
29
     * {@inheritdoc}
30
     * @param BillState $object
31
     */
32
    public function extract($object)
33
    {
34
        return $object->getName();
0 ignored issues
show
Bug Best Practice introduced by
The expression return $object->getName() returns the type string which is incompatible with the return type mandated by Zend\Hydrator\ExtractionInterface::extract() of array.

In the issue above, the returned value is violating the contract defined by the mentioned interface.

Let's take a look at an example:

interface HasName {
    /** @return string */
    public function getName();
}

class Name {
    public $name;
}

class User implements HasName {
    /** @return string|Name */
    public function getName() {
        return new Name('foo'); // This is a violation of the ``HasName`` interface
                                // which only allows a string value to be returned.
    }
}
Loading history...
35
    }
36
}
37