Conditions | 18 |
Paths | 140 |
Total Lines | 67 |
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 |
||
20 | public function process(ContainerBuilder $container) |
||
21 | { |
||
22 | $resolvers = $container->findTaggedServiceIds('doctrine.orm.entity_listener'); |
||
23 | |||
24 | $lazyServiceReferencesByResolver = []; |
||
25 | |||
26 | foreach ($resolvers as $id => $tagAttributes) { |
||
27 | foreach ($tagAttributes as $attributes) { |
||
28 | $name = isset($attributes['entity_manager']) ? $attributes['entity_manager'] : $container->getParameter('doctrine.default_entity_manager'); |
||
29 | $entityManager = sprintf('doctrine.orm.%s_entity_manager', $name); |
||
30 | |||
31 | if (! $container->hasDefinition($entityManager)) { |
||
32 | continue; |
||
33 | } |
||
34 | |||
35 | $resolverId = sprintf('doctrine.orm.%s_entity_listener_resolver', $name); |
||
36 | |||
37 | if (! $container->has($resolverId)) { |
||
38 | continue; |
||
39 | } |
||
40 | |||
41 | $resolver = $container->findDefinition($resolverId); |
||
42 | $resolver->setPublic(true); |
||
43 | |||
44 | if (isset($attributes['entity']) && isset($attributes['event'])) { |
||
45 | $this->attachToListener($container, $name, $id, $attributes); |
||
46 | } |
||
47 | |||
48 | $class = $resolver->getClass(); |
||
49 | |||
50 | if (substr($class, 0, 1) === '%') { |
||
51 | // resolve container parameter first |
||
52 | $class = $container->getParameterBag()->resolveValue($resolver->getClass()); |
||
53 | } |
||
54 | $resolverSupportsLazyListeners = is_a($class, EntityListenerServiceResolver::class, true); |
||
55 | |||
56 | $lazyByAttribute = isset($attributes['lazy']) && $attributes['lazy']; |
||
57 | if ($lazyByAttribute && ! $resolverSupportsLazyListeners) { |
||
58 | throw new InvalidArgumentException(sprintf( |
||
59 | 'Lazy-loaded entity listeners can only be resolved by a resolver implementing %s.', |
||
60 | EntityListenerServiceResolver::class |
||
61 | )); |
||
62 | } |
||
63 | |||
64 | if (! isset($attributes['lazy']) && $resolverSupportsLazyListeners || $lazyByAttribute) { |
||
65 | $listener = $container->findDefinition($id); |
||
66 | |||
67 | if ($listener->isAbstract()) { |
||
68 | throw new InvalidArgumentException(sprintf('The service "%s" must not be abstract as this entity listener is lazy-loaded.', $id)); |
||
69 | } |
||
70 | |||
71 | $resolver->addMethodCall('registerService', [$listener->getClass(), $id]); |
||
72 | |||
73 | if (! isset($lazyServiceReferencesByResolver[$resolverId])) { |
||
74 | $lazyServiceReferencesByResolver[$resolverId] = []; |
||
75 | } |
||
76 | $lazyServiceReferencesByResolver[$resolverId][$id] = new Reference($id); |
||
77 | } else { |
||
78 | $resolver->addMethodCall('register', [new Reference($id)]); |
||
79 | } |
||
80 | } |
||
81 | } |
||
82 | |||
83 | foreach ($lazyServiceReferencesByResolver as $resolverId => $listenerReferences) { |
||
84 | $container->findDefinition($resolverId)->replaceArgument(0, ServiceLocatorTagPass::register($container, $listenerReferences)); |
||
85 | } |
||
86 | } |
||
87 | |||
111 |