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
08:23
created

IdentifyCallbackServiceIdsPass::process()   B

Complexity

Conditions 10
Paths 13

Size

Total Lines 30
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 18
CRAP Score 10.0145

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
ccs 18
cts 19
cp 0.9474
crap 10.0145
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 38
    public function process(ContainerBuilder $container): void
18
    {
19 38
        if (!$container->hasParameter('overblog_graphql_types.config')) {
20
            return;
21
        }
22
        /** @var array $configs */
23 38
        $configs = $container->getParameter('overblog_graphql_types.config');
24 38
        foreach ($configs as &$typeConfig) {
25 37
            switch ($typeConfig['type']) {
26 37
                case 'object':
27 37
                    if (isset($typeConfig['config']['fieldResolver'])) {
28 2
                        $this->resolveServiceIdAndMethod($container, $typeConfig['config']['fieldResolver']);
29
                    }
30
31 37
                    foreach ($typeConfig['config']['fields'] as &$field) {
32 37
                        if (isset($field['resolver'])) {
33 30
                            $this->resolveServiceIdAndMethod($container, $field['resolver']);
34
                        }
35
                    }
36 37
                    break;
37
38 13
                case 'interface':
39 12
                case 'union':
40 5
                    if (isset($typeConfig['config']['typeResolver'])) {
41 3
                        $this->resolveServiceIdAndMethod($container, $typeConfig['config']['typeResolver']);
42
                    }
43 5
                    break;
44
            }
45
        }
46 38
        $container->setParameter('overblog_graphql_types.config', $configs);
47 38
    }
48
49 31
    private function resolveServiceIdAndMethod(ContainerBuilder $container, ?array &$callback): void
50
    {
51 31
        if (!isset($callback['id']) && !isset($callback['method'])) {
52 30
            return;
53
        }
54 8
        $originalId = $callback['id'] ?? null;
55 8
        $originalMethod = $callback['method'] ?? null;
56
57 8
        if (null === $originalId) {
58 8
            [$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 8
            $throw = false;
60
        } else {
61 7
            $id = $originalId;
62 7
            $method = $originalMethod;
63 7
            $throw = true;
64
        }
65
66
        try {
67 8
            $definition = $container->getDefinition($id);
68 8
        } catch (ServiceNotFoundException $e) {
69
            // get Alias real service ID
70
            try {
71 8
                $alias = $container->getAlias($id);
72 7
                $id = (string) $alias;
73 7
                $definition = $container->getDefinition($id);
74 1
            } catch (ServiceNotFoundException | InvalidArgumentException $e) {
75 1
                if ($throw) {
76
                    throw $e;
77
                }
78 1
                $callback['id'] = null;
79 1
                $callback['method'] = $originalMethod;
80
81 1
                return;
82
            }
83
        }
84
        if (
85 7
            !$definition->hasTag('overblog_graphql.service')
86 7
            && !$definition->hasTag('overblog_graphql.global_variable')
87
        ) {
88 7
            $definition->addTag('overblog_graphql.service');
89
        }
90
91 7
        $callback['id'] = $id;
92 7
        $callback['method'] = $method;
93 7
    }
94
}
95