Passed
Pull Request — master (#21)
by Christoffer
02:08
created

GraphQLSkipDirective()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
3
use Digia\GraphQL\GraphQLRuntime;
4
use Digia\GraphQL\Type\Definition\Directive;
5
use Digia\GraphQL\Type\Definition\DirectiveInterface;
6
use function Digia\GraphQL\Util\arraySome;
7
8
/**
9
 * @return Directive
10
 * @throws TypeError
11
 */
12
function GraphQLIncludeDirective(): Directive
13
{
14
    return GraphQLRuntime::make('GraphQLIncludeDirective');
15
}
16
17
/**
18
 * @return Directive
19
 * @throws TypeError
20
 */
21
function GraphQLSkipDirective(): Directive
22
{
23
    return GraphQLRuntime::make('GraphQLSkipDirective');
24
}
25
26
const DEFAULT_DEPRECATION_REASON = 'No longer supported';
27
28
/**
29
 * @return Directive
30
 * @throws TypeError
31
 */
32
function GraphQLDeprecatedDirective(): Directive
33
{
34
    return GraphQLRuntime::make('GraphQLDeprecatedDirective');
35
}
36
37
/**
38
 * @return array
39
 * @throws TypeError
40
 */
41
function specifiedDirectives(): array
42
{
43
    return [
44
        GraphQLIncludeDirective(),
45
        GraphQLSkipDirective(),
46
        GraphQLDeprecatedDirective(),
47
    ];
48
}
49
50
/**
51
 * @param DirectiveInterface $directive
52
 * @return bool
53
 * @throws ReflectionException
54
 * @throws TypeError
55
 */
56
function isSpecifiedDirective(DirectiveInterface $directive): bool
57
{
58
    return arraySome(
59
        specifiedDirectives(),
60
        function (DirectiveInterface $specifiedDirective) use ($directive) {
61
            return $specifiedDirective->getName() === $directive->getName();
62
        }
63
    );
64
}
65