Completed
Push — master ( 3d21e8...29ef50 )
by Alexandr
9s
created

Issue99Schema::build()   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 52
Code Lines 31

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 52
rs 9.4929
cc 2
eloc 31
nc 1
nop 1

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
namespace Youshido\Tests\Issues\Issue99;
3
4
use Youshido\GraphQL\Config\Schema\SchemaConfig;
5
use Youshido\GraphQL\Field\Field;
6
use Youshido\GraphQL\Schema\AbstractSchema;
7
use Youshido\GraphQL\Type\InputObject\InputObjectType;
8
use Youshido\GraphQL\Type\ListType\ListType;
9
use Youshido\GraphQL\Type\NonNullType;
10
use Youshido\GraphQL\Type\Object\ObjectType;
11
use Youshido\GraphQL\Type\Scalar\IdType;
12
use Youshido\GraphQL\Type\Scalar\StringType;
13
14
class Issue99Schema extends AbstractSchema
15
{
16
    public function build(SchemaConfig $config)
17
    {
18
        $config->setQuery(
19
            new ObjectType([
20
                'fields' => [
21
                    new Field([
22
                        'name' => 'items',
23
                        'type' => new ListType(new ObjectType([
24
                            'fields'  => [
25
                                'id'   => new NonNullType(new IdType()),
26
                                new Field([
27
                                    'name' => 'custom',
28
                                    'type' => new ObjectType([
29
                                        'fields' => [
30
                                            'value' => new StringType()
31
                                        ],
32
                                    ]),
33
                                    'args' => [
34
                                        'argX' => [
35
                                            'type' => new NonNullType(new InputObjectType([
36
                                                'fields' => [
37
                                                    'x' => new NonNullType(new StringType())
38
                                                ]
39
                                            ]))
40
                                        ]
41
                                    ],
42
                                    'resolve' => function($source, $args) {
43
                                        $x = isset($args['argX']['x']) ? $args['argX']['x'] : Issue99Test::BUG_EXISTS_VALUE;
44
45
                                        return [
46
                                            'value' => $x
47
                                        ];
48
                                    }
49
                                ])
50
                            ],
51
                        ])),
52
                        'args'    => [
53
                            'example' => new StringType()
54
                        ],
55
                        'resolve' => function () {
56
                            return [
57
                                ['id' => 1],
58
                                ['id' => 2],
59
                                ['id' => 3],
60
                                ['id' => 4],
61
                            ];
62
                        }
63
                    ])
64
                ]
65
            ])
66
        );
67
    }
68
}