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

src/bill/BillStateHydrator.php (1 issue)

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