Completed
Push — master ( d01340...7e7fa7 )
by Portey
07:36
created

InterfaceTypeConfig::build()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
/*
3
* This file is a part of GraphQL project.
4
*
5
* @author Alexandr Viniychuk <[email protected]>
6
* created: 12/5/15 12:18 AM
7
*/
8
9
namespace Youshido\GraphQL\Type\Config\Object;
10
11
12
use Youshido\GraphQL\Type\Config\Config;
13
use Youshido\GraphQL\Type\Config\Traits\ArgumentsAwareTrait;
14
use Youshido\GraphQL\Type\Config\Traits\FieldsAwareTrait;
15
use Youshido\GraphQL\Type\Config\TypeConfigInterface;
16
use Youshido\GraphQL\Type\TypeMap;
17
18
class InterfaceTypeConfig extends Config implements TypeConfigInterface
19
{
20
    use FieldsAwareTrait, ArgumentsAwareTrait;
21
22 6
    public function getRules()
23
    {
24
        return [
25 6
            'name'        => ['type' => TypeMap::TYPE_STRING, 'required' => true],
26 6
            'fields'      => ['type' => TypeMap::TYPE_ARRAY_OF_FIELDS],
27 6
            'description' => ['type' => TypeMap::TYPE_STRING],
28 6
            'resolveType' => ['type' => TypeMap::TYPE_FUNCTION]
29 6
        ];
30
    }
31
32 6
    protected function build()
33
    {
34 6
        $this->buildFields();
35 6
    }
36
37 2
    public function resolveType($object)
38
    {
39 2
        $callable = $this->get('resolveType');
40
41 2
        if($callable && is_callable($callable)) {
42
            return call_user_func_array($callable, [$object]);
43
        }
44
45 2
        return $this->contextObject->resolveType($object);
46
    }
47
}