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:18
created

OverblogGraphQLExtension::setServicesAliases()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 9
ccs 8
cts 8
cp 1
rs 9.6666
cc 3
eloc 5
nc 3
nop 2
crap 3
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 Symfony\Component\Config\FileLocator;
15
use Symfony\Component\DependencyInjection\ContainerBuilder;
16
use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface;
17
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
18
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
19
20
class OverblogGraphQLExtension extends Extension implements PrependExtensionInterface
21
{
22 45
    public function load(array $configs, ContainerBuilder $container)
23
    {
24 45
        $loader = new YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
25 45
        $loader->load('services.yml');
26 45
        $loader->load('graphql_types.yml');
27 45
        $loader->load('graphql_fields.yml');
28 45
        $loader->load('graphql_args.yml');
29
30 45
        $configuration = $this->getConfiguration($configs, $container);
31 45
        $config = $this->processConfiguration($configuration, $configs);
32
33 45
        $this->setServicesAliases($config, $container);
34 45
        $this->setSchemaBuilderArguments($config, $container);
35 45
        $this->setSchemaArguments($config, $container);
36 45
        $this->setErrorHandlerArguments($config, $container);
37 45
        $this->setGraphiQLTemplate($config, $container);
38 45
        $this->setSecurity($config, $container);
39 45
    }
40
41 45
    public function prepend(ContainerBuilder $container)
42
    {
43 45
        $configs = $container->getExtensionConfig($this->getAlias());
44 45
        $configs = $container->getParameterBag()->resolveValue($configs);
45 45
        $configuration = $this->getConfiguration($configs, $container);
46 45
        $config = $this->processConfiguration($configuration, $configs);
47
48
        /** @var OverblogGraphQLTypesExtension $typesExtension */
49 45
        $typesExtension = $container->getExtension($this->getAlias().'_types');
50 45
        $typesExtension->containerPrependExtensionConfig($config, $container);
51 45
    }
52
53 45
    private function setSecurity(array $config, ContainerBuilder $container)
54
    {
55 45 View Code Duplication
        if (isset($config['security']['query_max_depth'])) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
56
            $container
57 45
                ->getDefinition($this->getAlias().'.request_validator_rule_query_depth')
58 45
                ->addMethodCall('setMaxQueryDepth', [$config['security']['query_max_depth']])
59 45
                ->setPublic(true)
60
            ;
61 45
        }
62
63 45 View Code Duplication
        if (isset($config['security']['query_max_complexity'])) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
64
            $container
65 45
                ->getDefinition($this->getAlias().'.request_validator_rule_query_complexity')
66 45
                ->addMethodCall('setMaxQueryComplexity', [$config['security']['query_max_complexity']])
67 45
                ->setPublic(true)
68
            ;
69 45
        }
70 45
    }
71
72 45
    private function setGraphiQLTemplate(array $config, ContainerBuilder $container)
73
    {
74 45
        if (isset($config['templates']['graphiql'])) {
75 45
            $container->setParameter('overblog_graphql.graphiql_template', $config['templates']['graphiql']);
76 45
        }
77 45
    }
78
79 45
    private function setErrorHandlerArguments(array $config, ContainerBuilder $container)
80
    {
81 45 View Code Duplication
        if (isset($config['definitions']['internal_error_message'])) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
82
            $container
83
                ->getDefinition($this->getAlias().'.error_handler')
84
                ->replaceArgument(0, $config['definitions']['internal_error_message'])
85
                ->setPublic(true)
86
            ;
87
        }
88 45
    }
89
90 45
    private function setSchemaBuilderArguments(array $config, ContainerBuilder $container)
91
    {
92 45
        $container->getDefinition($this->getAlias().'.schema_builder')
93 45
            ->replaceArgument(1, $config['definitions']['config_validation']);
94 45
    }
95
96 45
    private function setSchemaArguments(array $config, ContainerBuilder $container)
97
    {
98 45
        if (isset($config['definitions']['schema'])) {
99
            $container
100 45
                ->getDefinition($this->getAlias().'.schema')
101 45
                ->replaceArgument(0, $config['definitions']['schema']['query'])
102 45
                ->replaceArgument(1, $config['definitions']['schema']['mutation'])
103 45
                ->replaceArgument(2, $config['definitions']['schema']['subscription'])
104 45
                ->setPublic(true)
105
            ;
106 45
        }
107 45
    }
108
109 45
    private function setServicesAliases(array $config, ContainerBuilder $container)
110
    {
111 45
        if (isset($config['services'])) {
112 45
            foreach ($config['services'] as $name => $id) {
113 45
                $alias = sprintf('%s.%s', $this->getAlias(), $name);
114 45
                $container->setAlias($alias, $id);
115 45
            }
116 45
        }
117 45
    }
118
119 45
    public function getAlias()
120
    {
121 45
        return 'overblog_graphql';
122
    }
123
124 45
    public function getConfiguration(array $config, ContainerBuilder $container)
125
    {
126 45
        return new Configuration($container->getParameter('kernel.debug'));
127
    }
128
}
129