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

Passed
Pull Request — master (#682)
by
unknown
24:37
created

TypeDefinition::deprecationReasonSection()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 3
dl 0
loc 7
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 1
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
     * @param int $level
58
     *
59
     * @return ArrayNodeDefinition|NodeDefinition
60
     */
61
    protected function validationSection(int $level): NodeParentInterface
62
    {
63
        $node = self::createNode('validation', 'array');
64
65 47
        $node
66
            // allow shorthands
67 47
            ->beforeNormalization()
68
                ->always(function ($value) {
69
                    if (\is_string($value)) {
70
                        // shorthand: cascade or link
71 47
                        return 'cascade' === $value ? ['cascade' => null] : ['link' => $value];
72
                    }
73 3
74
                    if (\is_array($value)) {
75 2
                        foreach ($value as $k => $a) {
76
                            if (!\is_int($k)) {
77
                                // validation: { link: ... , constraints: ..., cascade: ... }
78 2
                                return $value;
79 2
                            }
80 2
                        }
81
                        // validation: [list of constraints]
82 1
                        return ['constraints' => $value];
83
                    }
84
85
                    return [];
86 2
                })
87
            ->end()
88
            ->children()
89 1
                ->scalarNode('link')
90 47
//                    ->defaultNull()
91 47
                    ->validate()
92 47
                        ->ifTrue(function ($link) use ($level) {
93 47
                            if (self::VALIDATION_LEVEL_PROPERTY === $level) {
94 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);
95 47
                            } else {
96
                                return !\preg_match('/^(?:\\\\?[A-Za-z][A-Za-z\d]+)*[A-Za-z\d]$/m', $link);
97 1
                            }
98 1
                        })
99
                        ->thenInvalid('Invalid link provided: "%s".')
100 1
                    ->end()
101
                ->end()
102 47
                ->variableNode('constraints')->end()
103 47
            ->end();
104 47
105 47
        // Add the 'cascade' option if it's a property level validation section
106
        if (self::VALIDATION_LEVEL_PROPERTY === $level) {
107 47
            $node
108 47
                ->children()
109 47
                    ->arrayNode('cascade')
110 47
                        ->children()
111
                            ->arrayNode('groups')
112
                                ->beforeNormalization()
113 47
                                    ->castToArray()
114
                                ->end()
115 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

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