Passed
Push — master ( 429b06...f0c7c5 )
by Rafael
08:46
created

YnloGraphQLExtension   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 10
c 0
b 0
f 0
dl 0
loc 50
ccs 0
cts 23
cp 0
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getAlias() 0 3 1
D load() 0 36 9
1
<?php
2
3
/*******************************************************************************
4
 *  This file is part of the GraphQL Bundle package.
5
 *
6
 *  (c) YnloUltratech <[email protected]>
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 Ynlo\GraphQLBundle\DependencyInjection;
13
14
use Symfony\Component\Config\FileLocator;
15
use Symfony\Component\DependencyInjection\ContainerBuilder;
16
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
17
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
18
use Ynlo\GraphQLBundle\Cache\DefinitionCacheWarmer;
19
use Ynlo\GraphQLBundle\GraphiQL\JWTGraphiQLAuthentication;
20
21
/**
22
 * Class YnloGraphQLExtension
23
 */
24
class YnloGraphQLExtension extends Extension
25
{
26
    /**
27
     * {@inheritdoc}
28
     */
29
    public function load(array $configs, ContainerBuilder $container)
30
    {
31
        $configuration = new Configuration($container->getParameter('kernel.debug'));
0 ignored issues
show
Unused Code introduced by
The call to Ynlo\GraphQLBundle\Depen...guration::__construct() has too many arguments starting with $container->getParameter('kernel.debug'). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

31
        $configuration = /** @scrutinizer ignore-call */ new Configuration($container->getParameter('kernel.debug'));

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
32
        $config = $this->processConfiguration($configuration, $configs);
33
34
        if (!isset($config['definitions']['extensions']['namespaces']['bundles']['aliases']['GraphQLBundle'])) {
35
            $config['definitions']['extensions']['namespaces']['bundles']['aliases']['GraphQLBundle'] = 'AppBundle';
36
        }
37
38
        $container->setParameter('graphql.config', $config);
39
        if (isset($config['definitions']['extensions'])) {
40
            foreach ($config['definitions']['extensions'] as $extension => $extConfig) {
41
                $extConfig = isset($extConfig['enabled']) && $extConfig['enabled'] ? $extConfig : [];
42
                $container->setParameter('graphql.extension_config.'.$extension, $extConfig ?? []);
43
            }
44
        }
45
46
        $container->setParameter('graphql.cors_config', $config['cors'] ?? []);
47
        $container->setParameter('graphql.graphiql', $config['graphiql'] ?? []);
48
        $container->setParameter('graphql.graphiql_auth_jwt', $config['graphiql']['authentication']['provider']['jwt'] ?? []);
49
50
        $graphiQLAuthProvider = null;
51
        if ($config['graphiql']['authentication']['provider']['jwt']['enabled'] ?? false) {
52
            $graphiQLAuthProvider = JWTGraphiQLAuthentication::class;
53
        }
54
        if ($config['graphiql']['authentication']['provider']['custom'] ?? false) {
55
            $graphiQLAuthProvider = $config['graphiql']['authentication']['provider']['custom'];
56
        }
57
        $container->setParameter('graphql.graphiql_auth_provider', $graphiQLAuthProvider);
58
59
        $configDir = __DIR__.'/../Resources/config';
60
        $loader = new YamlFileLoader($container, new FileLocator($configDir));
61
        $loader->load('services.yml');
62
63
        if (!$container->getParameter('kernel.debug')) {
64
            $container->getDefinition(DefinitionCacheWarmer::class)->clearTag('kernel.event_subscriber');
65
        }
66
    }
67
68
    /**
69
     * {@inheritDoc}
70
     */
71
    public function getAlias()
72
    {
73
        return 'graphql';
74
    }
75
}
76