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 (#52)
by Jérémiah
07:31
created

OverblogGraphQLExtension::setVersions()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 5
ccs 4
cts 4
cp 1
rs 9.4285
cc 1
eloc 3
nc 1
nop 2
crap 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\Config\TypeWithOutputFieldsDefinition;
15
use Symfony\Component\Config\FileLocator;
16
use Symfony\Component\DependencyInjection\ContainerBuilder;
17
use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface;
18
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
19
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
20
21
class OverblogGraphQLExtension extends Extension implements PrependExtensionInterface
22
{
23 9
    public function load(array $configs, ContainerBuilder $container)
24
    {
25 9
        $loader = new YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
26 9
        $loader->load('services.yml');
27 9
        $loader->load('graphql_types.yml');
28 9
        $loader->load('graphql_resolvers.yml');
29
30 9
        $config = $this->treatConfigs($configs, $container);
31
32 9
        $this->setServicesAliases($config, $container);
0 ignored issues
show
Bug introduced by
It seems like $config defined by $this->treatConfigs($configs, $container) on line 30 can also be of type null; however, Overblog\GraphQLBundle\D...n::setServicesAliases() does only seem to accept array, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
33 9
        $this->setSchemaBuilderArguments($config, $container);
0 ignored issues
show
Bug introduced by
It seems like $config defined by $this->treatConfigs($configs, $container) on line 30 can also be of type null; however, Overblog\GraphQLBundle\D...chemaBuilderArguments() does only seem to accept array, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
34 9
        $this->setSchemaArguments($config, $container);
0 ignored issues
show
Bug introduced by
It seems like $config defined by $this->treatConfigs($configs, $container) on line 30 can also be of type null; however, Overblog\GraphQLBundle\D...n::setSchemaArguments() does only seem to accept array, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
35 9
        $this->setErrorHandlerArguments($config, $container);
0 ignored issues
show
Bug introduced by
It seems like $config defined by $this->treatConfigs($configs, $container) on line 30 can also be of type null; however, Overblog\GraphQLBundle\D...ErrorHandlerArguments() does only seem to accept array, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
36 9
        $this->setGraphiQLTemplate($config, $container);
0 ignored issues
show
Bug introduced by
It seems like $config defined by $this->treatConfigs($configs, $container) on line 30 can also be of type null; however, Overblog\GraphQLBundle\D...::setGraphiQLTemplate() does only seem to accept array, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
37 9
        $this->setSecurity($config, $container);
0 ignored issues
show
Bug introduced by
It seems like $config defined by $this->treatConfigs($configs, $container) on line 30 can also be of type null; however, Overblog\GraphQLBundle\D...xtension::setSecurity() does only seem to accept array, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
38 9
        $this->setConfigBuilders($config);
0 ignored issues
show
Bug introduced by
It seems like $config defined by $this->treatConfigs($configs, $container) on line 30 can also be of type null; however, Overblog\GraphQLBundle\D...on::setConfigBuilders() does only seem to accept array, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
39 9
        $this->setVersions($config, $container);
0 ignored issues
show
Bug introduced by
It seems like $config defined by $this->treatConfigs($configs, $container) on line 30 can also be of type null; however, Overblog\GraphQLBundle\D...xtension::setVersions() does only seem to accept array, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
40
41 9
        $container->setParameter($this->getAlias().'.resources_dir', realpath(__DIR__.'/../Resources'));
42 9
    }
43
44 8
    public function prepend(ContainerBuilder $container)
45
    {
46 8
        $configs = $container->getExtensionConfig($this->getAlias());
47 8
        $configs = $container->getParameterBag()->resolveValue($configs);
48 8
        $config = $this->treatConfigs($configs, $container, true);
49
50
        /** @var OverblogGraphQLTypesExtension $typesExtension */
51 8
        $typesExtension = $container->getExtension($this->getAlias().'_types');
52 8
        $typesExtension->containerPrependExtensionConfig($config, $container);
0 ignored issues
show
Bug introduced by
It seems like $config defined by $this->treatConfigs($configs, $container, true) on line 48 can also be of type null; however, Overblog\GraphQLBundle\D...rependExtensionConfig() does only seem to accept array, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
53 8
    }
54
55 9
    private function setVersions(array $config, ContainerBuilder $container)
56
    {
57 9
        $container->setParameter($this->getAlias().'.versions.graphiql', $config['versions']['graphiql']);
58 9
        $container->setParameter($this->getAlias().'.versions.react', $config['versions']['react']);
59 9
    }
60
61 9
    private function setConfigBuilders(array $config)
62
    {
63 9
        foreach (['args', 'field'] as $category) {
64 9
            if (!empty($config['definitions']['builders'][$category])) {
65 1
                $method = 'add'.ucfirst($category).'BuilderClass';
66
67 1
                foreach ($config['definitions']['builders'][$category] as $params) {
68 1
                    TypeWithOutputFieldsDefinition::$method($params['alias'], $params['class']);
69 1
                }
70 1
            }
71 9
        }
72 9
    }
73
74 9
    private function treatConfigs(array $configs, ContainerBuilder $container, $forceReload = false)
75
    {
76 9
        static $config = null;
77
78 9
        if ($forceReload || null === $config) {
79 9
            $configuration = $this->getConfiguration($configs, $container);
80 9
            $config = $this->processConfiguration($configuration, $configs);
81 9
        }
82
83 9
        return $config;
84
    }
85
86 9
    private function setSecurity(array $config, ContainerBuilder $container)
87
    {
88 9
        $container->setParameter($this->getAlias().'.query_max_depth', $config['security']['query_max_depth']);
89 9
        $container->setParameter($this->getAlias().'.query_max_complexity', $config['security']['query_max_complexity']);
90 9
    }
91
92 9
    private function setGraphiQLTemplate(array $config, ContainerBuilder $container)
93
    {
94 9
        $container->setParameter($this->getAlias().'.graphiql_template', $config['templates']['graphiql']);
95 9
    }
96
97 9
    private function setErrorHandlerArguments(array $config, ContainerBuilder $container)
98
    {
99 9
        if (isset($config['definitions']['internal_error_message'])) {
100
            $container
101 1
                ->getDefinition($this->getAlias().'.error_handler')
102 1
                ->replaceArgument(0, $config['definitions']['internal_error_message'])
103
            ;
104 1
        }
105 9
    }
106
107 9
    private function setSchemaBuilderArguments(array $config, ContainerBuilder $container)
108
    {
109 9
        $container->getDefinition($this->getAlias().'.schema_builder')
110 9
            ->replaceArgument(1, $config['definitions']['config_validation']);
111 9
    }
112
113 9
    private function setSchemaArguments(array $config, ContainerBuilder $container)
114
    {
115 9
        if (isset($config['definitions']['schema'])) {
116
            $container
117 9
                ->getDefinition($this->getAlias().'.schema')
118 9
                ->replaceArgument(0, $config['definitions']['schema']['query'])
119 9
                ->replaceArgument(1, $config['definitions']['schema']['mutation'])
120 9
                ->replaceArgument(2, $config['definitions']['schema']['subscription'])
121 9
                ->setPublic(true)
122
            ;
123 9
        }
124 9
    }
125
126 9
    private function setServicesAliases(array $config, ContainerBuilder $container)
127
    {
128 9
        if (isset($config['services'])) {
129 9
            foreach ($config['services'] as $name => $id) {
130 9
                $alias = sprintf('%s.%s', $this->getAlias(), $name);
131 9
                $container->setAlias($alias, $id);
132 9
            }
133 9
        }
134 9
    }
135
136 9
    public function getAlias()
137
    {
138 9
        return 'overblog_graphql';
139
    }
140
141 9
    public function getConfiguration(array $config, ContainerBuilder $container)
142
    {
143 9
        return new Configuration($container->getParameter('kernel.debug'));
144
    }
145
}
146