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 — master (#137)
by Jérémiah
06:26
created

TaggedServiceMappingPass::getParameterName()

Size

Total Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 1
c 0
b 0
f 0
ccs 0
cts 0
cp 0
nc 1
1
<?php
2
3
/*
4
 * This file is part of the OverblogGraphQLBundle package.
5
 *
6
 * (c) Overblog <http://github.com/overblog/>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Overblog\GraphQLBundle\DependencyInjection\Compiler;
13
14
use GraphQL\Type\Definition\Type;
15
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
16
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
17
use Symfony\Component\DependencyInjection\ContainerBuilder;
18
use Symfony\Component\DependencyInjection\Reference;
19
20
abstract class TaggedServiceMappingPass implements CompilerPassInterface
21
{
22 14
    private function getTaggedServiceMapping(ContainerBuilder $container, $tagName)
23
    {
24 14
        $serviceMapping = [];
25
26 14
        $taggedServices = $container->findTaggedServiceIds($tagName);
27
28 14
        foreach ($taggedServices as $id => $tags) {
29 14
            $className = $container->findDefinition($id)->getClass();
30 14
            $isType = is_subclass_of($className, Type::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 \GraphQL\Type\Definition\Type::class can be an interface. If so, you could instead use ReflectionClass::implementsInterface.
Loading history...
31 14
            foreach ($tags as $tag) {
32 14
                $this->checkRequirements($id, $tag);
33 14
                $tag = array_merge($tag, ['id' => $id]);
34 14
                if (!$isType) {
35 14
                    $tag['method'] = isset($tag['method']) ? $tag['method'] : '__invoke';
36 14
                }
37 14
                if (isset($tag['alias'])) {
38 14
                    $serviceMapping[$tag['alias']] = $tag;
39 14
                }
40
41
                // add FQCN alias
42 14
                $alias = $className;
43 14
                if (!$isType && '__invoke' !== $tag['method']) {
44 8
                    $alias .= '::'.$tag['method'];
45 8
                }
46 14
                $tag['alias'] = $alias;
47 14
                $serviceMapping[$tag['alias']] = $tag;
48 14
            }
49 14
        }
50
51 14
        return $serviceMapping;
52
    }
53
54 14
    public function process(ContainerBuilder $container)
55
    {
56 14
        $mapping = $this->getTaggedServiceMapping($container, $this->getTagName());
57 14
        $container->setParameter($this->getParameterName(), $mapping);
58 14
        $resolverDefinition = $container->findDefinition($this->getResolverServiceID());
59
60 14
        foreach ($mapping as $name => $options) {
61 14
            $cleanOptions = $options;
62 14
            $solutionID = $options['id'];
63
64 14
            $solutionDefinition = $container->findDefinition($options['id']);
65
66 14
            $methods = array_map(
67 14
                function ($methodCall) {
68 3
                    return $methodCall[0];
69 14
                },
70 14
                $solutionDefinition->getMethodCalls()
71 14
            );
72
            if (
73 14
                is_subclass_of($solutionDefinition->getClass(), ContainerAwareInterface::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 \Symfony\Component\Depen...erAwareInterface::class can be an interface. If so, you could instead use ReflectionClass::implementsInterface.
Loading history...
74 14
                && !in_array('setContainer', $methods)
75 14
            ) {
76 2
                @trigger_error(
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
77 2
                    'Autowire custom tagged (type, resolver or mutation) services is deprecated as of 0.9 and will be removed in 1.0. Use AutoMapping or set it manually instead.',
78
                    E_USER_DEPRECATED
79 2
                );
80 2
                $solutionDefinition->addMethodCall('setContainer', [new Reference('service_container')]);
81 2
            }
82
83 14
            $resolverDefinition->addMethodCall('addSolution', [$name, new Reference($solutionID), $cleanOptions]);
84 14
        }
85 14
    }
86
87 14
    protected function checkRequirements($id, array $tag)
88
    {
89 14 View Code Duplication
        if (isset($tag['alias']) && !is_string($tag['alias'])) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
90
            throw new \InvalidArgumentException(
91
                sprintf('Service tagged "%s" must have valid "alias" argument.', $id)
92
            );
93
        }
94 14
    }
95
96
    abstract protected function getTagName();
97
98
    abstract protected function getResolverServiceID();
99
100
    abstract protected function getParameterName();
101
}
102