GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Passed
Push — master ( cc39b3...2b121f )
by Anton
04:25 queued 01:05
created

AddConsoleCommandPass::process()   F

Complexity

Conditions 19
Paths 587

Size

Total Lines 98
Code Lines 60

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 19
eloc 60
c 2
b 0
f 0
nc 587
nop 1
dl 0
loc 98
rs 0.9236

How to fix   Long Method    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
/*
4
 * This file is part of the Symfony package.
5
 *
6
 * (c) Fabien Potencier <[email protected]>
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 Symfony\Component\Console\DependencyInjection;
13
14
use Symfony\Component\Console\Command\Command;
15
use Symfony\Component\Console\Command\LazyCommand;
16
use Symfony\Component\Console\CommandLoader\ContainerCommandLoader;
17
use Symfony\Component\DependencyInjection\Argument\ServiceClosureArgument;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\Depend...\ServiceClosureArgument was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
18
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\Depend...r\CompilerPassInterface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
19
use Symfony\Component\DependencyInjection\Compiler\ServiceLocatorTagPass;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\Depend...r\ServiceLocatorTagPass was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
20
use Symfony\Component\DependencyInjection\ContainerBuilder;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\Depend...ection\ContainerBuilder was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
21
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\Depend...nvalidArgumentException was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
22
use Symfony\Component\DependencyInjection\Reference;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\DependencyInjection\Reference was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
23
use Symfony\Component\DependencyInjection\TypedReference;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\Depend...njection\TypedReference was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
24
25
/**
26
 * Registers console commands.
27
 *
28
 * @author Grégoire Pineau <[email protected]>
29
 */
30
class AddConsoleCommandPass implements CompilerPassInterface
31
{
32
    public function process(ContainerBuilder $container): void
33
    {
34
        $commandServices = $container->findTaggedServiceIds('console.command', true);
35
        $lazyCommandMap = [];
36
        $lazyCommandRefs = [];
37
        $serviceIds = [];
38
39
        foreach ($commandServices as $id => $tags) {
40
            $definition = $container->getDefinition($id);
41
            $definition->addTag('container.no_preload');
42
            $class = $container->getParameterBag()->resolveValue($definition->getClass());
43
44
            if (isset($tags[0]['command'])) {
45
                $aliases = $tags[0]['command'];
46
            } else {
47
                if (!$r = $container->getReflectionClass($class)) {
48
                    throw new InvalidArgumentException(sprintf('Class "%s" used for service "%s" cannot be found.', $class, $id));
49
                }
50
                if (!$r->isSubclassOf(Command::class)) {
51
                    throw new InvalidArgumentException(sprintf('The service "%s" tagged "%s" must be a subclass of "%s".', $id, 'console.command', Command::class));
52
                }
53
                $aliases = str_replace('%', '%%', $class::getDefaultName() ?? '');
54
            }
55
56
            $aliases = explode('|', $aliases ?? '');
57
            $commandName = array_shift($aliases);
58
59
            if ($isHidden = '' === $commandName) {
60
                $commandName = array_shift($aliases);
61
            }
62
63
            if (null === $commandName) {
64
                if (!$definition->isPublic() || $definition->isPrivate() || $definition->hasTag('container.private')) {
65
                    $commandId = 'console.command.public_alias.'.$id;
66
                    $container->setAlias($commandId, $id)->setPublic(true);
67
                    $id = $commandId;
68
                }
69
                $serviceIds[] = $id;
70
71
                continue;
72
            }
73
74
            $description = $tags[0]['description'] ?? null;
75
76
            unset($tags[0]);
77
            $lazyCommandMap[$commandName] = $id;
78
            $lazyCommandRefs[$id] = new TypedReference($id, $class);
79
80
            foreach ($aliases as $alias) {
81
                $lazyCommandMap[$alias] = $id;
82
            }
83
84
            foreach ($tags as $tag) {
85
                if (isset($tag['command'])) {
86
                    $aliases[] = $tag['command'];
87
                    $lazyCommandMap[$tag['command']] = $id;
88
                }
89
90
                $description ??= $tag['description'] ?? null;
91
            }
92
93
            $definition->addMethodCall('setName', [$commandName]);
94
95
            if ($aliases) {
96
                $definition->addMethodCall('setAliases', [$aliases]);
97
            }
98
99
            if ($isHidden) {
100
                $definition->addMethodCall('setHidden', [true]);
101
            }
102
103
            if (!$description) {
104
                if (!$r = $container->getReflectionClass($class)) {
105
                    throw new InvalidArgumentException(sprintf('Class "%s" used for service "%s" cannot be found.', $class, $id));
106
                }
107
                if (!$r->isSubclassOf(Command::class)) {
108
                    throw new InvalidArgumentException(sprintf('The service "%s" tagged "%s" must be a subclass of "%s".', $id, 'console.command', Command::class));
109
                }
110
                $description = str_replace('%', '%%', $class::getDefaultDescription() ?? '');
111
            }
112
113
            if ($description) {
114
                $definition->addMethodCall('setDescription', [$description]);
115
116
                $container->register('.'.$id.'.lazy', LazyCommand::class)
117
                    ->setArguments([$commandName, $aliases, $description, $isHidden, new ServiceClosureArgument($lazyCommandRefs[$id])]);
118
119
                $lazyCommandRefs[$id] = new Reference('.'.$id.'.lazy');
120
            }
121
        }
122
123
        $container
124
            ->register('console.command_loader', ContainerCommandLoader::class)
125
            ->setPublic(true)
126
            ->addTag('container.no_preload')
127
            ->setArguments([ServiceLocatorTagPass::register($container, $lazyCommandRefs), $lazyCommandMap]);
128
129
        $container->setParameter('console.command.ids', $serviceIds);
130
    }
131
}
132