Scrutinizer GitHub App not installed

We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.

Install GitHub App

Completed
Pull Request — master (#682)
by
unknown
22:36 queued 54s
created

TypeDefinition::typeSection()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 5
dl 0
loc 11
ccs 5
cts 5
cp 1
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 1
crap 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Overblog\GraphQLBundle\Config;
6
7
use Overblog\GraphQLBundle\DependencyInjection\Configuration;
8
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
9
use Symfony\Component\Config\Definition\Builder\NodeDefinition;
10
use Symfony\Component\Config\Definition\Builder\NodeParentInterface;
11
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
12
13
abstract class TypeDefinition
14
{
15
    public const VALIDATION_LEVEL_CLASS = 0;
16
    public const VALIDATION_LEVEL_PROPERTY = 1;
17
18
    abstract public function getDefinition();
19
20 47
    protected function __construct()
21
    {
22 47
    }
23
24
    /**
25
     * @return static
26
     */
27 47
    public static function create()
28
    {
29 47
        return new static();
30
    }
31
32 47
    protected function resolveTypeSection()
33
    {
34 47
        $node = self::createNode('resolveType', 'variable');
35
36 47
        return $node;
37
    }
38
39 47
    protected function nameSection()
40
    {
41 47
        $node = self::createNode('name', 'scalar');
42 47
        $node->isRequired();
43 47
        $node->validate()
44
            ->ifTrue(fn ($name) => !\preg_match('/^[_a-z][_0-9a-z]*$/i', $name))
45 38
            ->thenInvalid('Invalid type name "%s". (see http://spec.graphql.org/June2018/#sec-Names)')
46 47
        ->end();
47 47
48 47
        return $node;
49
    }
50 47
51
    protected function defaultValueSection()
52
    {
53 47
        return self::createNode('defaultValue', 'variable');
54
    }
55 47
56
    /**
57 47
     * @return ArrayNodeDefinition|NodeDefinition
58
     */
59
    protected function validationSection(int $level): NodeParentInterface
60
    {
61
        $node = self::createNode('validation', 'array');
62
63 47
        $node
64
            // allow shorthands
65 47
            ->beforeNormalization()
66
                ->always(function ($value) {
67
                    if (\is_string($value)) {
68
                        // shorthand: cascade or link
69 47
                        return 'cascade' === $value ? ['cascade' => null] : ['link' => $value];
70
                    }
71 3
72
                    if (\is_array($value)) {
73 2
                        foreach ($value as $k => $a) {
74
                            if (!\is_int($k)) {
75
                                // validation: { link: ... , constraints: ..., cascade: ... }
76 2
                                return $value;
77 2
                            }
78 2
                        }
79
                        // validation: [list of constraints]
80 1
                        return ['constraints' => $value];
81
                    }
82
83
                    return [];
84 2
                })
85
            ->end()
86
            ->children()
87 1
                ->scalarNode('link')
88 47
//                    ->defaultNull()
89 47
                    ->validate()
90 47
                        ->ifTrue(function ($link) use ($level) {
91 47
                            if (self::VALIDATION_LEVEL_PROPERTY === $level) {
92 47
                                return !\preg_match('/^(?:\\\\?[A-Za-z][A-Za-z\d]+)*[A-Za-z\d]+::(?:[$]?[A-Za-z][A-Za-z_\d]+|[A-Za-z_\d]+\(\))$/m', $link);
93 47
                            } else {
94
                                return !\preg_match('/^(?:\\\\?[A-Za-z][A-Za-z\d]+)*[A-Za-z\d]$/m', $link);
95 1
                            }
96 1
                        })
97
                        ->thenInvalid('Invalid link provided: "%s".')
98 1
                    ->end()
99
                ->end()
100 47
                ->variableNode('constraints')->end()
101 47
            ->end();
102 47
103 47
        // Add the 'cascade' option if it's a property level validation section
104
        if (self::VALIDATION_LEVEL_PROPERTY === $level) {
105 47
            $node
106 47
                ->children()
107 47
                    ->arrayNode('cascade')
108 47
                        ->children()
109
                            ->arrayNode('groups')
110
                                ->beforeNormalization()
111 47
                                    ->castToArray()
112
                                ->end()
113 47
                                ->scalarPrototype()->end()
0 ignored issues
show
Bug introduced by
The method scalarPrototype() does not exist on Symfony\Component\Config...\Builder\NodeDefinition. It seems like you code against a sub-type of Symfony\Component\Config...\Builder\NodeDefinition such as Symfony\Component\Config...der\ArrayNodeDefinition. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

113
                                ->/** @scrutinizer ignore-call */ scalarPrototype()->end()
Loading history...
114 47
                            ->end()
115 47
                        ->end()
116 47
                    ->end()
117 47
                ->end();
118 47
        }
119 47
120 47
        return $node;
121 47
    }
122 47
123 47
    protected function descriptionSection()
124 47
    {
125
        $node = self::createNode('description', 'scalar');
126
127 47
        return $node;
128
    }
129
130 47
    protected function deprecationReasonSection()
131
    {
132 47
        $node = self::createNode('deprecationReason', 'scalar');
133
134 47
        $node->info('Text describing why this field is deprecated. When not empty - field will not be returned by introspection queries (unless forced)');
135
136
        return $node;
137 47
    }
138
139 47
    protected function typeSection($isRequired = false)
140
    {
141 47
        $node = self::createNode('type', 'scalar');
142
143 47
        $node->info('One of internal or custom types.');
144
145
        if ($isRequired) {
146 47
            $node->isRequired();
147
        }
148 47
149
        return $node;
150 47
    }
151
152 47
    /**
153 47
     * @return ArrayNodeDefinition|NodeDefinition
154
     *
155
     * @internal
156 47
     */
157
    protected static function createNode(string $name, string $type = 'array')
158
    {
159
        return Configuration::getRootNodeWithoutDeprecation(new TreeBuilder($name, $type), $name, $type);
160
    }
161
}
162