Completed
Push — master ( 1826e3...724c6f )
by Rafael
07:29
created

InterfaceDefinitionType::resolveFields()   B

Complexity

Conditions 5
Paths 7

Size

Total Lines 25
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 14
CRAP Score 5.0073

Importance

Changes 0
Metric Value
dl 0
loc 25
ccs 14
cts 15
cp 0.9333
rs 8.439
c 0
b 0
f 0
cc 5
eloc 14
nc 7
nop 0
crap 5.0073
1
<?php
2
/*******************************************************************************
3
 *  This file is part of the GraphQL Bundle package.
4
 *
5
 *  (c) YnloUltratech <[email protected]>
6
 *
7
 *  For the full copyright and license information, please view the LICENSE
8
 *  file that was distributed with this source code.
9
 ******************************************************************************/
10
11
namespace Ynlo\GraphQLBundle\Type\Definition;
12
13
use GraphQL\Type\Definition\InterfaceType;
14
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
15
use Symfony\Component\DependencyInjection\ContainerAwareTrait;
16
use Ynlo\GraphQLBundle\Definition\InterfaceDefinition;
17
use Ynlo\GraphQLBundle\Util\GraphQLBuilder;
18
use Ynlo\GraphQLBundle\Util\TypeUtil;
19
20
/**
21
 * Class InterfaceDefinitionType
22
 */
23
class InterfaceDefinitionType extends InterfaceType implements EndpointAwareInterface, ContainerAwareInterface
24
{
25
    use ContainerAwareTrait;
26
    use EndpointAwareTrait;
27
28
    /**
29
     * @var InterfaceDefinition
30
     */
31
    protected $definition;
32
33
    /**
34
     * InterfaceDefinitionType constructor.
35
     *
36
     * @param InterfaceDefinition $definition
37
     */
38
    public function __construct(InterfaceDefinition $definition)
39 22
    {
40
        $this->definition = $definition;
41 22
42
        parent::__construct(
43 22
            [
44
                'name' => $definition->getName(),
45 22
                'description' => $definition->getDescription(),
46 22
                'fields' => function () use ($definition) {
47 22
                    return GraphQLBuilder::resolveFields($definition);
48 22
                },
49 22
                'resolveType' => function ($value) {
50 22
                    return TypeUtil::resolveObjectType($this->endpoint, $value);
51 7
                },
52 7
            ]
53
        );
54 7
    }
55
}
56