InterfaceFromObjectType   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 2
eloc 11
dl 0
loc 23
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 16 2
1
<?php
2
3
4
namespace TheCodingMachine\GraphQL\Controllers\Types;
5
6
7
use GraphQL\Type\Definition\ObjectType;
8
use GraphQL\Type\Definition\OutputType;
9
use TheCodingMachine\GraphQL\Controllers\Mappers\RecursiveTypeMapperInterface;
10
11
class InterfaceFromObjectType extends \GraphQL\Type\Definition\InterfaceType
12
{
13
    /**
14
     * @param string $name The name of the interface
15
     * @param ObjectType $type
16
     * @param RecursiveTypeMapperInterface $typeMapper
17
     */
18
    public function __construct(string $name, ObjectType $type, ?ObjectType $subType, RecursiveTypeMapperInterface $typeMapper)
19
    {
20
        parent::__construct([
21
            'name' => $name,
22
            'fields' => function() use ($type) {
23
                return $type->getFields();
24
            },
25
            'description' => $type->description,
26
            'resolveType' => function($value) use ($typeMapper, $subType) {
27
                if (!is_object($value)) {
28
                    throw new \InvalidArgumentException('Expected object for resolveType. Got: "'.gettype($value).'"');
29
                }
30
31
                $className = get_class($value);
32
33
                return $typeMapper->mapClassToType($className, $subType);
34
            }
35
        ]);
36
    }
37
}
38