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 (#40)
by Jérémiah
13:22
created

Configuration::getConfigTreeBuilder()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 87
Code Lines 82

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 81
CRAP Score 1

Importance

Changes 13
Bugs 1 Features 5
Metric Value
c 13
b 1
f 5
dl 0
loc 87
ccs 81
cts 81
cp 1
rs 8.6296
cc 1
eloc 82
nc 1
nop 0
crap 1

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
/*
4
 * This file is part of the OverblogGraphQLBundle package.
5
 *
6
 * (c) Overblog <http://github.com/overblog/>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Overblog\GraphQLBundle\DependencyInjection;
13
14
use GraphQL\Validator\Rules\QueryComplexity;
15
use GraphQL\Validator\Rules\QueryDepth;
16
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
17
use Symfony\Component\Config\Definition\ConfigurationInterface;
18
19
/**
20
 * @todo fix xml
21
 */
22
class Configuration implements ConfigurationInterface
23
{
24
    private $debug;
25
26
    /**
27
     * Constructor.
28
     *
29
     * @param bool $debug Whether to use the debug mode
30
     */
31 9
    public function __construct($debug)
32
    {
33 9
        $this->debug = (Boolean) $debug;
34 9
    }
35
36 9
    public function getConfigTreeBuilder()
37
    {
38 9
        $treeBuilder = new TreeBuilder();
39 9
        $rootNode = $treeBuilder->root('overblog_graphql');
40
41
        $rootNode
42 9
            ->children()
43 9
                ->arrayNode('definitions')
44 9
                    ->addDefaultsIfNotSet()
45 9
                    ->children()
46 9
                        ->scalarNode('internal_error_message')->defaultNull()->end()
47 9
                        ->booleanNode('config_validation')->defaultValue($this->debug)->end()
48 9
                        ->arrayNode('schema')
49 9
                            ->addDefaultsIfNotSet()
50 9
                            ->children()
51 9
                                ->scalarNode('query')->defaultNull()->end()
52 9
                                ->scalarNode('mutation')->defaultNull()->end()
53 9
                                ->scalarNode('subscription')->defaultNull()->end()
54 9
                            ->end()
55 9
                        ->end()
56 9
                        ->arrayNode('mappings')
57 9
                            ->children()
58 9
                                ->arrayNode('types')
59 9
                                    ->prototype('array')
60 9
                                        ->addDefaultsIfNotSet()
61 9
                                        ->children()
62 9
                                            ->enumNode('type')->isRequired()->values(['yml', 'xml'])->end()
63 9
                                            ->scalarNode('dir')->defaultNull()->end()
64 9
                                        ->end()
65 9
                                    ->end()
66 9
                                ->end()
67 9
                            ->end()
68 9
                        ->end()
69 9
                        ->arrayNode('builders')
70 9
                            ->children()
71 9
                                ->arrayNode('field')
72 9
                                    ->prototype('array')
73 9
                                        ->children()
74 9
                                            ->scalarNode('alias')->isRequired()->end()
75 9
                                            ->scalarNode('class')->isRequired()->end()
76 9
                                        ->end()
77 9
                                    ->end()
78 9
                                ->end()
79 9
                                ->arrayNode('args')
80 9
                                    ->prototype('array')
81 9
                                        ->children()
82 9
                                            ->scalarNode('alias')->isRequired()->end()
83 9
                                            ->scalarNode('class')->isRequired()->end()
84 9
                                        ->end()
85 9
                                    ->end()
86 9
                                ->end()
87 9
                            ->end()
88 9
                        ->end()
89
90 9
                    ->end()
91 9
                ->end()
92 9
                ->arrayNode('templates')
93 9
                    ->addDefaultsIfNotSet()
94 9
                    ->children()
95 9
                        ->scalarNode('graphiql')
96 9
                            ->defaultValue('OverblogGraphQLBundle:GraphiQL:index.html.twig')
97 9
                        ->end()
98 9
                    ->end()
99 9
                ->end()
100 9
                ->arrayNode('services')
101 9
                    ->addDefaultsIfNotSet()
102 9
                    ->children()
103 9
                        ->scalarNode('expression_language')
104 9
                            ->defaultValue('overblog_graphql.expression_language.default')
105 9
                        ->end()
106 9
                        ->scalarNode('cache_expression_language_parser')
107 9
                            ->defaultValue('overblog_graphql.cache_expression_language_parser.default')
108 9
                        ->end()
109 9
                    ->end()
110 9
                ->end()
111 9
                ->arrayNode('security')
112 9
                    ->addDefaultsIfNotSet()
113 9
                        ->children()
114 9
                            ->append($this->addSecurityQuerySection('query_max_depth', QueryDepth::DISABLED))
115 9
                            ->append($this->addSecurityQuerySection('query_max_complexity', QueryComplexity::DISABLED))
116 9
                        ->end()
117 9
                    ->end()
118 9
                ->end()
119 9
            ->end();
120
121 9
        return $treeBuilder;
122
    }
123
124 9
    private function addSecurityQuerySection($name, $disabledValue)
125
    {
126 9
        $builder = new TreeBuilder();
127 9
        $node = $builder->root($name, 'integer');
128
129
        $node
130 9
            ->info('Disabled if equal to false.')
131 9
            ->beforeNormalization()
132
                ->ifTrue(function ($v) { return false === $v; })
133
                ->then(function () use ($disabledValue) { return $disabledValue; })
134 9
            ->end()
135 9
            ->defaultFalse()
136 9
            ->validate()
137
                ->ifTrue(function ($v) { return $v < 0; })
138 9
                ->thenInvalid('"overblog_graphql.security.'.$name.'" must be greater or equal to 0.')
139 9
            ->end()
140
        ;
141
142 9
        return $node;
143
    }
144
}
145