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 ( 5c920d...e34953 )
by Jérémiah
05:53 queued 24s
created

Configuration::addSecurityQuerySection()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 26
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 17
CRAP Score 1.0001

Importance

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