Passed
Pull Request — master (#63)
by David
03:26
created

FactoryHydrator   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 16
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 2
eloc 4
dl 0
loc 16
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A hydrate() 0 6 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