| Conditions | 17 |
| Paths | 84 |
| Total Lines | 64 |
| 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 |
||
| 26 | public function process(ContainerBuilder $container) |
||
| 27 | { |
||
| 28 | $resolvers = $this->findAndSortTaggedServices('doctrine.orm.entity_listener', $container); |
||
| 29 | |||
| 30 | $lazyServiceReferencesByResolver = []; |
||
| 31 | |||
| 32 | foreach ($resolvers as $reference) { |
||
| 33 | $id = $reference->__toString(); |
||
| 34 | foreach ($container->getDefinition($id)->getTag('doctrine.orm.entity_listener') as $attributes) { |
||
| 35 | $name = isset($attributes['entity_manager']) ? $attributes['entity_manager'] : $container->getParameter('doctrine.default_entity_manager'); |
||
| 36 | $entityManager = sprintf('doctrine.orm.%s_entity_manager', $name); |
||
| 37 | |||
| 38 | if (! $container->hasDefinition($entityManager)) { |
||
| 39 | continue; |
||
| 40 | } |
||
| 41 | |||
| 42 | $resolverId = sprintf('doctrine.orm.%s_entity_listener_resolver', $name); |
||
| 43 | |||
| 44 | if (! $container->has($resolverId)) { |
||
| 45 | continue; |
||
| 46 | } |
||
| 47 | |||
| 48 | $resolver = $container->findDefinition($resolverId); |
||
| 49 | $resolver->setPublic(true); |
||
| 50 | |||
| 51 | if (isset($attributes['entity']) && isset($attributes['event'])) { |
||
| 52 | $this->attachToListener($container, $name, $this->getConcreteDefinitionClass($container->findDefinition($id), $container, $id), $attributes); |
||
| 53 | } |
||
| 54 | |||
| 55 | $resolverClass = $this->getResolverClass($resolver, $container, $resolverId); |
||
| 56 | $resolverSupportsLazyListeners = is_a($resolverClass, EntityListenerServiceResolver::class, true); |
||
| 57 | |||
| 58 | $lazyByAttribute = isset($attributes['lazy']) && $attributes['lazy']; |
||
| 59 | if ($lazyByAttribute && ! $resolverSupportsLazyListeners) { |
||
| 60 | throw new InvalidArgumentException(sprintf( |
||
| 61 | 'Lazy-loaded entity listeners can only be resolved by a resolver implementing %s.', |
||
| 62 | EntityListenerServiceResolver::class |
||
| 63 | )); |
||
| 64 | } |
||
| 65 | |||
| 66 | if (! isset($attributes['lazy']) && $resolverSupportsLazyListeners || $lazyByAttribute) { |
||
| 67 | $listener = $container->findDefinition($id); |
||
| 68 | |||
| 69 | $resolver->addMethodCall('registerService', [$this->getConcreteDefinitionClass($listener, $container, $id), $id]); |
||
| 70 | |||
| 71 | // if the resolver uses the default class we will use a service locator for all listeners |
||
| 72 | if ($resolverClass === ContainerEntityListenerResolver::class) { |
||
| 73 | if (! isset($lazyServiceReferencesByResolver[$resolverId])) { |
||
| 74 | $lazyServiceReferencesByResolver[$resolverId] = []; |
||
| 75 | } |
||
| 76 | $lazyServiceReferencesByResolver[$resolverId][$id] = new Reference($id); |
||
| 77 | } else { |
||
| 78 | $listener->setPublic(true); |
||
| 79 | } |
||
| 80 | } else { |
||
| 81 | $resolver->addMethodCall('register', [new Reference($id)]); |
||
| 82 | } |
||
| 83 | } |
||
| 84 | } |
||
| 85 | |||
| 86 | foreach ($lazyServiceReferencesByResolver as $resolverId => $listenerReferences) { |
||
| 87 | $container->findDefinition($resolverId)->setArgument(0, ServiceLocatorTagPass::register($container, $listenerReferences)); |
||
| 88 | } |
||
| 89 | } |
||
| 90 | |||
| 145 |
In PHP, under loose comparison (like
==, or!=, orswitchconditions), values of different types might be equal.For
stringvalues, the empty string''is a special case, in particular the following results might be unexpected: