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 (#23)
by Jérémiah
12:19
created

Configuration   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 106
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 15
Bugs 1 Features 9
Metric Value
wmc 3
c 15
b 1
f 9
lcom 1
cbo 4
dl 0
loc 106
ccs 74
cts 74
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getConfigTreeBuilder() 0 70 1
A addSecurityQuerySection() 0 20 1
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 Overblog\GraphQLBundle\Request\Validator\Rule\QueryDepth;
15
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
16
use Symfony\Component\Config\Definition\ConfigurationInterface;
17
18
/**
19
 * @todo fix xml
20
 */
21
class Configuration implements ConfigurationInterface
22
{
23
    private $debug;
24
25
    /**
26
     * Constructor.
27
     *
28
     * @param bool $debug Whether to use the debug mode
29 36
     */
30
    public function __construct($debug)
31 36
    {
32 36
        $this->debug = (Boolean) $debug;
33
    }
34 36
35
    public function getConfigTreeBuilder()
36 36
    {
37 36
        $treeBuilder = new TreeBuilder();
38
        $rootNode = $treeBuilder->root('overblog_graphql');
39
40 36
        $rootNode
41 36
            ->children()
42 36
                ->arrayNode('definitions')
43 36
                    ->addDefaultsIfNotSet()
44 36
                    ->children()
45 36
                        ->scalarNode('internal_error_message')->defaultNull()->end()
46 36
                        ->booleanNode('config_validation')->defaultValue($this->debug)->end()
47 36
                        ->arrayNode('schema')
48 36
                            ->addDefaultsIfNotSet()
49 36
                            ->children()
50 36
                                ->scalarNode('query')->defaultNull()->end()
51 36
                                ->scalarNode('mutation')->defaultNull()->end()
52 36
                                ->scalarNode('subscription')->defaultNull()->end()
53 36
                            ->end()
54 36
                        ->end()
55 36
                        ->arrayNode('mappings')
56 36
                            ->children()
57 36
                                ->arrayNode('types')
58 36
                                    ->prototype('array')
59 36
                                        ->addDefaultsIfNotSet()
60 36
                                        ->children()
61 36
                                            ->enumNode('type')->isRequired()->values(['yml', 'xml'])->end()
62 36
                                            ->scalarNode('dir')->defaultNull()->end()
63 36
                                        ->end()
64 36
                                    ->end()
65 36
                                ->end()
66 36
                            ->end()
67
                        ->end()
68 36
                        // TODO remove when types mapping 100% functional
69 36
                        ->variableNode('types')
70 36
                            ->info('Defining types using semantic config is deprecated and will be soon removed.')
71 36
                        ->end()
72 36
                    ->end()
73 36
                ->end()
74 36
                ->arrayNode('templates')
75 36
                    ->addDefaultsIfNotSet()
76 36
                    ->children()
77 36
                        ->scalarNode('graphiql')
78 36
                            ->defaultValue('OverblogGraphQLBundle:GraphiQL:index.html.twig')
79 36
                        ->end()
80 36
                    ->end()
81 36
                ->end()
82 36
                ->arrayNode('services')
83 36
                    ->addDefaultsIfNotSet()
84 36
                    ->children()
85 36
                        ->scalarNode('expression_language')
86 36
                            ->defaultValue('overblog_graphql.expression_language.default')
87 36
                        ->end()
88 36
                        ->scalarNode('cache_expression_language_parser')
89 36
                            ->defaultValue('overblog_graphql.cache_expression_language_parser.default')
90 36
                        ->end()
91 36
                    ->end()
92 36
                ->end()
93 36
                ->arrayNode('security')
94 36
                    ->addDefaultsIfNotSet()
95 36
                        ->children()
96 36
                            ->append($this->addSecurityQuerySection('query_max_depth', QueryDepth::DISABLED))
97 36
                            ->append($this->addSecurityQuerySection('query_max_complexity', QueryDepth::DISABLED))
98
                        ->end()
99
                    ->end()
100 36
                ->end()
101 36
            ->end();
102 36
103
        return $treeBuilder;
104 36
    }
105 36
106 36
    private function addSecurityQuerySection($name, $disabledValue)
107 36
    {
108 36
        $builder = new TreeBuilder();
109 36
        $node = $builder->root($name, 'integer');
110 36
111
        $node
112 36
            ->info('Disabled if equal to false.')
113
            ->beforeNormalization()
114
                ->ifTrue(function ($v) { return false === $v; })
115
                ->then(function () use ($disabledValue) { return $disabledValue; })
116
            ->end()
117
            ->defaultFalse()
118
            ->validate()
119
                ->ifTrue(function ($v) { return $v < 0; })
120
                ->thenInvalid('"overblog_graphql.security.'.$name.'" must be greater or equal to 0.')
121
            ->end()
122
        ;
123
124
        return $node;
125
    }
126
}
127