Code Duplication    Length = 30-30 lines in 2 locations

src/Type/Config/Object/InterfaceTypeConfig.php 1 location

@@ 18-47 (lines=30) @@
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
    public function getRules()
23
    {
24
        return [
25
            'name'        => ['type' => TypeMap::TYPE_STRING, 'required' => true],
26
            'fields'      => ['type' => TypeMap::TYPE_ARRAY_OF_FIELDS],
27
            'description' => ['type' => TypeMap::TYPE_STRING],
28
            'resolveType' => ['type' => TypeMap::TYPE_FUNCTION]
29
        ];
30
    }
31
32
    protected function build()
33
    {
34
        $this->buildFields();
35
    }
36
37
    public function resolveType($object)
38
    {
39
        $callable = $this->get('resolveType');
40
41
        if($callable && is_callable($callable)) {
42
            return call_user_func_array($callable, [$object]);
43
        }
44
45
        return $this->contextObject->resolveType($object);
46
    }
47
}

src/Type/Config/Object/UnionTypeConfig.php 1 location

@@ 18-47 (lines=30) @@
15
use Youshido\GraphQL\Type\Config\TypeConfigInterface;
16
use Youshido\GraphQL\Type\TypeMap;
17
18
class UnionTypeConfig extends Config implements TypeConfigInterface
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
}