hiqdev /
billing-hiapi
| 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\target; |
||||
| 12 | |||||
| 13 | use hiqdev\php\billing\target\TargetInterface; |
||||
| 14 | use hiqdev\billing\hiapi\models\Target; |
||||
| 15 | use hiqdev\php\billing\target\TargetFactoryInterface; |
||||
| 16 | use hiqdev\yii\DataMapper\hydrator\GeneratedHydrator; |
||||
| 17 | use Zend\Hydrator\HydratorInterface; |
||||
| 18 | |||||
| 19 | /** |
||||
| 20 | * Class TargetHydrator. |
||||
| 21 | * |
||||
| 22 | * @author Andrii Vasyliev <[email protected]> |
||||
| 23 | */ |
||||
| 24 | class TargetHydrator extends GeneratedHydrator |
||||
| 25 | { |
||||
| 26 | /** |
||||
| 27 | * @var TargetFactoryInterface |
||||
| 28 | */ |
||||
| 29 | private $targetFactory; |
||||
| 30 | |||||
| 31 | 1 | public function __construct(HydratorInterface $hydrator, TargetFactoryInterface $targetFactory) |
|||
| 32 | { |
||||
| 33 | 1 | parent::__construct($hydrator); |
|||
| 34 | 1 | $this->targetFactory = $targetFactory; |
|||
| 35 | 1 | } |
|||
| 36 | |||||
| 37 | /** |
||||
| 38 | * {@inheritdoc} |
||||
| 39 | * @param object|Target $object |
||||
| 40 | */ |
||||
| 41 | public function extract($object) |
||||
| 42 | { |
||||
| 43 | return [ |
||||
| 44 | 'id' => $this->extractNone($object->getId()), |
||||
|
0 ignored issues
–
show
|
|||||
| 45 | 'type' => $this->extractNone($object->getType()), |
||||
|
0 ignored issues
–
show
The method
getType() does not exist on hiqdev\billing\hiapi\models\Target.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. Loading history...
|
|||||
| 46 | 'name' => $object->getName(), |
||||
|
0 ignored issues
–
show
The method
getName() does not exist on hiqdev\billing\hiapi\models\Target.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. Loading history...
|
|||||
| 47 | ]; |
||||
| 48 | } |
||||
| 49 | |||||
| 50 | protected function extractNone($value) |
||||
| 51 | { |
||||
| 52 | /** |
||||
| 53 | * XXX JSON doesn't support float INF and NAN |
||||
| 54 | * TODO think of it more. |
||||
| 55 | */ |
||||
| 56 | return $value === TargetInterface::NONE ? '' : $value; |
||||
| 57 | } |
||||
| 58 | |||||
| 59 | /** {@inheritdoc} */ |
||||
| 60 | 6 | public function hydrate(array $data, $object) |
|||
| 61 | { |
||||
| 62 | 6 | if (!empty($data['type'])) { |
|||
| 63 | 6 | $data['type'] = $this->targetFactory->shortenType($data['type']); |
|||
| 64 | } |
||||
| 65 | |||||
| 66 | 6 | return parent::hydrate($data, $object); |
|||
| 67 | } |
||||
| 68 | |||||
| 69 | 5 | public function createEmptyInstance(string $className, array $data = []) |
|||
| 70 | { |
||||
| 71 | 5 | if (isset($data['type'])) { |
|||
| 72 | 5 | $className = $this->targetFactory->getClassForType($data['type']); |
|||
| 73 | } |
||||
| 74 | |||||
| 75 | 5 | return parent::createEmptyInstance($className, $data); |
|||
| 76 | } |
||||
| 77 | } |
||||
| 78 |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.