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

InterfaceTypeConfig::resolveType()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 3.072

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 10
ccs 4
cts 5
cp 0.8
rs 9.4286
cc 3
eloc 5
nc 2
nop 1
crap 3.072
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
}