Passed
Push — master ( 2772d3...ae4d04 )
by Bruno
03:33
created

HiddenDirective::definition()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 6
c 1
b 0
f 1
nc 1
nop 0
dl 0
loc 3
ccs 1
cts 1
cp 1
crap 1
rs 10
1
<?php
2
3
namespace Modelarium\Laravel\Lighthouse\Directives;
4
5
use GraphQL\Language\AST\FieldDefinitionNode;
6
use GraphQL\Language\AST\InputValueDefinitionNode;
7
use GraphQL\Language\AST\NodeList;
8
use GraphQL\Language\AST\ObjectTypeDefinitionNode;
9
use GraphQL\Language\Parser;
10
use Nuwave\Lighthouse\Schema\AST\DocumentAST;
11
use Nuwave\Lighthouse\Schema\Directives\BaseDirective;
12
use Nuwave\Lighthouse\Support\Contracts\FieldManipulator;
13
use Nuwave\Lighthouse\Support\Contracts\r;
0 ignored issues
show
Bug introduced by
The type Nuwave\Lighthouse\Support\Contracts\r was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
14
15
class HiddenDirective extends BaseDirective implements FieldManipulator
16
{
17 8
    public static function definition(): string
18
    {
19
        return /** @lang GraphQL */ <<<'GRAPHQL'
20 8
"""
21
Make this field hidden. It will not show up on introspection or queries.
22
"""
23
directive @hidden on ARGUMENT_DEFINITION
24
GRAPHQL;
25
    }
26
27
    /**
28
     * Manipulate the AST based on a field definition.
29
     *
30
     * @return void
31
     */
32
    public function manipulateFieldDefinition(
33
        DocumentAST &$documentAST,
34
        FieldDefinitionNode &$fieldDefinition,
35
        ObjectTypeDefinitionNode &$parentType
36
    ) {
37
        $fieldName = $fieldDefinition->name->value;
38
        /**
39
         * @var NodeList $fields
40
         */
41
        $fields = $parentType->fields;
42
        foreach ($fields as $k => $f) {
43
            if ($f->name->value === $fieldName) {
44
                unset($fields[$k]);
45
            }
46
        }
47
    }
48
}
49