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 (#638)
by Vincent
21:48
created

Configuration::definitionsSection()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 32
Code Lines 27

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 27
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 27
c 1
b 0
f 0
dl 0
loc 32
rs 9.488
ccs 27
cts 27
cp 1
cc 1
nc 1
nop 0
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Overblog\GraphQLBundle\DependencyInjection;
6
7
use GraphQL\Executor\Promise\Adapter\SyncPromiseAdapter;
8
use GraphQL\Validator\Rules\QueryComplexity;
9
use GraphQL\Validator\Rules\QueryDepth;
10
use Overblog\GraphQLBundle\Definition\Argument;
11
use Overblog\GraphQLBundle\DependencyInjection\Compiler\ConfigParserPass;
12
use Overblog\GraphQLBundle\Error\ErrorHandler;
13
use Overblog\GraphQLBundle\EventListener\ErrorLoggerListener;
14
use Overblog\GraphQLBundle\Executor\Executor;
15
use Overblog\GraphQLBundle\ExpressionLanguage\ExpressionLanguage;
16
use Overblog\GraphQLBundle\Resolver\FieldResolver;
17
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
18
use Symfony\Component\Config\Definition\Builder\EnumNodeDefinition;
19
use Symfony\Component\Config\Definition\Builder\ScalarNodeDefinition;
20
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
21
use Symfony\Component\Config\Definition\ConfigurationInterface;
22
23
class Configuration implements ConfigurationInterface
24
{
25
    public const NAME = 'overblog_graphql';
26
27
    /** bool */
28
    private $debug;
29
30
    /** null|string */
31
    private $cacheDir;
32
33
    /**
34
     * Constructor.
35
     *
36
     * @param bool $debug Whether to use the debug mode
37
     */
38
    public function __construct(bool $debug, string $cacheDir = null)
39 42
    {
40
        $this->debug = (bool) $debug;
41 42
        $this->cacheDir = $cacheDir;
42 42
    }
43 42
44
    public function getConfigTreeBuilder()
45 42
    {
46
        $treeBuilder = new TreeBuilder(self::NAME);
47 42
48
        $rootNode = self::getRootNodeWithoutDeprecation($treeBuilder, self::NAME);
49 42
50
        $rootNode
51
            ->children()
52 42
                ->append($this->batchingMethodSection())
53 42
                ->append($this->definitionsSection())
54 42
                ->append($this->errorsHandlerSection())
55 42
                ->append($this->servicesSection())
56 42
                ->append($this->securitySection())
57 42
                ->append($this->doctrineSection())
58 42
                ->append($this->profilerSection())
59 42
            ->end();
60
61 42
        return $treeBuilder;
62
    }
63
64 42
    private function batchingMethodSection()
65
    {
66 42
        $builder = new TreeBuilder('batching_method', 'enum');
67
        /** @var EnumNodeDefinition $node */
68 42
        $node = self::getRootNodeWithoutDeprecation($builder, 'batching_method', 'enum');
69
70
        $node
71 42
            ->values(['relay', 'apollo'])
72 42
            ->defaultValue('relay')
73 42
        ->end();
74
75 42
        return $node;
76
    }
77
78 42
    private function errorsHandlerSection()
79
    {
80 42
        $builder = new TreeBuilder('errors_handler');
81
        /** @var ArrayNodeDefinition $node */
82 42
        $node = self::getRootNodeWithoutDeprecation($builder, 'errors_handler');
83
        $node
84 42
            ->treatFalseLike(['enabled' => false])
85 42
            ->treatTrueLike(['enabled' => true])
86 42
            ->treatNullLike(['enabled' => true])
87 42
            ->addDefaultsIfNotSet()
88 42
            ->children()
89 42
                ->booleanNode('enabled')->defaultTrue()->end()
90 42
                ->scalarNode('internal_error_message')->defaultValue(ErrorHandler::DEFAULT_ERROR_MESSAGE)->end()
0 ignored issues
show
Bug introduced by
The method scalarNode() does not exist on Symfony\Component\Config...der\NodeParentInterface. It seems like you code against a sub-type of Symfony\Component\Config...der\NodeParentInterface such as Symfony\Component\Config...ion\Builder\NodeBuilder. ( Ignorable by Annotation )

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

90
                ->/** @scrutinizer ignore-call */ scalarNode('internal_error_message')->defaultValue(ErrorHandler::DEFAULT_ERROR_MESSAGE)->end()
Loading history...
91 42
                ->booleanNode('rethrow_internal_exceptions')->defaultFalse()->end()
92 42
                ->booleanNode('debug')->defaultValue($this->debug)->end()
93 42
                ->booleanNode('log')->defaultTrue()->end()
94 42
                ->scalarNode('logger_service')->defaultValue(ErrorLoggerListener::DEFAULT_LOGGER_SERVICE)->end()
95 42
                ->booleanNode('map_exceptions_to_parent')->defaultFalse()->end()
96 42
                ->arrayNode('exceptions')
97 42
                    ->addDefaultsIfNotSet()
98 42
                    ->children()
99 42
                        ->arrayNode('warnings')
100 42
                            ->treatNullLike([])
101 42
                            ->prototype('scalar')->end()
102 42
                        ->end()
103 42
                        ->arrayNode('errors')
104 42
                            ->treatNullLike([])
105 42
                            ->prototype('scalar')->end()
106 42
                    ->end()
107 42
                ->end()
108 42
            ->end();
109
110 42
        return $node;
111
    }
112
113 42
    private function definitionsSection()
114
    {
115 42
        $builder = new TreeBuilder('definitions');
116
        /** @var ArrayNodeDefinition $node */
117 42
        $node = self::getRootNodeWithoutDeprecation($builder, 'definitions');
118
        $node
119 42
            ->addDefaultsIfNotSet()
120 42
            ->children()
121 42
                ->scalarNode('argument_class')->defaultValue(Argument::class)->end()
122 42
                ->scalarNode('use_experimental_executor')->defaultFalse()->end()
123 42
                ->scalarNode('default_field_resolver')->defaultValue(FieldResolver::class)->end()
124 42
                ->scalarNode('class_namespace')->defaultValue('Overblog\\GraphQLBundle\\__DEFINITIONS__')->end()
125 42
                ->scalarNode('cache_dir')->defaultNull()->end()
126 42
                ->scalarNode('cache_dir_permissions')->defaultNull()->end()
127 42
                ->booleanNode('use_classloader_listener')->defaultTrue()->end()
128 42
                ->scalarNode('auto_compile')->defaultTrue()->end()
129 42
                ->booleanNode('show_debug_info')->info('Show some performance stats in extensions')->defaultFalse()->end()
130 42
                ->booleanNode('config_validation')->defaultValue($this->debug)->end()
131 42
                ->append($this->definitionsSchemaSection())
132 42
                ->append($this->definitionsMappingsSection())
133 42
                ->arrayNode('builders')
134 42
                    ->children()
135 42
                        ->append($this->builderSection('field'))
136 42
                        ->append($this->builderSection('fields'))
137 42
                        ->append($this->builderSection('args'))
138 42
                    ->end()
139 42
                ->end()
140
141 42
            ->end()
142 42
        ->end();
143
144 42
        return $node;
145
    }
146
147 42
    private function servicesSection()
148
    {
149 42
        $builder = new TreeBuilder('services');
150
        /** @var ArrayNodeDefinition $node */
151 42
        $node = self::getRootNodeWithoutDeprecation($builder, 'services');
152
        $node
153 42
            ->addDefaultsIfNotSet()
154 42
            ->children()
155 42
                ->scalarNode('executor')
156 42
                    ->defaultValue(Executor::class)
157 42
                ->end()
158 42
                ->scalarNode('promise_adapter')
159 42
                    ->defaultValue(SyncPromiseAdapter::class)
160 42
                ->end()
161 42
                ->scalarNode('expression_language')
162 42
                    ->defaultValue(ExpressionLanguage::class)
163 42
                ->end()
164 42
                ->scalarNode('cache_expression_language_parser')->end()
165 42
            ->end()
166 42
        ->end();
167
168 42
        return $node;
169
    }
170
171 42
    private function securitySection()
172
    {
173 42
        $builder = new TreeBuilder('security');
174
        /** @var ArrayNodeDefinition $node */
175 42
        $node = self::getRootNodeWithoutDeprecation($builder, 'security');
176
        $node
177 42
            ->addDefaultsIfNotSet()
178 42
            ->children()
179 42
                ->append($this->securityQuerySection('query_max_depth', QueryDepth::DISABLED))
0 ignored issues
show
Bug introduced by
GraphQL\Validator\Rules\QueryDepth::DISABLED of type integer is incompatible with the type boolean expected by parameter $disabledValue of Overblog\GraphQLBundle\D...:securityQuerySection(). ( Ignorable by Annotation )

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

179
                ->append($this->securityQuerySection('query_max_depth', /** @scrutinizer ignore-type */ QueryDepth::DISABLED))
Loading history...
180 42
                ->append($this->securityQuerySection('query_max_complexity', QueryComplexity::DISABLED))
181 42
                ->booleanNode('enable_introspection')->defaultTrue()->end()
182 42
                ->booleanNode('handle_cors')->defaultFalse()->end()
0 ignored issues
show
Bug introduced by
The method booleanNode() does not exist on Symfony\Component\Config...der\NodeParentInterface. It seems like you code against a sub-type of Symfony\Component\Config...der\NodeParentInterface such as Symfony\Component\Config...ion\Builder\NodeBuilder. ( Ignorable by Annotation )

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

182
                ->/** @scrutinizer ignore-call */ booleanNode('handle_cors')->defaultFalse()->end()
Loading history...
183 42
            ->end()
184 42
        ->end();
185
186 42
        return $node;
187
    }
188
189 42
    private function definitionsSchemaSection()
190
    {
191 42
        $builder = new TreeBuilder('schema');
192
        /** @var ArrayNodeDefinition $node */
193 42
        $node = self::getRootNodeWithoutDeprecation($builder, 'schema');
194
        $node
195 42
            ->beforeNormalization()
196
                ->ifTrue(function ($v) {
197 34
                    return isset($v['query']) && \is_string($v['query']) || isset($v['mutation']) && \is_string($v['mutation']);
198 42
                })
199
                ->then(function ($v) {
200 32
                    return ['default' => $v];
201 42
                })
202 42
            ->end()
203 42
            ->useAttributeAsKey('name')
0 ignored issues
show
Bug introduced by
The method useAttributeAsKey() 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

203
            ->/** @scrutinizer ignore-call */ useAttributeAsKey('name')
Loading history...
204 42
            ->prototype('array')
205 42
                ->addDefaultsIfNotSet()
206 42
                ->children()
207 42
                    ->scalarNode('query')->defaultNull()->end()
208 42
                    ->scalarNode('mutation')->defaultNull()->end()
209 42
                    ->scalarNode('subscription')->defaultNull()->end()
210 42
                    ->arrayNode('resolver_maps')
211 42
                        ->defaultValue([])
212 42
                        ->prototype('scalar')->end()
213 42
                        ->setDeprecated('The "%path%.%node%" configuration is deprecated since version 0.13 and will be removed in 0.14. Add the "overblog_graphql.resolver_map" tag to the services instead.', '0.13')
214 42
                    ->end()
215 42
                    ->arrayNode('types')
216 42
                        ->defaultValue([])
217 42
                        ->prototype('scalar')->end()
218 42
                    ->end()
219 42
                ->end()
220 42
            ->end()
221 42
        ->end();
222
223 42
        return $node;
224
    }
225
226 42
    private function definitionsMappingsSection()
227
    {
228 42
        $builder = new TreeBuilder('mappings');
229 42
        $node = self::getRootNodeWithoutDeprecation($builder, 'mappings');
230
        $node
231 42
            ->children()
232 42
                ->arrayNode('auto_discover')
233 42
                    ->treatFalseLike(['bundles' => false, 'root_dir' => false])
234 42
                    ->treatTrueLike(['bundles' => true, 'root_dir' => true])
235 42
                    ->treatNullLike(['bundles' => true, 'root_dir' => true])
236 42
                    ->addDefaultsIfNotSet()
237 42
                    ->children()
238 42
                        ->booleanNode('bundles')->defaultFalse()->end()
239 42
                        ->booleanNode('root_dir')->defaultFalse()->end()
240 42
                    ->end()
241 42
                ->end()
242 42
                ->arrayNode('types')
243 42
                    ->prototype('array')
244 42
                        ->addDefaultsIfNotSet()
245 42
                        ->beforeNormalization()
246
                            ->ifTrue(function ($v) {
247 33
                                return isset($v['type']) && \is_string($v['type']);
248 42
                            })
249
                            ->then(function ($v) {
250 32
                                if ('yml' === $v['type']) {
251 7
                                    $v['types'] = ['yaml'];
252
                                } else {
253 25
                                    $v['types'] = [$v['type']];
254
                                }
255 32
                                unset($v['type']);
256
257 32
                                return $v;
258 42
                            })
259 42
                        ->end()
260 42
                        ->children()
261 42
                            ->arrayNode('types')
262 42
                                ->prototype('enum')->values(\array_keys(ConfigParserPass::SUPPORTED_TYPES_EXTENSIONS))->isRequired()->end()
263 42
                            ->end()
264 42
                            ->scalarNode('dir')->defaultNull()->end()
265 42
                            ->scalarNode('suffix')->defaultValue(ConfigParserPass::DEFAULT_TYPES_SUFFIX)->end()
266 42
                        ->end()
267 42
                    ->end()
268 42
                ->end()
269 42
            ->end()
270
        ;
271
272 42
        return $node;
273
    }
274
275 42
    private function doctrineSection()
276
    {
277 42
        $builder = new TreeBuilder('doctrine');
278
        /** @var ArrayNodeDefinition $node */
279 42
        $node = self::getRootNodeWithoutDeprecation($builder, 'doctrine');
280
        $node
281 42
            ->addDefaultsIfNotSet()
282 42
            ->children()
283 42
                ->arrayNode('types_mapping')
284 42
                    ->defaultValue([])
285 42
                    ->prototype('scalar')->end()
286 42
                ->end()
0 ignored issues
show
Bug introduced by
The method end() does not exist on Symfony\Component\Config...der\NodeParentInterface. It seems like you code against a sub-type of said class. However, the method does not exist in Symfony\Component\Config...ion\Builder\TreeBuilder. Are you sure you never get one of those? ( Ignorable by Annotation )

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

286
                ->/** @scrutinizer ignore-call */ end()
Loading history...
287 42
            ->end()
288
        ;
289
290 42
        return $node;
291
    }
292
293
    private function profilerSection()
294
    {
295
        $builder = new TreeBuilder('profiler');
296
        /** @var ArrayNodeDefinition $node */
297
        $node = self::getRootNodeWithoutDeprecation($builder, 'profiler');
298 42
        $node
299
            ->addDefaultsIfNotSet()
300 42
            ->children()
301
                ->scalarNode('query_match')->defaultNull()->end()
302 42
            ->end()
303 42
        ;
304
305 5
        return $node;
306 42
    }
307
308 5
    /**
309 5
     * @param string $name
310
     *
311 5
     * @return ArrayNodeDefinition
312 5
     */
313
    private function builderSection($name)
314
    {
315
        $builder = new TreeBuilder($name);
316
        /** @var ArrayNodeDefinition $node */
317 5
        $node = self::getRootNodeWithoutDeprecation($builder, $name);
318 42
        $node->beforeNormalization()
319 42
            ->ifTrue(function ($v) {
320
                return \is_array($v) && !empty($v);
321 42
            })
322 42
            ->then(function ($v) {
323 42
                foreach ($v as $key => &$config) {
324 42
                    if (\is_string($config)) {
325 42
                        $config = [
326 42
                            'alias' => $key,
327
                            'class' => $config,
328
                        ];
329 42
                    }
330
                }
331
332
                return $v;
333
            })
334
        ->end();
335
336
        $node->prototype('array')
337
            ->children()
338 42
                ->scalarNode('alias')->isRequired()->end()
339
                ->scalarNode('class')->isRequired()->end()
340 42
            ->end()
341
        ->end()
342 42
        ;
343 42
344
        return $node;
345 36
    }
346 42
347
    /**
348 2
     * @param string $name
349 42
     * @param bool   $disabledValue
350 42
     *
351
     * @return ScalarNodeDefinition
352
     */
353 42
    private function securityQuerySection($name, $disabledValue)
354 42
    {
355
        $builder = new TreeBuilder($name, 'scalar');
356 36
        /** @var ScalarNodeDefinition $node */
357 42
        $node = self::getRootNodeWithoutDeprecation($builder, $name, 'scalar');
358
        $node->beforeNormalization()
359 36
                ->ifTrue(function ($v) {
360 42
                    return \is_string($v) && \is_numeric($v);
361 42
                })
362 42
                ->then(function ($v) {
363 42
                    return (int) $v;
364
                })
365 36
            ->end();
366 42
367 42
        $node
368 42
            ->info('Disabled if equal to false.')
369
            ->beforeNormalization()
370
                ->ifTrue(function ($v) {
371 42
                    return false === $v;
372
                })
373
                ->then(function () use ($disabledValue) {
374
                    return $disabledValue;
375
                })
376
            ->end()
377
            ->defaultValue($disabledValue)
378
            ->validate()
379
                ->ifTrue(function ($v) {
380
                    return \is_int($v) && $v < 0;
381
                })
382
                ->thenInvalid(\sprintf('"%s.security.%s" must be greater or equal to 0.', self::NAME, $name))
383 48
            ->end()
384
        ;
385
386 48
        return $node;
387
    }
388
389
    /**
390
     * @internal
391
     *
392
     * @param string|null $name
393
     *
394
     * @return ArrayNodeDefinition|\Symfony\Component\Config\Definition\Builder\NodeDefinition
395
     */
396
    public static function getRootNodeWithoutDeprecation(TreeBuilder $builder, string $name, string $type = 'array')
397
    {
398
        // BC layer for symfony/config 4.1 and older
399
        return \method_exists($builder, 'getRootNode') ? $builder->getRootNode() : $builder->root($name, $type);
0 ignored issues
show
Bug introduced by
The method root() does not exist on Symfony\Component\Config...ion\Builder\TreeBuilder. ( Ignorable by Annotation )

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

399
        return \method_exists($builder, 'getRootNode') ? $builder->getRootNode() : $builder->/** @scrutinizer ignore-call */ root($name, $type);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
400
    }
401
}
402