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

Configuration::getConfigTreeBuilder()   B

Complexity

Conditions 6
Paths 1

Size

Total Lines 141
Code Lines 132

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 130
CRAP Score 6

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 141
ccs 130
cts 131
cp 0.9924
rs 8.1463
cc 6
eloc 132
nc 1
nop 0
crap 6

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 Overblog\GraphQLBundle\Error\ErrorHandler;
17
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
18
use Symfony\Component\Config\Definition\ConfigurationInterface;
19
20
/**
21
 * @todo fix xml
22
 */
23
class Configuration implements ConfigurationInterface
24
{
25
    private $debug;
26
27
    /**
28
     * Constructor.
29
     *
30
     * @param bool $debug Whether to use the debug mode
31
     */
32 13
    public function __construct($debug)
33
    {
34 13
        $this->debug = (bool) $debug;
35 13
    }
36
37 13
    public function getConfigTreeBuilder()
38
    {
39 13
        $treeBuilder = new TreeBuilder();
40 13
        $rootNode = $treeBuilder->root('overblog_graphql');
41
42
        $rootNode
43 13
            ->children()
44 13
                ->arrayNode('definitions')
45 13
                    ->addDefaultsIfNotSet()
46 13
                    ->children()
47 13
                        ->scalarNode('internal_error_message')->defaultNull()->end()
48 13
                        ->booleanNode('show_debug_info')->defaultValue(false)->end()
49 13
                        ->booleanNode('config_validation')->defaultValue($this->debug)->end()
50 13
                        ->arrayNode('schema')
51 13
                            ->beforeNormalization()
52
                                ->ifTrue(function ($v) {
53 10
                                    $needNormalization = isset($v['query']) && is_string($v['query']) ||
54
                                        isset($v['mutation']) && is_string($v['mutation']) ||
55 10
                                        isset($v['subscription']) && is_string($v['subscription']);
56
57 10
                                    return $needNormalization;
58 13
                                })
59
                                ->then(function ($v) {
60 10
                                    return ['default' => $v];
61 13
                                })
62 13
                            ->end()
63 13
                            ->useAttributeAsKey('name')
64 13
                            ->prototype('array')
65 13
                                ->addDefaultsIfNotSet()
66 13
                                ->children()
67 13
                                    ->scalarNode('query')->defaultNull()->end()
68 13
                                    ->scalarNode('mutation')->defaultNull()->end()
69 13
                                    ->scalarNode('subscription')->defaultNull()->end()
70 13
                                ->end()
71 13
                            ->end()
72 13
                        ->end()
73 13
                        ->arrayNode('mappings')
74 13
                            ->children()
75 13
                                ->arrayNode('types')
76 13
                                    ->prototype('array')
77 13
                                        ->addDefaultsIfNotSet()
78 13
                                        ->children()
79 13
                                            ->enumNode('type')->isRequired()->values(['yml', 'xml'])->end()
80 13
                                            ->scalarNode('dir')->defaultNull()->end()
81 13
                                        ->end()
82 13
                                    ->end()
83 13
                                ->end()
84 13
                            ->end()
85 13
                        ->end()
86 13
                        ->arrayNode('exceptions')
87 13
                            ->addDefaultsIfNotSet()
88 13
                            ->children()
89 13
                                ->arrayNode('warnings')
90 13
                                    ->treatNullLike([])
91 13
                                    ->prototype('scalar')->end()
92 13
                                ->end()
93 13
                                ->arrayNode('errors')
94 13
                                    ->treatNullLike([])
95 13
                                    ->prototype('scalar')->end()
96 13
                                ->end()
97 13
                                ->arrayNode('types')
98 13
                                    ->addDefaultsIfNotSet()
99 13
                                    ->children()
100 13
                                        ->scalarNode('warnings')
101 13
                                            ->defaultValue(ErrorHandler::DEFAULT_USER_WARNING_CLASS)
102 13
                                        ->end()
103 13
                                        ->scalarNode('errors')
104 13
                                            ->defaultValue(ErrorHandler::DEFAULT_USER_ERROR_CLASS)
105 13
                                        ->end()
106 13
                                    ->end()
107 13
                                ->end()
108 13
                            ->end()
109 13
                        ->end()
110
111 13
                        ->arrayNode('builders')
112 13
                            ->children()
113 13
                                ->arrayNode('field')
114 13
                                    ->prototype('array')
115 13
                                        ->children()
116 13
                                            ->scalarNode('alias')->isRequired()->end()
117 13
                                            ->scalarNode('class')->isRequired()->end()
118 13
                                        ->end()
119 13
                                    ->end()
120 13
                                ->end()
121 13
                                ->arrayNode('args')
122 13
                                    ->prototype('array')
123 13
                                        ->children()
124 13
                                            ->scalarNode('alias')->isRequired()->end()
125 13
                                            ->scalarNode('class')->isRequired()->end()
126 13
                                        ->end()
127 13
                                    ->end()
128 13
                                ->end()
129 13
                            ->end()
130 13
                        ->end()
131
132 13
                    ->end()
133 13
                ->end()
134 13
                ->arrayNode('templates')
135 13
                    ->addDefaultsIfNotSet()
136 13
                    ->children()
137 13
                        ->scalarNode('graphiql')
138 13
                            ->defaultValue('OverblogGraphQLBundle:GraphiQL:index.html.twig')
139 13
                        ->end()
140 13
                    ->end()
141 13
                ->end()
142 13
                ->arrayNode('services')
143 13
                    ->addDefaultsIfNotSet()
144 13
                    ->children()
145 13
                        ->scalarNode('executor')
146 13
                            ->defaultValue('overblog_graphql.executor.default')
147 13
                        ->end()
148 13
                        ->scalarNode('promise_adapter')
149 13
                            ->defaultValue('overblog_graphql.promise_adapter.default')
150 13
                        ->end()
151 13
                        ->scalarNode('expression_language')
152 13
                            ->defaultValue('overblog_graphql.expression_language.default')
153 13
                        ->end()
154 13
                        ->scalarNode('cache_expression_language_parser')
155 13
                            ->defaultValue('overblog_graphql.cache_expression_language_parser.default')
156 13
                        ->end()
157 13
                    ->end()
158 13
                ->end()
159 13
                ->arrayNode('security')
160 13
                    ->addDefaultsIfNotSet()
161 13
                    ->children()
162 13
                        ->append($this->addSecurityQuerySection('query_max_depth', QueryDepth::DISABLED))
163 13
                        ->append($this->addSecurityQuerySection('query_max_complexity', QueryComplexity::DISABLED))
164 13
                    ->end()
165 13
                ->end()
166 13
                ->arrayNode('versions')
167 13
                    ->addDefaultsIfNotSet()
168 13
                    ->children()
169 13
                        ->scalarNode('graphiql')->defaultValue('0.7.8')->end()
170 13
                        ->scalarNode('react')->defaultValue('15.3.2')->end()
171 13
                        ->scalarNode('fetch')->defaultValue('2.0.1')->end()
172 13
                    ->end()
173 13
                ->end()
174 13
            ->end();
175
176 13
        return $treeBuilder;
177
    }
178
179 13
    private function addSecurityQuerySection($name, $disabledValue)
180
    {
181 13
        $builder = new TreeBuilder();
182 13
        $node = $builder->root($name, 'integer');
183
184
        $node
185 13
            ->info('Disabled if equal to false.')
186 13
            ->beforeNormalization()
187
                ->ifTrue(function ($v) {
188 1
                    return false === $v;
189 13
                })
190
                ->then(function () use ($disabledValue) {
191
                    return $disabledValue;
192 13
                })
193 13
            ->end()
194 13
            ->defaultFalse()
195 13
            ->validate()
196 13
                ->ifTrue(function ($v) {
197 1
                    return $v < 0;
198 13
                })
199 13
                ->thenInvalid('"overblog_graphql.security.'.$name.'" must be greater or equal to 0.')
200 13
            ->end()
201
        ;
202
203 13
        return $node;
204
    }
205
}
206