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 — 0.14 (#851)
by Jérémiah
47:23 queued 23:20
created

IdentifyCallbackServiceIdsPass::process()   B

Complexity

Conditions 10
Paths 13

Size

Total Lines 30
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 10
eloc 18
c 1
b 0
f 0
nc 13
nop 1
dl 0
loc 30
rs 7.6666

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
declare(strict_types=1);
4
5
namespace Overblog\GraphQLBundle\DependencyInjection\Compiler;
6
7
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
8
use Symfony\Component\DependencyInjection\ContainerBuilder;
9
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
10
use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException;
11
12
final class IdentifyCallbackServiceIdsPass implements CompilerPassInterface
13
{
14
    /**
15
     * {@inheritdoc}
16
     */
17
    public function process(ContainerBuilder $container): void
18
    {
19
        if (!$container->hasParameter('overblog_graphql_types.config')) {
20
            return;
21
        }
22
        /** @var array $configs */
23
        $configs = $container->getParameter('overblog_graphql_types.config');
24
        foreach ($configs as &$typeConfig) {
25
            switch ($typeConfig['type']) {
26
                case 'object':
27
                    if (isset($typeConfig['config']['fieldResolver'])) {
28
                        $this->resolveServiceIdAndMethod($container, $typeConfig['config']['fieldResolver']);
29
                    }
30
31
                    foreach ($typeConfig['config']['fields'] as &$field) {
32
                        if (isset($field['resolver'])) {
33
                            $this->resolveServiceIdAndMethod($container, $field['resolver']);
34
                        }
35
                    }
36
                    break;
37
38
                case 'interface':
39
                case 'union':
40
                    if (isset($typeConfig['config']['typeResolver'])) {
41
                        $this->resolveServiceIdAndMethod($container, $typeConfig['config']['typeResolver']);
42
                    }
43
                    break;
44
            }
45
        }
46
        $container->setParameter('overblog_graphql_types.config', $configs);
47
    }
48
49
    private function resolveServiceIdAndMethod(ContainerBuilder $container, ?array &$callback): void
50
    {
51
        if (!isset($callback['id']) && !isset($callback['method'])) {
52
            return;
53
        }
54
        $originalId = $callback['id'] ?? null;
55
        $originalMethod = $callback['method'] ?? null;
56
57
        if (null === $originalId) {
58
            [$id, $method] = explode('::', $originalMethod, 2) + [null, null];
0 ignored issues
show
Bug introduced by
It seems like $originalMethod can also be of type null; however, parameter $string of explode() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

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

58
            [$id, $method] = explode('::', /** @scrutinizer ignore-type */ $originalMethod, 2) + [null, null];
Loading history...
59
            $throw = false;
60
        } else {
61
            $id = $originalId;
62
            $method = $originalMethod;
63
            $throw = true;
64
        }
65
66
        try {
67
            $definition = $container->getDefinition($id);
68
        } catch (ServiceNotFoundException $e) {
69
            // get Alias real service ID
70
            try {
71
                $alias = $container->getAlias($id);
72
                $id = (string) $alias;
73
                $definition = $container->getDefinition($id);
74
            } catch (ServiceNotFoundException | InvalidArgumentException $e) {
75
                if ($throw) {
76
                    throw $e;
77
                }
78
                $callback['id'] = null;
79
                $callback['method'] = $originalMethod;
80
81
                return;
82
            }
83
        }
84
        if (
85
            !$definition->hasTag('overblog_graphql.service')
86
            && !$definition->hasTag('overblog_graphql.global_variable')
87
        ) {
88
            $definition->addTag('overblog_graphql.service');
89
        }
90
91
        $callback['id'] = $id;
92
        $callback['method'] = $method;
93
    }
94
}
95