Completed
Push — master ( 631929...5231d5 )
by Alexandr
02:39
created

SchemaType::resolveDirectives()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 3
cts 3
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 1
crap 1
1
<?php
2
/**
3
 * Date: 03.12.15
4
 *
5
 * @author Portey Vasil <[email protected]>
6
 */
7
8
namespace Youshido\GraphQL\Introspection;
9
10
use Youshido\GraphQL\Field\Field;
11
use Youshido\GraphQL\Introspection\Field\TypesField;
12
use Youshido\GraphQL\Schema\AbstractSchema;
13
use Youshido\GraphQL\Type\ListType\ListType;
14
use Youshido\GraphQL\Type\Object\AbstractObjectType;
15
use Youshido\GraphQL\Type\Object\ObjectType;
16
use Youshido\GraphQL\Type\TypeMap;
17
18
class SchemaType extends AbstractObjectType
19
{
20
21
    /**
22
     * @return String type name
23
     */
24 65
    public function getName()
25
    {
26 65
        return '__Schema';
27
    }
28
29 4
    public function resolveQueryType($value)
30
    {
31
        /** @var AbstractSchema|Field $value */
32 4
        return $value->getQueryType();
0 ignored issues
show
Bug introduced by
The method getQueryType does only exist in Youshido\GraphQL\Schema\AbstractSchema, but not in Youshido\GraphQL\Field\Field.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
33
    }
34
35 2
    public function resolveMutationType($value)
36
    {
37
        /** @var AbstractSchema|Field $value */
38 2
        return $value->getMutationType()->hasFields() ? $value->getMutationType() : null;
0 ignored issues
show
Bug introduced by
The method getMutationType does only exist in Youshido\GraphQL\Schema\AbstractSchema, but not in Youshido\GraphQL\Field\Field.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
39
    }
40
41 1
    public function resolveSubscriptionType()
42
    {
43 1
        return null;
44
    }
45
46 2
    public function resolveDirectives($value)
47
    {
48
        /** @var AbstractSchema|Field $value */
49 2
        $dirs = $value->getDirectiveList()->getDirectives();
0 ignored issues
show
Bug introduced by
The method getDirectiveList does only exist in Youshido\GraphQL\Schema\AbstractSchema, but not in Youshido\GraphQL\Field\Field.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
50 2
        return $dirs;
51
    }
52
53 9
    public function build($config)
54
    {
55
        $config
56 9
            ->addField(new Field([
57 9
                'name'    => 'queryType',
58 9
                'type'    => new QueryType(),
59 9
                'resolve' => [$this, 'resolveQueryType']
60
            ]))
61 9
            ->addField(new Field([
62 9
                'name'    => 'mutationType',
63 9
                'type'    => new QueryType(),
64 9
                'resolve' => [$this, 'resolveMutationType']
65
            ]))
66 9
            ->addField(new Field([
67 9
                'name'    => 'subscriptionType',
68 9
                'type'    => new QueryType(),
69 9
                'resolve' => [$this, 'resolveSubscriptionType']
70
            ]))
71 9
            ->addField(new TypesField())
72 9
            ->addField(new Field([
73 9
                'name'    => 'directives',
74 9
                'type'    => new ListType(new DirectiveType()),
75 9
                'resolve' => [$this, 'resolveDirectives']
76
            ]));
77 9
    }
78
}
79