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

BillStateHydrator::hydrate()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 3
ccs 0
cts 3
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 1
nc 1
nop 2
crap 2
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