Conditions | 11 |
Paths | 19 |
Total Lines | 62 |
Code Lines | 39 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 1 |
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 |
||
28 | public function process(ContainerBuilder $container) |
||
29 | { |
||
30 | $commandServices = $container->findTaggedServiceIds($this->commandTag, true); |
||
31 | $lazyCommandMap = []; |
||
32 | $lazyCommandRefs = []; |
||
33 | $serviceIds = []; |
||
34 | |||
35 | foreach ($commandServices as $id => $tags) { |
||
36 | $definition = $container->getDefinition($id); |
||
37 | $class = $container->getParameterBag()->resolveValue($definition->getClass()); |
||
38 | |||
39 | if (isset($tags[0]['command'])) { |
||
40 | $commandName = $tags[0]['command']; |
||
41 | } else { |
||
42 | if (!$r = $container->getReflectionClass($class)) { |
||
43 | throw new InvalidArgumentException(sprintf('Class "%s" used for service "%s" cannot be found.', $class, $id)); |
||
44 | } |
||
45 | if (!$r->isSubclassOf(Command::class)) { |
||
46 | throw new InvalidArgumentException(sprintf('The service "%s" tagged "%s" must be a subclass of "%s".', $id, $this->commandTag, Command::class)); |
||
47 | } |
||
48 | $commandName = $class::getDefaultName(); |
||
49 | } |
||
50 | |||
51 | // the magic sauce! |
||
52 | $commandName = str_replace('db3v4l:', '', $commandName); |
||
53 | |||
54 | if (null === $commandName) { |
||
55 | if (!$definition->isPublic() || $definition->isPrivate()) { |
||
56 | $commandId = 'dbconsole.command.public_alias.'.$id; |
||
57 | $container->setAlias($commandId, $id)->setPublic(true); |
||
58 | $id = $commandId; |
||
59 | } |
||
60 | $serviceIds[] = $id; |
||
61 | |||
62 | continue; |
||
63 | } |
||
64 | |||
65 | unset($tags[0]); |
||
66 | $lazyCommandMap[$commandName] = $id; |
||
67 | $lazyCommandRefs[$id] = new TypedReference($id, $class); |
||
68 | $aliases = []; |
||
69 | |||
70 | foreach ($tags as $tag) { |
||
71 | if (isset($tag['command'])) { |
||
72 | $aliases[] = $tag['command']; |
||
73 | $lazyCommandMap[$tag['command']] = $id; |
||
74 | } |
||
75 | } |
||
76 | |||
77 | $definition->addMethodCall('setName', [$commandName]); |
||
78 | |||
79 | if ($aliases) { |
||
80 | $definition->addMethodCall('setAliases', [$aliases]); |
||
81 | } |
||
82 | } |
||
83 | |||
84 | $container |
||
85 | ->register($this->commandLoaderServiceId, ContainerCommandLoader::class) |
||
86 | ->setPublic(true) |
||
87 | ->setArguments([ServiceLocatorTagPass::register($container, $lazyCommandRefs), $lazyCommandMap]); |
||
88 | |||
89 | $container->setParameter('dbconsole.command.ids', $serviceIds); |
||
90 | } |
||
92 |