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

Completed
Pull Request — 0.12 (#560)
by Jérémiah
24:23
created

ResolverMethodAliasesPass::process()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 3
c 1
b 0
f 0
dl 0
loc 5
rs 10
cc 3
nc 3
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Overblog\GraphQLBundle\DependencyInjection\Compiler;
6
7
use Overblog\GraphQLBundle\Definition\Resolver\AliasedInterface;
8
use Overblog\GraphQLBundle\Definition\Resolver\MutationInterface;
9
use Overblog\GraphQLBundle\Definition\Resolver\ResolverInterface;
10
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
11
use Symfony\Component\DependencyInjection\ContainerBuilder;
12
use Symfony\Component\DependencyInjection\Definition;
13
14
final class ResolverMethodAliasesPass implements CompilerPassInterface
15
{
16
    private const SERVICE_SUBCLASS_TAG_MAPPING = [
17
        MutationInterface::class => 'overblog_graphql.mutation',
18
        ResolverInterface::class => 'overblog_graphql.resolver',
19
    ];
20
21
    /**
22
     * {@inheritdoc}
23
     */
24
    public function process(ContainerBuilder $container): void
25
    {
26
        foreach ($container->getDefinitions() as $definition) {
27
            foreach (self::SERVICE_SUBCLASS_TAG_MAPPING as $tagName) {
28
                $this->addDefinitionTagsFromClassReflection($definition, $tagName);
29
            }
30
        }
31
    }
32
33
    private function addDefinitionTagsFromClassReflection(Definition $definition, string $tagName): void
34
    {
35
        if ($definition->hasTag($tagName)) {
36
            foreach ($definition->getTag($tagName) as $tag => $attributes) {
37
                if (!isset($attributes['method'])) {
38
                    $reflectionClass = new \ReflectionClass($definition->getClass());
39
40
                    if (!$reflectionClass->isAbstract()) {
41
                        $publicReflectionMethods = $reflectionClass->getMethods(\ReflectionMethod::IS_PUBLIC);
42
                        $isAliased = $reflectionClass->implementsInterface(AliasedInterface::class);
43
                        foreach ($publicReflectionMethods as $publicReflectionMethod) {
44
                            if ('__construct' === $publicReflectionMethod->name || $isAliased && 'getAliases' === $publicReflectionMethod->name) {
45
                                continue;
46
                            }
47
                            $definition->addTag($tagName, ['method' => $publicReflectionMethod->name]);
48
                        }
49
                    }
50
                    continue;
51
                }
52
            }
53
        }
54
    }
55
}
56