Introspection   F
last analyzed

Complexity

Total Complexity 106

Size/Duplication

Total Lines 871
Duplicated Lines 3.44 %

Coupling/Cohesion

Components 9
Dependencies 12

Test Coverage

Coverage 94.1%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 106
c 2
b 0
f 0
lcom 9
cbo 12
dl 30
loc 871
ccs 287
cts 305
cp 0.941
rs 1.263

46 Methods

Rating   Name   Duplication   Size   Complexity  
A resolveSchemaTypes() 0 7 2
A resolveSchemaQueryType() 0 7 2
A resolveSchemaMutationType() 0 7 2
A resolveSchemaDirectives() 0 7 2
B schema() 0 29 2
A resolveDirectiveName() 0 7 2
A resolveDirectiveDescription() 0 7 2
A resolveDirectiveArguments() 0 7 2
A resolveDirectiveOnOperation() 0 7 2
A resolveDirectiveOnFragment() 0 7 2
A resolveDirectiveOnField() 0 7 2
B directive() 0 33 2
D resolveTypeKind() 0 35 9
A resolveTypeName() 0 7 2
A resolveTypeDescription() 0 7 2
A resolveTypeFields() 15 15 4
A resolveTypeInterfaces() 0 7 2
A resolveTypePossibleTypes() 0 7 3
A resolveTypeEnumValues() 15 15 3
A resolveTypeOfType() 0 5 2
A type() 0 57 2
A resolveFieldName() 0 7 2
A resolveFieldDescription() 0 7 2
A resolveFieldArguments() 0 7 3
A resolveFieldType() 0 7 2
A resolveFieldIsDeprecated() 0 7 2
A resolveFieldDeprecationReason() 0 7 2
B field() 0 33 2
A resolveInputValueName() 0 7 3
A resolveInputValueDescription() 0 7 3
A resolveInputValueType() 0 7 3
A resolveInputValueDefaultValue() 0 8 4
B inputValue() 0 25 2
A resolveEnumValueName() 0 7 2
A resolveEnumValueDescription() 0 7 2
A resolveEnumValueIsDeprecated() 0 7 2
A resolveEnumValueDeprecationReason() 0 7 2
B enumValue() 0 25 2
B typeKind() 0 41 2
A resolveSchemaMetaField() 0 3 1
A schemaMetaFieldDefinition() 0 14 2
A resolveTypeMetaField() 0 3 1
A typeMetaFieldDefinition() 0 16 2
A resolveTypeNameMetaField() 0 3 1
A typeNameMetaFieldDefinition() 0 14 2
A resolveTypeInputFields() 0 7 2

How to fix   Duplicated Code    Complexity   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

Complex Class

 Tip:   Before tackling complexity, make sure that you eliminate any duplication first. This often can reduce the size of classes significantly.

Complex classes like Introspection often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use Introspection, and based on these observations, apply Extract Interface, too.

1
<?php
2
3
namespace Fubhy\GraphQL\Type;
4
5
use Fubhy\GraphQL\Schema;
6
use Fubhy\GraphQL\Type\Definition\EnumValueDefinition;
7
use Fubhy\GraphQL\Type\Definition\FieldArgument;
8
use Fubhy\GraphQL\Type\Definition\FieldDefinition;
9
use Fubhy\GraphQL\Type\Definition\InputObjectField;
10
use Fubhy\GraphQL\Type\Definition\Types\EnumType;
11
use Fubhy\GraphQL\Type\Definition\Types\InputObjectType;
12
use Fubhy\GraphQL\Type\Definition\Types\InterfaceType;
13
use Fubhy\GraphQL\Type\Definition\Types\ListModifier;
14
use Fubhy\GraphQL\Type\Definition\Types\ModifierInterface;
15
use Fubhy\GraphQL\Type\Definition\Types\NonNullModifier;
16
use Fubhy\GraphQL\Type\Definition\Types\ObjectType;
17
use Fubhy\GraphQL\Type\Definition\Types\ScalarTypeInterface;
18
use Fubhy\GraphQL\Type\Definition\Types\Type;
19
use Fubhy\GraphQL\Type\Definition\Types\TypeInterface;
20
use Fubhy\GraphQL\Type\Definition\Types\UnionType;
21
use Fubhy\GraphQL\Type\Directives\DirectiveInterface;
22
23
class Introspection
24
{
25
    const TYPEKIND_SCALAR = 0;
26
    const TYPEKIND_OBJECT = 1;
27
    const TYPEKIND_INTERFACE = 2;
28
    const TYPEKIND_UNION = 3;
29
    const TYPEKIND_ENUM = 4;
30
    const TYPEKIND_INPUT_OBJECT = 5;
31
    const TYPEKIND_LIST = 6;
32
    const TYPEKIND_NON_NULL = 7;
33
34
    /**
35
     * @var \Fubhy\GraphQL\Type\Definition\Types\ObjectType
36
     */
37
    protected static $schema;
38
39
    /**
40
     * @var \Fubhy\GraphQL\Type\Definition\Types\ObjectType
41
     */
42
    protected static $directive;
43
44
    /**
45
     * @var \Fubhy\GraphQL\Type\Definition\Types\ObjectType
46
     */
47
    protected static $type;
48
49
    /**
50
     * @var \Fubhy\GraphQL\Type\Definition\Types\ObjectType
51
     */
52
    protected static $field;
53
54
    /**
55
     * @var \Fubhy\GraphQL\Type\Definition\Types\ObjectType
56
     */
57
    protected static $inputValue;
58
59
    /**
60
     * @var \Fubhy\GraphQL\Type\Definition\Types\ObjectType
61
     */
62
    protected static $typeKind;
63
64
    /**
65
     * @var \Fubhy\GraphQL\Type\Definition\Types\ObjectType
66
     */
67
    protected static $enumValue;
68
69
    /**
70
     * @var \Fubhy\GraphQL\Type\Definition\FieldDefinition
71
     */
72
    protected static $typeNameMetaFieldDefinition;
73
74
    /**
75
     * @var \Fubhy\GraphQL\Type\Definition\FieldDefinition
76
     */
77
    protected static $schemaMetaFieldDefinition;
78
79
    /**
80
     * @var \Fubhy\GraphQL\Type\Definition\FieldDefinition
81
     */
82
    protected static $typeMetaFieldDefinition;
83
84
    /**
85
     * @param $source
86
     * @return array|null
87 159
     */
88
    public static function resolveSchemaTypes($source) {
89 159
        if ($source instanceof Schema) {
90 3
            return array_values($source->getTypeMap());
91
        }
92 3
93 3
        return NULL;
94
    }
95 9
96 9
    /**
97
     * @param $source
98 3
     * @return \Fubhy\GraphQL\Type\Definition\Types\ObjectType|null
99 3
     */
100
    public static function resolveSchemaQueryType($source) {
101 3
        if ($source instanceof Schema) {
102 3
            return $source->getQueryType();
103
        }
104 9
105 9
        return NULL;
106
    }
107 3
108 3
    /**
109
     * @param $source
110 3
     * @return \Fubhy\GraphQL\Type\Definition\Types\ObjectType|null
111 3
     */
112
    public static function resolveSchemaMutationType($source) {
113 3
        if ($source instanceof Schema) {
114 3
            return $source->getMutationType();
115
        }
116 3
117 3
        return NULL;
118
    }
119 3
120 3
    /**
121
     * @param $source
122 3
     * @return \Fubhy\GraphQL\Type\Directives\DirectiveInterface[]|null
123 3
     */
124
    public static function resolveSchemaDirectives($source) {
125 3
        if ($source instanceof Schema) {
126 3
            return $source->getDirectives();
127 3
        }
128 3
129
        return NULL;
130 159
    }
131
132
    /**
133
     * @return \Fubhy\GraphQL\Type\Definition\Types\ObjectType
134
     */
135
    public static function schema()
136 153
    {
137
        if (!isset(static::$schema)) {
138 153
            static::$schema = new ObjectType('__Schema', [
139 3
                'types' => [
140
                    'description' => 'A list of all types supported by this server.',
141 3
                    'type' => new NonNullModifier(new ListModifier(new NonNullModifier([__CLASS__, 'type']))),
142
                    'resolve' => [__CLASS__, 'resolveSchemaTypes'],
143 3
                ],
144 3
                'queryType' => [
145
                    'description' => 'The type that query operations will be rooted at.',
146
                    'type' => new NonNullModifier([__CLASS__, 'type']),
147 3
                    'resolve' => [__CLASS__, 'resolveSchemaQueryType'],
148
                ],
149 3
                'mutationType' => [
150
                    'description' => 'If this server supports mutation, the type that mutation operations will be rooted at.',
151
                    'type' => [__CLASS__, 'type'],
152
                    'resolve' => [__CLASS__, 'resolveSchemaMutationType'],
153
                ],
154
                'directives' => [
155 3
                    'description' => 'A list of all directives supported by this server.',
156
                    'type' => new NonNullModifier(new ListModifier(new NonNullModifier([__CLASS__, 'directive']))),
157 3
                    'resolve' => [__CLASS__, 'resolveSchemaDirectives'],
158
                ],
159 3
            ], [], NULL, 'A GraphQL Schema defines the capabilities of a GraphQL server. It exposes all available types and directives on the server, as well as the entry points for query and mutation operations.');
160 3
        }
161
162
        return static::$schema;
163 3
    }
164
165 3
    /**
166
     * @param $source
167 3
     * @return string
168 3
     */
169
    public static function resolveDirectiveName($source) {
170
        if ($source instanceof DirectiveInterface) {
171 3
            return $source->getName();
172
        }
173 3
174
        return NULL;
175 3
    }
176 3
177
178
    /**
179 3
     * @param $source
180
     * @return string
181 3
     */
182
    public static function resolveDirectiveDescription($source) {
183 3
        if ($source instanceof DirectiveInterface) {
184 3
            return $source->getDescription();
185
        }
186
187 3
        return NULL;
188 3
    }
189 3
190
    /**
191 153
     * @param $source
192
     * @return string
193
     */
194
    public static function resolveDirectiveArguments($source) {
195
        if ($source instanceof DirectiveInterface) {
196
            return $source->getArguments();
197 159
        }
198
199 159
        return NULL;
200 3
    }
201
202 3
    /**
203
     * @param $source
204 24
     * @return bool|null
205 15
     */
206
    public static function resolveDirectiveOnOperation($source) {
207
        if ($source instanceof DirectiveInterface) {
208 24
            return $source->onOperation();
209 9
        }
210
211
        return NULL;
212 21
    }
213 12
214
    /**
215
     * @param $source
216 21
     * @return bool|null
217 3
     */
218
    public static function resolveDirectiveOnFragment($source) {
219
        if ($source instanceof DirectiveInterface) {
220 21
            return $source->onFragment();
221 9
        }
222
223
        return NULL;
224 18
    }
225 3
226
    /**
227
     * @param $source
228 15
     * @return bool|null
229 12
     */
230
    public static function resolveDirectiveOnField($source) {
231
        if ($source instanceof DirectiveInterface) {
232 12
            return $source->onField();
233 12
        }
234
235
        return NULL;
236
    }
237 3
238 3
    /**
239
     * @return \Fubhy\GraphQL\Type\Definition\Types\ObjectType
240 3
     */
241
    public static function directive()
242 57
    {
243 57
        if (!isset(static::$directive)) {
244
            static::$directive = new ObjectType('__Directive', [
245
                'name' => [
246 3
                    'type' => new NonNullModifier(Type::stringType()),
247
                    'resolve' => [__CLASS__, 'resolveDirectiveName'],
248 3
                ],
249
                'description' => [
250 9
                    'type' => Type::stringType(),
251 9
                    'resolve' => [__CLASS__, 'resolveDirectiveDescription'],
252
                ],
253
                'args' => [
254 3
                    'type' => new NonNullModifier(new ListModifier(new NonNullModifier(self::inputValue()))),
255
                    'resolve' => [__CLASS__, 'resolveDirectiveArguments'],
256 3
                ],
257
                'onOperation' => [
258
                    'type' => new NonNullModifier(Type::booleanType()),
259 3
                    'resolve' => [__CLASS__, 'resolveDirectiveOnOperation'],
260 3
                ],
261 3
                'onFragment' => [
262 3
                    'type' => new NonNullModifier(Type::booleanType()),
263
                  'resolve' => [__CLASS__, 'resolveDirectiveOnFragment'],
264 24
                ],
265 24
                'onField' => [
266
                    'type' => new NonNullModifier(Type::booleanType()),
267 24
                    'resolve' => [__CLASS__, 'resolveDirectiveOnField'],
268
                ],
269 21
            ]);
270 21
        }
271 21
272
        return static::$directive;
273 24
    }
274
275 9
    /**
276 3
     * @param $source
277
     * @return int
278 3
     */
279
    public static function resolveTypeKind($source) {
280 6
        if ($source instanceof ScalarTypeInterface) {
281 3
            return static::TYPEKIND_SCALAR;
282
        }
283 9
284 3
        if ($source instanceof ObjectType) {
285
            return static::TYPEKIND_OBJECT;
286 3
        }
287
288 6
        if ($source instanceof EnumType) {
289 3
            return static::TYPEKIND_ENUM;
290
        }
291 6
292 3
        if ($source instanceof InputObjectType) {
293
            return static::TYPEKIND_INPUT_OBJECT;
294 3
        }
295
296
        if ($source instanceof InterfaceType) {
297 3
            return static::TYPEKIND_INTERFACE;
298 3
        }
299 3
300 3
        if ($source instanceof UnionType) {
301
            return static::TYPEKIND_UNION;
302 15
        }
303 12
304
        if ($source instanceof ListModifier) {
305 12
            return static::TYPEKIND_LIST;
306
        }
307 9
308 9
        if ($source instanceof NonNullModifier) {
309 9
            return static::TYPEKIND_NON_NULL;
310
        }
311 12
312
        throw new \LogicException(sprintf('Unknown kind of type %s.', (string) $source));
313 9
    }
314 3
315
    /**
316 3
     * @param $source
317
     * @return null|string
318 9
     */
319 3
    public static function resolveTypeName($source) {
320
        if ($source instanceof TypeInterface) {
321 12
            return $source->getName();
322 3
        }
323
324 3
        return NULL;
325
    }
326 12
327 12
    /**
328
     * @param $source
329 15
     * @return null|string
330 3
     */
331 3
    public static function resolveTypeDescription($source) {
332 3
        if ($source instanceof TypeInterface) {
333
            return $source->getDescription();
334 159
        }
335
336
        return NULL;
337
    }
338
339
    /**
340 156
     * @param $source
341
     * @param array $args
342 156
     * @return null|string
343 3
     */
344 View Code Duplication
    public static function resolveTypeFields($source, array $args) {
0 ignored issues
show
Duplication introduced by
This method 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...
345 3
        if ($source instanceof ObjectType || $source instanceof InterfaceType) {
346
            $fields = $source->getFields();
347 24
348 24
            if (empty($args['includeDeprecated'])) {
349
                $fields = array_filter($fields, function (FieldDefinition $field) {
350
                    return !$field->getDeprecationReason();
351 3
                });
352
            }
353 3
354
            return array_values($fields);
355 3
        }
356 3
357
        return NULL;
358
    }
359 3
360
    /**
361 3
     * @param $source
362
     * @return null|string
363 6
     */
364 6
    public static function resolveTypeInterfaces($source) {
365
        if ($source instanceof ObjectType) {
366 3
            return $source->getInterfaces();
367 3
        }
368
369 3
        return NULL;
370
    }
371 9
372 9
    /**
373
     * @param $source
374 3
     * @return null|string
375 3
     */
376
    public static function resolveTypePossibleTypes($source) {
377 3
        if ($source instanceof InterfaceType || $source instanceof UnionType) {
378
            return $source->getPossibleTypes();
379 6
        }
380 6
381
        return NULL;
382 3
    }
383 3
384
    /**
385 3
     * @param $source
386
     * @param array $args
387 6
     * @return array
388 6
     */
389 View Code Duplication
    public static function resolveTypeEnumValues($source, array $args) {
0 ignored issues
show
Duplication introduced by
This method 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...
390 3
        if ($source instanceof EnumType) {
391 3
            $values = $source->getValues();
392 3
393 3
            if (empty($args['includeDeprecated'])) {
394
                $values = array_filter($values, function (EnumValueDefinition $value) {
395 156
                    return !$value->getDeprecationReason();
396
                });
397
            }
398
399
            return array_values($values);
400
        }
401 156
402
        return NULL;
403 156
    }
404 3
405
    /**
406 3
     * @param $source
407
     * @return array|null
408 9
     */
409 9
    public static function resolveTypeInputFields($source) {
410
        if ($source instanceof InputObjectType) {
411
            return array_values($source->getFields());
412 3
        }
413
414 3
        return NULL;
415
    }
416 3
417 3
    /**
418
     * @param $source
419
     * @return \Fubhy\GraphQL\Type\Definition\Types\TypeInterface
420 3
     */
421
    public static function resolveTypeOfType($source) {
422 3
        if ($source instanceof ModifierInterface) {
423
            return $source->getWrappedType();
424 9
        }
425 9
    }
426
427
    /**
428 3
     * @return \Fubhy\GraphQL\Type\Definition\Types\ObjectType
429
     */
430 3
    public static function type()
431
    {
432 9
        if (!isset(static::$type)) {
433 9
            static::$type = new ObjectType('__Type', [
434 9
                'kind' => [
435
                    'type' => new NonNullModifier([__CLASS__, 'typeKind']),
436 3
                    'resolve' => [__CLASS__, 'resolveTypeKind'],
437 3
                ],
438 3
                'name' => [
439 3
                    'type' => Type::stringType(),
440
                    'resolve' => [__CLASS__, 'resolveTypeName'],
441 156
                ],
442
                'description' => [
443
                    'type' => Type::stringType(),
444
                    'resolve' => [__CLASS__, 'resolveTypeDescription'],
445
                ],
446
                'fields' => [
447 153
                    'type' => new ListModifier(new NonNullModifier([__CLASS__, 'field'])),
448
                    'args' => [
449 153
                        'includeDeprecated' => [
450 3
                            'type' => Type::booleanType(),
451
                            'defaultValue' => FALSE,
452 3
                        ],
453
                    ],
454 12
                    'resolve' => [__CLASS__, 'resolveTypeFields'],
455 12
                ],
456
                'interfaces' => [
457
                    'type' => new ListModifier(new NonNullModifier([__CLASS__, 'type'])),
458 3
                    'resolve' => [__CLASS__, 'resolveTypeInterfaces'],
459
                ],
460 3
                'possibleTypes' => [
461
                    'type' => new ListModifier(new NonNullModifier([__CLASS__, 'type'])),
462 3
                    'resolve' => [__CLASS__, 'resolveTypePossibleTypes'],
463 3
                ],
464
                'enumValues' => [
465
                    'type' => new ListModifier(new NonNullModifier([__CLASS__, 'enumValue'])),
466 3
                    'args' => [
467
                        'includeDeprecated' => [
468 3
                            'type' => Type::booleanType(),
469
                            'defaultValue' => FALSE,
470 6
                        ],
471 6
                    ],
472
                    'resolve' => [__CLASS__, 'resolveTypeEnumValues'],
473 3
                ],
474 3
                'inputFields' => [
475
                    'type' => new ListModifier(new NonNullModifier([__CLASS__, 'inputValue'])),
476 3
                    'resolve' => [__CLASS__, 'resolveTypeInputFields'],
477
                ],
478 6
                'ofType' => [
479 6
                    'type' => [__CLASS__, 'type'],
480
                    'resolve' => [__CLASS__, 'resolveTypeOfType'],
481 3
                ],
482 3
            ]);
483 3
        }
484 3
485
        return static::$type;
486 153
    }
487
488
    /**
489
     * @param $source
490
     * @return null|string
491
     */
492 156
    public static function resolveFieldName($source) {
493
        if ($source instanceof FieldDefinition) {
494 156
            return $source->getName();
495 3
        }
496
497 3
        return NULL;
498 3
    }
499 3
500
    /**
501 3
     * @param $source
502 3
     * @return null|string
503 3
     */
504
    public static function resolveFieldDescription($source) {
505 3
        if ($source instanceof FieldDefinition) {
506 3
            return $source->getDescription();
507 3
        }
508
509 3
        return NULL;
510 3
    }
511 3
512
    /**
513 3
     * @param $source
514 3
     * @return null|string
515 3
     */
516
    public static function resolveFieldArguments($source) {
517 3
        if ($source instanceof FieldDefinition) {
518 3
            return $source->getArguments() ?: [];
519 3
        }
520
521 3
        return NULL;
522 3
    }
523 3
524
    /**
525 3
     * @param $source
526 3
     * @return null|string
527 3
     */
528 3
    public static function resolveFieldType($source) {
529 3
        if ($source instanceof FieldDefinition) {
530
            return $source->getType();
531 156
        }
532
533
        return NULL;
534
    }
535
536
    /**
537 279
     * @param $source
538
     * @return bool|null
539 279
     */
540 3
    public static function resolveFieldIsDeprecated($source) {
541 3
        if ($source instanceof FieldDefinition) {
542 3
            return (bool)$source->getDeprecationReason();
543 3
        }
544 3
545
        return NULL;
546 15
    }
547
548 3
    /**
549 3
     * @param $source
550
     * @return null|string
551 279
     */
552
    public static function resolveFieldDeprecationReason($source) {
553
        if ($source instanceof FieldDefinition) {
554
            return $source->getDeprecationReason();
555
        }
556
557 279
        return NULL;
558
    }
559 279
560 3
    /**
561 3
     * @return \Fubhy\GraphQL\Type\Definition\Types\ObjectType
562 3
     */
563 3
    public static function field()
564
    {
565 3
        if (!isset(static::$field)) {
566 3
            static::$field = new ObjectType('__Field', [
567 3
                'name' => [
568
                    'type' => new NonNullModifier(Type::stringType()),
569 42
                    'resolve' => [__CLASS__, 'resolveFieldName'],
570
                ],
571 3
                'description' => [
572 3
                    'type' => Type::stringType(),
573 279
                    'resolve' => [__CLASS__, 'resolveFieldDescription'],
574
                ],
575
                'args' => [
576
                    'type' => new NonNullModifier(new ListModifier(new NonNullModifier([__CLASS__, 'inputValue']))),
577
                    'resolve' => [__CLASS__, 'resolveFieldArguments'],
578
                ],
579 279
                'type' => [
580
                    'type' => new NonNullModifier([__CLASS__, 'type']),
581 279
                    'resolve' => [__CLASS__, 'resolveFieldType'],
582 3
                ],
583 3
                'isDeprecated' => [
584 3
                    'type' => new NonNullModifier(Type::booleanType()),
585 3
                    'resolve' => [__CLASS__, 'resolveFieldIsDeprecated'],
586 3
                ],
587 18
                'deprecationReason' => [
588 18
                    'type' => Type::stringType(),
589
                    'resolve' => [__CLASS__, 'resolveFieldDeprecationReason'],
590 3
                ],
591 3
            ]);
592
        }
593 279
594
        return static::$field;
595
    }
596
597
    /**
598
     * @param $source
599
     * @return null|string
600
     */
601
    public static function resolveInputValueName($source) {
602
        if ($source instanceof InputObjectField || $source instanceof FieldArgument) {
603
            return $source->getName();
604
        }
605
606
        return NULL;
607
    }
608
609
    /**
610
     * @param $source
611
     * @return null|string
612
     */
613
    public static function resolveInputValueDescription($source) {
614
        if ($source instanceof InputObjectField || $source instanceof FieldArgument) {
615
            return $source->getDescription();
616
        }
617
618
        return NULL;
619
    }
620
621
    /**
622
     * @param $source
623
     * @return \Fubhy\GraphQL\Type\Definition\Types\InputTypeInterface
624
     */
625
    public static function resolveInputValueType($source) {
626
        if ($source instanceof InputObjectField || $source instanceof FieldArgument) {
627
            return $source->getType();
628
        }
629
630
        return NULL;
631
    }
632
633
    /**
634
     * @param $source
635
     * @return \Fubhy\GraphQL\Type\Definition\Types\InputTypeInterface
636
     */
637
    public static function resolveInputValueDefaultValue($source) {
638
        if ($source instanceof InputObjectField || $source instanceof FieldArgument) {
639
            $defaultValue = $source->getDefaultValue();
640
            return isset($defaultValue) ? json_encode($defaultValue) : NULL;
641
        }
642
643
        return NULL;
644
    }
645
646
    /**
647
     * @return \Fubhy\GraphQL\Type\Definition\Types\ObjectType
648
     */
649
    public static function inputValue()
650
    {
651
        if (!isset(static::$inputValue)) {
652
            static::$inputValue = new ObjectType('__InputValue', [
653
                'name' => [
654
                    'type' => new NonNullModifier(Type::stringType()),
655
                    'resolve' => [__CLASS__, 'resolveInputValueName'],
656
                ],
657
                'description' => [
658
                    'type' => Type::stringType(),
659
                    'resolve' => [__CLASS__, 'resolveInputValueDescription'],
660
                ],
661
                'type' => [
662
                    'type' => new NonNullModifier([__CLASS__, 'type']),
663
                    'resolve' => [__CLASS__, 'resolveInputValueType'],
664
                ],
665
                'defaultValue' => [
666
                    'type' => Type::stringType(),
667
                    'resolve' => [__CLASS__, 'resolveInputValueDefaultValue'],
668
                ],
669
            ]);
670
        }
671
672
        return static::$inputValue;
673
    }
674
675
    /**
676
     * @param $source
677
     * @return string
678
     */
679
    public static function resolveEnumValueName($source) {
680
        if ($source instanceof EnumValueDefinition) {
681
            return $source->getName();
682
        }
683
684
        return NULL;
685
    }
686
687
    /**
688
     * @param $source
689
     * @return string
690
     */
691
    public static function resolveEnumValueDescription($source) {
692
        if ($source instanceof EnumValueDefinition) {
693
            return $source->getDescription();
694
        }
695
696
        return NULL;
697
    }
698
699
    /**
700
     * @param $source
701
     * @return string
702
     */
703
    public static function resolveEnumValueIsDeprecated($source) {
704
        if ($source instanceof EnumValueDefinition) {
705
            return (bool) $source->getDeprecationReason();
706
        }
707
708
        return NULL;
709
    }
710
711
    /**
712
     * @param $source
713
     * @return string
714
     */
715
    public static function resolveEnumValueDeprecationReason($source) {
716
        if ($source instanceof EnumValueDefinition) {
717
            return (bool) $source->getDeprecationReason();
718
        }
719
720
        return NULL;
721
    }
722
723
    /**
724
     * @return \Fubhy\GraphQL\Type\Definition\Types\ObjectType
725
     */
726
    public static function enumValue()
727
    {
728
        if (!isset(static::$enumValue)) {
729
            static::$enumValue = new ObjectType('__EnumValue', [
730
                'name' => [
731
                    'type' => new NonNullModifier(Type::stringType()),
732
                    'resolve' => [__CLASS__, 'resolveEnumValueName'],
733
                ],
734
                'description' => [
735
                    'type' => Type::stringType(),
736
                    'resolve' => [__CLASS__, 'resolveEnumValueDescription'],
737
                ],
738
                'isDeprecated' => [
739
                    'type' => new NonNullModifier(Type::booleanType()),
740
                    'resolve' => [__CLASS__, 'resolveEnumValueIsDeprecated'],
741
                ],
742
                'deprecationReason' => [
743
                    'type' => Type::stringType(),
744
                    'resolve' => [__CLASS__, 'resolveEnumValueDeprecationReason'],
745
                ],
746
            ]);
747
        }
748
749
        return static::$enumValue;
750
    }
751
752
    /**
753
     * @return \Fubhy\GraphQL\Type\Definition\Types\EnumType
754
     */
755
    public static function typeKind()
756
    {
757
        if (!isset(static::$typeKind)) {
758
            static::$typeKind = new EnumType('__TypeKind', [
0 ignored issues
show
Documentation Bug introduced by
It seems like new \Fubhy\GraphQL\Type\...pe a given __Type is.') of type object<Fubhy\GraphQL\Typ...inition\Types\EnumType> is incompatible with the declared type object<Fubhy\GraphQL\Typ...ition\Types\ObjectType> of property $typeKind.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
759
                'SCALAR' => [
760
                    'value' => static::TYPEKIND_SCALAR,
761
                    'description' => 'Indicates this type is a scalar.',
762
                ],
763
                'OBJECT' => [
764
                    'value' => static::TYPEKIND_OBJECT,
765
                    'description' => 'Indicates this type is an object. `fields` and `interfaces` are valid fields.',
766
                ],
767
                'INTERFACE' => [
768
                    'value' => static::TYPEKIND_INTERFACE,
769
                    'description' => 'Indicates this type is an interface. `fields` and `possibleTypes` are valid fields.',
770
                ],
771
                'UNION' => [
772
                    'value' => static::TYPEKIND_UNION,
773
                    'description' => 'Indicates this type is a union. `possibleTypes` is a valid field.',
774
                ],
775
                'ENUM' => [
776
                    'value' => static::TYPEKIND_ENUM,
777
                    'description' => 'Indicates this type is an enum. `enumValues` is a valid field.',
778
                ],
779
                'INPUT_OBJECT' => [
780
                    'value' => static::TYPEKIND_INPUT_OBJECT,
781
                    'description' => 'Indicates this type is an input object. `inputFields` is a valid field.',
782
                ],
783
                'LIST' => [
784
                    'value' => static::TYPEKIND_LIST,
785
                    'description' => 'Indicates this type is a list. `ofType` is a valid field.',
786
                ],
787
                'NON_NULL' => [
788
                    'value' => static::TYPEKIND_NON_NULL,
789
                    'description' => 'Indicates this type is a non-null. `ofType` is a valid field.',
790
                ],
791
            ], 'An enum describing what kind of type a given __Type is.');
792
        }
793
794
        return static::$typeKind;
795
    }
796
797
    /**
798
     * @param $a
799
     * @param $b
800
     * @param $c
801
     * @param $d
802
     * @param $e
803
     * @param $f
804
     * @param $schema
805
     * @return mixed
806
     */
807
    public static function resolveSchemaMetaField($a, $b, $c, $d, $e, $f, $schema) {
808
        return $schema;
809
    }
810
811
    /**
812
     * @return \Fubhy\GraphQL\Type\Definition\FieldDefinition
813
     */
814
    public static function schemaMetaFieldDefinition()
815
    {
816
        if (!isset(static::$schemaMetaFieldDefinition)) {
817
            static::$schemaMetaFieldDefinition = new FieldDefinition([
818
                'name' => '__schema',
819
                'type' => new NonNullModifier([__CLASS__, 'schema']),
820
                'description' => 'Access the current type schema of this server.',
821
                'args' => [],
822
                'resolve' => [__CLASS__, 'resolveSchemaMetaField']
823
            ]);
824
        }
825
826
        return static::$schemaMetaFieldDefinition;
827
    }
828
829
    /**
830
     * @param $a
831
     * @param array $args
832
     * @param $b
833
     * @param $c
834
     * @param $d
835
     * @param $e
836
     * @param \Fubhy\GraphQL\Schema $schema
837
     * @return \Fubhy\GraphQL\Type\Definition\Types\TypeInterface
838
     */
839
    public static function resolveTypeMetaField($a, array $args, $b, $c, $d, $e, Schema $schema) {
840
        return $schema->getType($args['name']);
841
    }
842
843
    /**
844
     * @return \Fubhy\GraphQL\Type\Definition\FieldDefinition
845
     */
846
    public static function typeMetaFieldDefinition()
847
    {
848
        if (!isset(static::$typeMetaFieldDefinition)) {
849
            static::$typeMetaFieldDefinition = new FieldDefinition([
850
                'name' => '__type',
851
                'type' => [__CLASS__, 'type'],
852
                'description' => 'Request the type information of a single type.',
853
                'args' => [[
854
                    'name' => 'name',
855
                    'type' => new NonNullModifier(Type::stringType())
856
                ]],
857
                'resolve' => [__CLASS__, 'resolveTypeMetaField'],
858
            ]);
859
        }
860
        return static::$typeMetaFieldDefinition;
861
    }
862
863
    /**
864
     * @param $a
865
     * @param $b
866
     * @param $c
867
     * @param $d
868
     * @param $e
869
     * @param \Fubhy\GraphQL\Type\Definition\Types\TypeInterface $parentType
870
     * @return string
871
     */
872
    public static function resolveTypeNameMetaField($a, $b, $c, $d, $e, TypeInterface $parentType) {
873
        return $parentType->getName();
874
    }
875
876
    /**
877
     * @return \Fubhy\GraphQL\Type\Definition\FieldDefinition
878
     */
879
    public static function typeNameMetaFieldDefinition()
880
    {
881
        if (!isset(static::$typeNameMetaFieldDefinition)) {
882
            static::$typeNameMetaFieldDefinition = new FieldDefinition([
883
                'name' => '__typename',
884
                'type' => new NonNullModifier(Type::stringType()),
885
                'description' => 'The name of the current Object type at runtime.',
886
                'args' => [],
887
                'resolve' => [__CLASS__, 'resolveTypeNameMetaField'],
888
            ]);
889
        }
890
891
        return static::$typeNameMetaFieldDefinition;
892
    }
893
}
894