Completed
Push — master ( 6c95d8...49bfd8 )
by Christoffer
03:47 queued 01:30
created

TypeResolver   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 16
Duplicated Lines 0 %

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A resolve() 0 11 2
1
<?php
2
3
namespace Digia\GraphQL\Execution\Resolver;
4
5
use Digia\GraphQL\Execution\ExecutionEnvironment;
6
7
class TypeResolver implements ResolverInterface
8
{
9
    /**
10
     * @inheritdoc
11
     */
12
    public function resolve(ExecutionEnvironment $environment)
13
    {
14
        $schema    = $environment->getInfo()->getSchema();
15
        // TODO: Benchmark
16
        $className = (new \ReflectionClass($environment->getValue()))->getShortName();
17
18
        if (null !== ($type = $schema->getType($className . 'Type'))) {
19
            return $type;
20
        }
21
22
        throw new \Exception(sprintf('Could not resolve type for class "%s".', $className));
23
    }
24
}
25