| Conditions | 10 |
| Paths | 27 |
| Total Lines | 45 |
| Code Lines | 23 |
| 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 | if (!$container->hasDefinition('sonata.notification.dispatcher')) { |
||
| 27 | return; |
||
| 28 | } |
||
| 29 | |||
| 30 | $definition = $container->getDefinition('sonata.notification.dispatcher'); |
||
| 31 | |||
| 32 | $informations = array(); |
||
| 33 | |||
| 34 | foreach ($container->findTaggedServiceIds('sonata.notification.consumer') as $id => $events) { |
||
| 35 | foreach ($events as $event) { |
||
| 36 | $priority = isset($event['priority']) ? $event['priority'] : 0; |
||
| 37 | |||
| 38 | if (!isset($event['type'])) { |
||
| 39 | throw new \InvalidArgumentException(sprintf('Service "%s" must define the "type" attribute on "sonata.notification" tags.', $id)); |
||
| 40 | } |
||
| 41 | |||
| 42 | if (!isset($informations[$event['type']])) { |
||
| 43 | $informations[$event['type']] = array(); |
||
| 44 | } |
||
| 45 | |||
| 46 | $informations[$event['type']][] = $id; |
||
| 47 | |||
| 48 | $definition->addMethodCall('addListenerService', array($event['type'], array($id, 'process'), $priority)); |
||
| 49 | } |
||
| 50 | } |
||
| 51 | |||
| 52 | $container->getDefinition('sonata.notification.consumer.metadata')->replaceArgument(0, $informations); |
||
| 53 | |||
| 54 | if ($container->getParameter('sonata.notification.event.iteration_listeners')) { |
||
| 55 | $ids = $container->getParameter('sonata.notification.event.iteration_listeners'); |
||
| 56 | |||
| 57 | foreach ($ids as $serviceId) { |
||
| 58 | $definition = $container->getDefinition($serviceId); |
||
| 59 | |||
| 60 | $class = new \ReflectionClass($definition->getClass()); |
||
| 61 | if (!$class->implementsInterface('Sonata\NotificationBundle\Event\IterationListener')) { |
||
| 62 | throw new RuntimeException('Iteration listeners must implement Sonata\NotificationBundle\Event\IterationListener'); |
||
| 63 | } |
||
| 64 | |||
| 65 | $definition->addTag('kernel.event_listener', array('event' => IterateEvent::EVENT_NAME, 'method' => 'iterate')); |
||
| 66 | } |
||
| 67 | } |
||
| 68 | } |
||
| 69 | } |
||
| 70 |