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

setErrorHandlerArguments()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 9
ccs 6
cts 6
cp 1
rs 9.6666
cc 2
eloc 5
nc 2
nop 2
crap 2
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
40 9
        $container->setParameter($this->getAlias().'.resources_dir', realpath(__DIR__.'/../Resources'));
41 9
    }
42
43 8
    public function prepend(ContainerBuilder $container)
44
    {
45 8
        $configs = $container->getExtensionConfig($this->getAlias());
46 8
        $configs = $container->getParameterBag()->resolveValue($configs);
47 8
        $config = $this->treatConfigs($configs, $container, true);
48
49
        /** @var OverblogGraphQLTypesExtension $typesExtension */
50 8
        $typesExtension = $container->getExtension($this->getAlias().'_types');
51 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 47 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...
52 8
    }
53
54 9
    private function setConfigBuilders(array $config)
55
    {
56 9
        foreach (['args', 'field'] as $category) {
57 9
            if (!empty($config['definitions']['builders'][$category])) {
58 1
                $method = 'add'.ucfirst($category).'BuilderClass';
59
60 1
                foreach ($config['definitions']['builders'][$category] as $params) {
61 1
                    TypeWithOutputFieldsDefinition::$method($params['alias'], $params['class']);
62 1
                }
63 1
            }
64 9
        }
65 9
    }
66
67 9
    private function treatConfigs(array $configs, ContainerBuilder $container, $forceReload = false)
68
    {
69 9
        static $config = null;
70
71 9
        if ($forceReload || null === $config) {
72 9
            $configuration = $this->getConfiguration($configs, $container);
73 9
            $config = $this->processConfiguration($configuration, $configs);
74 9
        }
75
76 9
        return $config;
77
    }
78
79 9
    private function setSecurity(array $config, ContainerBuilder $container)
80
    {
81 9
        $container->setParameter($this->getAlias().'.query_max_depth', $config['security']['query_max_depth']);
82 9
        $container->setParameter($this->getAlias().'.query_max_complexity', $config['security']['query_max_complexity']);
83 9
    }
84
85 9
    private function setGraphiQLTemplate(array $config, ContainerBuilder $container)
86
    {
87 9
        $container->setParameter($this->getAlias().'.graphiql_template', $config['templates']['graphiql']);
88 9
    }
89
90 9
    private function setErrorHandlerArguments(array $config, ContainerBuilder $container)
91
    {
92 9
        if (isset($config['definitions']['internal_error_message'])) {
93
            $container
94 1
                ->getDefinition($this->getAlias().'.error_handler')
95 1
                ->replaceArgument(0, $config['definitions']['internal_error_message'])
96
            ;
97 1
        }
98 9
    }
99
100 9
    private function setSchemaBuilderArguments(array $config, ContainerBuilder $container)
101
    {
102 9
        $container->getDefinition($this->getAlias().'.schema_builder')
103 9
            ->replaceArgument(1, $config['definitions']['config_validation']);
104 9
    }
105
106 9
    private function setSchemaArguments(array $config, ContainerBuilder $container)
107
    {
108 9
        if (isset($config['definitions']['schema'])) {
109
            $container
110 9
                ->getDefinition($this->getAlias().'.schema')
111 9
                ->replaceArgument(0, $config['definitions']['schema']['query'])
112 9
                ->replaceArgument(1, $config['definitions']['schema']['mutation'])
113 9
                ->replaceArgument(2, $config['definitions']['schema']['subscription'])
114 9
                ->setPublic(true)
115
            ;
116 9
        }
117 9
    }
118
119 9
    private function setServicesAliases(array $config, ContainerBuilder $container)
120
    {
121 9
        if (isset($config['services'])) {
122 9
            foreach ($config['services'] as $name => $id) {
123 9
                $alias = sprintf('%s.%s', $this->getAlias(), $name);
124 9
                $container->setAlias($alias, $id);
125 9
            }
126 9
        }
127 9
    }
128
129 9
    public function getAlias()
130
    {
131 9
        return 'overblog_graphql';
132
    }
133
134 9
    public function getConfiguration(array $config, ContainerBuilder $container)
135
    {
136 9
        return new Configuration($container->getParameter('kernel.debug'));
137
    }
138
}
139