Completed
Pull Request — master (#30)
by Quang
02:15
created

TypeResolver::resolveType()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 4
c 0
b 0
f 0
nc 2
nop 1
dl 0
loc 9
rs 9.6666
1
<?php
2
3
namespace Digia\Lumen\GraphQL\Types;
4
5
use Digia\Lumen\GraphQL\Contracts\TypeResolverInterface;
6
use Digia\Lumen\GraphQL\Exceptions\UnsupportedTypeException;
7
use Youshido\GraphQL\Type\AbstractType;
8
9
/**
10
 * Class TypeResolver
11
 * @package Digia\Lumen\GraphQL\Types
12
 */
13
class TypeResolver implements TypeResolverInterface
14
{
15
    /**
16
     * @param array $object
17
     *
18
     * @return AbstractType
19
     *
20
     * @throws UnsupportedTypeException
21
     */
22
    public static function resolveType(array $object): AbstractType
23
    {
24
        if (!array_key_exists($object['type'], config('graphql.types'))) {
25
            throw new UnsupportedTypeException(sprintf('Unsupported entity type `%s`.', $object['type']));
26
        }
27
28
        $className = config('graphql.types')[$object['type']];
29
30
        return new $className();
31
    }
32
}
33