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

TypeResolver::resolve()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 5
nc 2
nop 1
dl 0
loc 11
rs 9.4285
c 0
b 0
f 0
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