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