| Conditions | 10 | 
| Paths | 27 | 
| Total Lines | 60 | 
| Code Lines | 33 | 
| 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( | ||
| 40 | 'Service "%s" must define the "type" attribute on "sonata.notification" tags.', | ||
| 41 | $id | ||
| 42 | )); | ||
| 43 | } | ||
| 44 | |||
| 45 |                 if (!isset($informations[$event['type']])) { | ||
| 46 | $informations[$event['type']] = array(); | ||
| 47 | } | ||
| 48 | |||
| 49 | $informations[$event['type']][] = $id; | ||
| 50 | |||
| 51 | $definition->addMethodCall( | ||
| 52 | 'addListenerService', | ||
| 53 | array( | ||
| 54 | $event['type'], | ||
| 55 | array($id, 'process'), | ||
| 56 | $priority, | ||
| 57 | ) | ||
| 58 | ); | ||
| 59 | } | ||
| 60 | } | ||
| 61 | |||
| 62 |         $container->getDefinition('sonata.notification.consumer.metadata')->replaceArgument(0, $informations); | ||
| 63 | |||
| 64 |         if ($container->getParameter('sonata.notification.event.iteration_listeners')) { | ||
| 65 |             $ids = $container->getParameter('sonata.notification.event.iteration_listeners'); | ||
| 66 | |||
| 67 |             foreach ($ids as $serviceId) { | ||
| 68 | $definition = $container->getDefinition($serviceId); | ||
| 69 | |||
| 70 | $class = new \ReflectionClass($definition->getClass()); | ||
| 71 |                 if (!$class->implementsInterface('Sonata\NotificationBundle\Event\IterationListener')) { | ||
| 72 | throw new RuntimeException( | ||
| 73 | 'Iteration listeners must implement Sonata\NotificationBundle\Event\IterationListener' | ||
| 74 | ); | ||
| 75 | } | ||
| 76 | |||
| 77 | $definition->addTag( | ||
| 78 | 'kernel.event_listener', | ||
| 79 |                     array('event' => IterateEvent::EVENT_NAME, 'method' => 'iterate') | ||
| 80 | ); | ||
| 81 | } | ||
| 82 | } | ||
| 83 | } | ||
| 84 | } | ||
| 85 |