Conditions | 18 |
Paths | 92 |
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 |
||
23 | public function process(ContainerBuilder $container) |
||
24 | { |
||
25 | $resolvers = $container->findTaggedServiceIds('doctrine.orm.entity_listener'); |
||
26 | |||
27 | $lazyServiceReferencesByResolver = []; |
||
28 | |||
29 | foreach ($resolvers as $id => $tagAttributes) { |
||
30 | foreach ($tagAttributes as $attributes) { |
||
31 | $name = isset($attributes['entity_manager']) ? $attributes['entity_manager'] : $container->getParameter('doctrine.default_entity_manager'); |
||
32 | $entityManager = sprintf('doctrine.orm.%s_entity_manager', $name); |
||
33 | |||
34 | if (! $container->hasDefinition($entityManager)) { |
||
35 | continue; |
||
36 | } |
||
37 | |||
38 | $resolverId = sprintf('doctrine.orm.%s_entity_listener_resolver', $name); |
||
39 | |||
40 | if (! $container->has($resolverId)) { |
||
41 | continue; |
||
42 | } |
||
43 | |||
44 | $resolver = $container->findDefinition($resolverId); |
||
45 | $resolver->setPublic(true); |
||
46 | |||
47 | if (isset($attributes['entity']) && isset($attributes['event'])) { |
||
48 | $this->attachToListener($container, $name, $this->getConcreteDefinitionClass($container->findDefinition($id), $container, $id), $attributes); |
||
49 | } |
||
50 | |||
51 | $resolverClass = $this->getResolverClass($resolver, $container, $resolverId); |
||
52 | $resolverSupportsLazyListeners = is_a($resolverClass, EntityListenerServiceResolver::class, true); |
||
53 | |||
54 | $lazyByAttribute = isset($attributes['lazy']) && $attributes['lazy']; |
||
55 | if ($lazyByAttribute && ! $resolverSupportsLazyListeners) { |
||
56 | throw new InvalidArgumentException(sprintf( |
||
57 | 'Lazy-loaded entity listeners can only be resolved by a resolver implementing %s.', |
||
58 | EntityListenerServiceResolver::class |
||
59 | )); |
||
60 | } |
||
61 | |||
62 | if (! isset($attributes['lazy']) && $resolverSupportsLazyListeners || $lazyByAttribute) { |
||
63 | $listener = $container->findDefinition($id); |
||
64 | |||
65 | if ($listener->isAbstract()) { |
||
66 | throw new InvalidArgumentException(sprintf('The service "%s" must not be abstract as this entity listener is lazy-loaded.', $id)); |
||
67 | } |
||
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!=
, orswitch
conditions), values of different types might be equal.For
string
values, the empty string''
is a special case, in particular the following results might be unexpected: