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
Push — master ( 8554cb...ac4e13 )
by Jérémiah
16:31
created

AliasedPass::guessTagName()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 12
ccs 7
cts 7
cp 1
rs 9.4285
cc 3
eloc 7
nc 3
nop 1
crap 3
1
<?php
2
3
namespace Overblog\GraphQLBundle\DependencyInjection\Compiler;
4
5
use Overblog\GraphQLBundle\Definition\Resolver\AliasedInterface;
6
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
7
use Symfony\Component\DependencyInjection\ContainerBuilder;
8
use Symfony\Component\DependencyInjection\Definition;
9
10
final class AliasedPass implements CompilerPassInterface
11
{
12
    /**
13
     * {@inheritdoc}
14
     */
15 23
    public function process(ContainerBuilder $container)
16
    {
17 23
        $definitions = $this->filterDefinitions($container->getDefinitions());
18 23
        foreach ($definitions as $definition) {
19 23
            $this->addDefinitionTagsFromAliases($definition);
20
        }
21 23
    }
22
23
    /**
24
     * @param Definition[] $definitions
25
     *
26
     * @return Definition[]
27
     */
28
    private function filterDefinitions($definitions)
29
    {
30 23
        return array_filter($definitions, function (Definition $definition) {
31 23
            foreach (AutoMappingPass::SERVICE_SUBCLASS_TAG_MAPPING as $tagName) {
32 23
                if ($definition->hasTag($tagName)) {
33 23
                    return is_subclass_of($definition->getClass(), AliasedInterface::class);
0 ignored issues
show
Bug introduced by
Due to PHP Bug #53727, is_subclass_of might return inconsistent results on some PHP versions if \Overblog\GraphQLBundle\...AliasedInterface::class can be an interface. If so, you could instead use ReflectionClass::implementsInterface.
Loading history...
34
                }
35
            }
36
37 23
            return false;
38 23
        });
39
    }
40
41
    /**
42
     * @param Definition $definition
43
     */
44 23
    private function addDefinitionTagsFromAliases(Definition $definition)
45
    {
46 23
        $aliases = call_user_func([$definition->getClass(), 'getAliases']);
47 23
        $tagName = $this->guessTagName($definition);
48 23
        $withMethod = TypeTaggedServiceMappingPass::TAG_NAME !== $tagName;
49
50 23
        foreach ($aliases as $key => $alias) {
51 23
            $definition->addTag($tagName, $withMethod ? ['alias' => $alias, 'method' => $key] : ['alias' => $alias]);
52
        }
53 23
    }
54
55 23
    private function guessTagName(Definition $definition)
56
    {
57 23
        $tagName = null;
58 23
        foreach (AutoMappingPass::SERVICE_SUBCLASS_TAG_MAPPING as $refClassName => $tag) {
59 23
            if (is_subclass_of($definition->getClass(), $refClassName)) {
0 ignored issues
show
Bug introduced by
Due to PHP Bug #53727, is_subclass_of might return inconsistent results on some PHP versions if $refClassName can be an interface. If so, you could instead use ReflectionClass::implementsInterface.
Loading history...
60 23
                $tagName = $tag;
61 23
                break;
62
            }
63
        }
64
65 23
        return $tagName;
66
    }
67
}
68