| Conditions | 12 |
| Paths | 56 |
| Total Lines | 49 |
| Code Lines | 32 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 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 |
||
| 24 | public function process(ContainerBuilder $container) |
||
| 25 | { |
||
| 26 | $ids = $container->getServiceIds(); |
||
| 27 | $commands = array(); |
||
| 28 | $subscribers = array(); |
||
| 29 | foreach ($ids as $id) { |
||
| 30 | $definition = $container->findDefinition($id); |
||
| 31 | $definition |
||
| 32 | ->setPublic(true) |
||
| 33 | ->setAutoconfigured(true) |
||
| 34 | ->setAutowired(true) |
||
| 35 | ; |
||
| 36 | $class = $definition->getClass(); |
||
| 37 | if (!class_exists($class)) { |
||
| 38 | continue; |
||
| 39 | } |
||
| 40 | if (!$container->hasDefinition($class) && class_exists($class)) { |
||
| 41 | if ($class !== $id) { |
||
| 42 | $container |
||
| 43 | ->setAlias($class, $id) |
||
| 44 | ->setPublic(true) |
||
| 45 | ; |
||
| 46 | } |
||
| 47 | } |
||
| 48 | |||
| 49 | $r = new \ReflectionClass($class); |
||
| 50 | if ( |
||
| 51 | $r->implementsInterface(CommandInterface::class) |
||
| 52 | && !in_array($class, $commands) |
||
| 53 | ) { |
||
| 54 | $commands[] = $class; |
||
| 55 | } |
||
| 56 | |||
| 57 | if ( |
||
| 58 | $r->implementsInterface(EventSubscriberInterface::class) |
||
| 59 | && !in_array($class, $subscribers) |
||
| 60 | ) { |
||
| 61 | $subscribers[] = $class; |
||
| 62 | } |
||
| 63 | } |
||
| 64 | |||
| 65 | $application = $container->findDefinition(Application::class); |
||
| 66 | $dispatcher = $container->findDefinition(Dispatcher::class); |
||
| 67 | foreach ($commands as $class) { |
||
| 68 | $application->addMethodCall('add', array(new Reference($class))); |
||
| 69 | } |
||
| 70 | |||
| 71 | foreach ($subscribers as $class) { |
||
| 72 | $dispatcher->addMethodCall('addSubscriber', array(new Reference($class))); |
||
| 73 | } |
||
| 76 |