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
13:51 queued 05:06
created

OverblogGraphQLExtension   A

Complexity

Total Complexity 17

Size/Duplication

Total Lines 109
Duplicated Lines 19.27 %

Coupling/Cohesion

Components 1
Dependencies 8

Test Coverage

Coverage 94.44%

Importance

Changes 11
Bugs 1 Features 6
Metric Value
wmc 17
c 11
b 1
f 6
lcom 1
cbo 8
dl 21
loc 109
ccs 68
cts 72
cp 0.9444
rs 10

10 Methods

Rating   Name   Duplication   Size   Complexity  
A load() 0 18 1
A prepend() 0 11 1
A setSecurity() 14 18 3
A setSchemaBuilderArguments() 0 5 1
A setSchemaArguments() 0 12 2
A setGraphiQLTemplate() 0 6 2
A setErrorHandlerArguments() 7 10 2
A setServicesAliases() 0 9 3
A getAlias() 0 4 1
A getConfiguration() 0 4 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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'])) {
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'])) {
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'])) {
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