Completed
Pull Request — master (#63)
by David
02:03
created

FactoryHydrator::hydrate()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 3
dl 0
loc 6
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 2
1
<?php
2
3
4
namespace TheCodingMachine\GraphQL\Controllers\Hydrators;
5
6
use GraphQL\Type\Definition\InputObjectType;
7
use TheCodingMachine\GraphQL\Controllers\GraphQLException;
8
use TheCodingMachine\GraphQL\Controllers\HydratorInterface;
9
use TheCodingMachine\GraphQL\Controllers\Types\ResolvableInputObjectType;
10
11
/**
12
 * Hydrates input types based on the Factory annotation.
13
 */
14
class FactoryHydrator implements HydratorInterface
15
{
16
17
    /**
18
     * Hydrates/returns an object based on a PHP array and a GraphQL type.
19
     *
20
     * @param mixed[] $data
21
     * @param InputObjectType $type
22
     * @return object
23
     */
24
    public function hydrate(array $data, InputObjectType $type)
25
    {
26
        if ($type instanceof ResolvableInputObjectType) {
27
            return $type->resolve($data);
28
        }
29
        throw new GraphQLException('Cannot hydrate type '.$type->name);
30
    }
31
}
32