Completed
Push — master ( c02837...734e06 )
by Portey
03:28
created

UnionTypeConfig::build()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 4
Ratio 100 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 4
loc 4
ccs 0
cts 4
cp 0
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 2
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 View Code Duplication
class UnionTypeConfig extends Config implements TypeConfigInterface
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
19
{
20
    use FieldsAwareTrait, ArgumentsAwareTrait;
21
22
    public function getRules()
23
    {
24
        return [
25
            'name'        => ['type' => TypeMap::TYPE_STRING, 'required' => true],
26
            'types'       => ['type' => TypeMap::TYPE_ARRAY_OF_FIELDS],
27
            'description' => ['type' => TypeMap::TYPE_STRING],
28
            'resolveType' => ['type' => TypeMap::TYPE_FUNCTION]
29
        ];
30
    }
31
32
    public function resolveType($object)
33
    {
34
        $callable = $this->get('resolveType');
35
36
        if ($callable && is_callable($callable)) {
37
            return call_user_func_array($callable, [$object]);
38
        }
39
40
        return $this->contextObject->resolveType($object);
41
    }
42
43
    protected function build()
44
    {
45
        $this->buildFields();
46
    }
47
}