| Conditions | 9 |
| Paths | 18 |
| Total Lines | 62 |
| 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 |
||
| 29 | public function process(ContainerBuilder $container): void |
||
| 30 | { |
||
| 31 | if (!$container->hasDefinition('sonata.notification.dispatcher')) { |
||
| 32 | return; |
||
| 33 | } |
||
| 34 | |||
| 35 | $definition = $container->getDefinition('sonata.notification.dispatcher'); |
||
| 36 | |||
| 37 | $informations = []; |
||
| 38 | |||
| 39 | foreach ($container->findTaggedServiceIds('sonata.notification.consumer') as $id => $events) { |
||
| 40 | $container->getDefinition($id)->setPublic(true); |
||
| 41 | |||
| 42 | foreach ($events as $event) { |
||
| 43 | $priority = $event['priority'] ?? 0; |
||
| 44 | |||
| 45 | if (!isset($event['type'])) { |
||
| 46 | throw new \InvalidArgumentException(sprintf( |
||
| 47 | 'Service "%s" must define the "type" attribute on "sonata.notification" tags.', |
||
| 48 | $id |
||
| 49 | )); |
||
| 50 | } |
||
| 51 | |||
| 52 | if (!isset($informations[$event['type']])) { |
||
| 53 | $informations[$event['type']] = []; |
||
| 54 | } |
||
| 55 | |||
| 56 | $informations[$event['type']][] = $id; |
||
| 57 | |||
| 58 | $definition->addMethodCall( |
||
| 59 | 'addListener', |
||
| 60 | [ |
||
| 61 | $event['type'], |
||
| 62 | [new ServiceClosureArgument(new Reference($id)), 'process'], |
||
| 63 | $priority, |
||
| 64 | ] |
||
| 65 | ); |
||
| 66 | } |
||
| 67 | } |
||
| 68 | |||
| 69 | $container->getDefinition('sonata.notification.consumer.metadata')->replaceArgument(0, $informations); |
||
| 70 | |||
| 71 | if ($container->getParameter('sonata.notification.event.iteration_listeners')) { |
||
| 72 | $ids = $container->getParameter('sonata.notification.event.iteration_listeners'); |
||
| 73 | |||
| 74 | foreach ($ids as $serviceId) { |
||
| 75 | $definition = $container->getDefinition($serviceId); |
||
| 76 | |||
| 77 | $class = new \ReflectionClass($definition->getClass()); |
||
| 78 | if (!$class->implementsInterface(IterationListener::class)) { |
||
| 79 | throw new RuntimeException( |
||
| 80 | 'Iteration listeners must implement Sonata\NotificationBundle\Event\IterationListener' |
||
| 81 | ); |
||
| 82 | } |
||
| 83 | |||
| 84 | $definition->addTag( |
||
| 85 | 'kernel.event_listener', |
||
| 86 | ['event' => IterateEvent::EVENT_NAME, 'method' => 'iterate'] |
||
| 87 | ); |
||
| 88 | } |
||
| 89 | } |
||
| 90 | } |
||
| 91 | } |
||
| 92 |