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

Passed
Pull Request — master (#786)
by Timur
21:54
created

GraphQLServicesPass::process()   B

Complexity

Conditions 8
Paths 14

Size

Total Lines 41
Code Lines 21

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 21
dl 0
loc 41
rs 8.4444
c 1
b 0
f 0
cc 8
nc 14
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Overblog\GraphQLBundle\DependencyInjection\Compiler;
6
7
use InvalidArgumentException;
8
use Overblog\GraphQLBundle\Definition\GraphQLServices;
9
use Overblog\GraphQLBundle\Generator\TypeGenerator;
10
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
11
use Symfony\Component\DependencyInjection\ContainerBuilder;
12
use Symfony\Component\DependencyInjection\Reference;
13
use function is_string;
14
use function sprintf;
15
16
final class GraphQLServicesPass implements CompilerPassInterface
17
{
18
    /**
19
     * {@inheritdoc}
20
     */
21
    public function process(ContainerBuilder $container): void
22
    {
23
        $taggedServices = $container->findTaggedServiceIds('overblog_graphql.service', true);
24
25
        // TODO: remove following if-block in 1.0
26
        // @codeCoverageIgnoreStart
27
        if (count($deprecatedTaggedServices = $container->findTaggedServiceIds('overblog_graphql.global_variable', true)) > 0) {
28
            @trigger_error(
29
                "The tag 'overblog_graphql.global_variable' is deprecated since 0.14 and will be removed in 1.0. Use 'overblog_graphql.service' instead. For more info visit: https://github.com/overblog/GraphQLBundle/issues/775",
30
                E_USER_DEPRECATED
31
            );
32
33
            $taggedServices = array_merge($taggedServices, $deprecatedTaggedServices);
34
        }
35
        // @codeCoverageIgnoreEnd
36
37
        $serviceContainer = ['container' => new Reference('service_container')];
38
        $expressionLanguageDefinition = $container->findDefinition('overblog_graphql.expression_language');
39
40
        foreach ($taggedServices as $id => $tags) {
41
            foreach ($tags as $attributes) {
42
                if (empty($attributes['alias']) || !is_string($attributes['alias'])) {
43
                    throw new InvalidArgumentException(
44
                        sprintf('Service "%s" tagged "overblog_graphql.service" should have a valid "alias" attribute.', $id)
45
                    );
46
                }
47
                $serviceContainer[$attributes['alias']] = new Reference($id);
48
49
                $isPublic = isset($attributes['public']) ? (bool) $attributes['public'] : true;
50
                if ($isPublic) {
51
                    $expressionLanguageDefinition->addMethodCall(
52
                        'addGlobalName',
53
                        [
54
                            sprintf(TypeGenerator::GRAPHQL_SERVICES.'->get(\'%s\')', $attributes['alias']),
55
                            $attributes['alias'],
56
                        ]
57
                    );
58
                }
59
            }
60
        }
61
        $container->findDefinition(GraphQLServices::class)->addArgument($serviceContainer);
62
    }
63
}
64