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
Push — master ( 0ef2a6...5c920d )
by Jérémiah
37s
created

Configuration::getConfigTreeBuilder()   B

Complexity

Conditions 6
Paths 1

Size

Total Lines 132
Code Lines 123

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 121
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 132
ccs 121
cts 122
cp 0.9918
rs 8.1463
c 0
b 0
f 0
cc 6
eloc 123
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 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 11
    public function __construct($debug)
32
    {
33 11
        $this->debug = (Boolean) $debug;
34 11
    }
35
36 11
    public function getConfigTreeBuilder()
37
    {
38 11
        $treeBuilder = new TreeBuilder();
39 11
        $rootNode = $treeBuilder->root('overblog_graphql');
40
41
        $rootNode
42 11
            ->children()
43 11
                ->arrayNode('definitions')
44 11
                    ->addDefaultsIfNotSet()
45 11
                    ->children()
46 11
                        ->scalarNode('internal_error_message')->defaultNull()->end()
47 11
                        ->booleanNode('config_validation')->defaultValue($this->debug)->end()
48 11
                        ->arrayNode('schema')
49 11
                            ->beforeNormalization()
50
                                ->ifTrue(function ($v) {
51 8
                                    $needNormalization = isset($v['query']) && is_string($v['query']) ||
52
                                        isset($v['mutation']) && is_string($v['mutation']) ||
53 8
                                        isset($v['subscription']) && is_string($v['subscription']);
54
55 8
                                    return $needNormalization;
56 11
                                })
57
                                ->then(function ($v) {
58 8
                                    return ['default' => $v];
59 11
                                })
60 11
                            ->end()
61 11
                            ->useAttributeAsKey('name')
62 11
                            ->prototype('array')
63 11
                                ->addDefaultsIfNotSet()
64 11
                                ->children()
65 11
                                    ->scalarNode('query')->defaultNull()->end()
66 11
                                    ->scalarNode('mutation')->defaultNull()->end()
67 11
                                    ->scalarNode('subscription')->defaultNull()->end()
68 11
                                ->end()
69 11
                            ->end()
70 11
                        ->end()
71 11
                        ->arrayNode('mappings')
72 11
                            ->children()
73 11
                                ->arrayNode('types')
74 11
                                    ->prototype('array')
75 11
                                        ->addDefaultsIfNotSet()
76 11
                                        ->children()
77 11
                                            ->enumNode('type')->isRequired()->values(['yml', 'xml'])->end()
78 11
                                            ->scalarNode('dir')->defaultNull()->end()
79 11
                                        ->end()
80 11
                                    ->end()
81 11
                                ->end()
82 11
                            ->end()
83 11
                        ->end()
84 11
                        ->arrayNode('exceptions')
85 11
                            ->children()
86 11
                                ->arrayNode('warnings')
87 11
                                    ->treatNullLike(array())
88 11
                                    ->prototype('scalar')->end()
89 11
                                ->end()
90 11
                                ->arrayNode('errors')
91 11
                                    ->treatNullLike(array())
92 11
                                    ->prototype('scalar')->end()
93 11
                                ->end()
94 11
                                ->arrayNode('types')
95 11
                                    ->addDefaultsIfNotSet()
96 11
                                    ->children()
97 11
                                        ->scalarNode('warnings')
98 11
                                            ->defaultValue('Overblog\\GraphQLBundle\\Error\\UserWarning')
99 11
                                        ->end()
100 11
                                        ->scalarNode('errors')
101 11
                                            ->defaultValue('Overblog\\GraphQLBundle\\Error\\UserError')
102 11
                                        ->end()
103 11
                                    ->end()
104 11
                                ->end()
105 11
                            ->end()
106 11
                        ->end()
107
108 11
                        ->arrayNode('builders')
109 11
                            ->children()
110 11
                                ->arrayNode('field')
111 11
                                    ->prototype('array')
112 11
                                        ->children()
113 11
                                            ->scalarNode('alias')->isRequired()->end()
114 11
                                            ->scalarNode('class')->isRequired()->end()
115 11
                                        ->end()
116 11
                                    ->end()
117 11
                                ->end()
118 11
                                ->arrayNode('args')
119 11
                                    ->prototype('array')
120 11
                                        ->children()
121 11
                                            ->scalarNode('alias')->isRequired()->end()
122 11
                                            ->scalarNode('class')->isRequired()->end()
123 11
                                        ->end()
124 11
                                    ->end()
125 11
                                ->end()
126 11
                            ->end()
127 11
                        ->end()
128
129 11
                    ->end()
130 11
                ->end()
131 11
                ->arrayNode('templates')
132 11
                    ->addDefaultsIfNotSet()
133 11
                    ->children()
134 11
                        ->scalarNode('graphiql')
135 11
                            ->defaultValue('OverblogGraphQLBundle:GraphiQL:index.html.twig')
136 11
                        ->end()
137 11
                    ->end()
138 11
                ->end()
139 11
                ->arrayNode('services')
140 11
                    ->addDefaultsIfNotSet()
141 11
                    ->children()
142 11
                        ->scalarNode('expression_language')
143 11
                            ->defaultValue('overblog_graphql.expression_language.default')
144 11
                        ->end()
145 11
                        ->scalarNode('cache_expression_language_parser')
146 11
                            ->defaultValue('overblog_graphql.cache_expression_language_parser.default')
147 11
                        ->end()
148 11
                    ->end()
149 11
                ->end()
150 11
                ->arrayNode('security')
151 11
                    ->addDefaultsIfNotSet()
152 11
                    ->children()
153 11
                        ->append($this->addSecurityQuerySection('query_max_depth', QueryDepth::DISABLED))
154 11
                        ->append($this->addSecurityQuerySection('query_max_complexity', QueryComplexity::DISABLED))
155 11
                    ->end()
156 11
                ->end()
157 11
                ->arrayNode('versions')
158 11
                    ->addDefaultsIfNotSet()
159 11
                    ->children()
160 11
                        ->scalarNode('graphiql')->defaultValue('0.7.8')->end()
161 11
                        ->scalarNode('react')->defaultValue('15.3.2')->end()
162 11
                    ->end()
163 11
                ->end()
164 11
            ->end();
165
166 11
        return $treeBuilder;
167
    }
168
169 11
    private function addSecurityQuerySection($name, $disabledValue)
170
    {
171 11
        $builder = new TreeBuilder();
172 11
        $node = $builder->root($name, 'integer');
173
174
        $node
175 11
            ->info('Disabled if equal to false.')
176 11
            ->beforeNormalization()
177
                ->ifTrue(function ($v) { return false === $v; })
178
                ->then(function () use ($disabledValue) { return $disabledValue; })
179 11
            ->end()
180 11
            ->defaultFalse()
181 11
            ->validate()
182
                ->ifTrue(function ($v) { return $v < 0; })
183 11
                ->thenInvalid('"overblog_graphql.security.'.$name.'" must be greater or equal to 0.')
184 11
            ->end()
185
        ;
186
187 11
        return $node;
188
    }
189
}
190