Conditions | 19 |
Paths | 587 |
Total Lines | 98 |
Code Lines | 60 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
Bugs | 0 | Features | 0 |
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:
If many parameters/temporary variables are present:
1 | <?php |
||
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 | } |
||
132 |
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:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths