Conditions | 4 |
Paths | 5 |
Total Lines | 52 |
Code Lines | 27 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 1 |
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 |
||
27 | public function process(ContainerBuilder $container) |
||
28 | { |
||
29 | $managers = $container->getParameter('es.managers'); |
||
30 | |||
31 | $collector = $container->get('es.metadata_collector'); |
||
32 | |||
33 | foreach ($managers as $managerName => $manager) { |
||
34 | $connection = $manager['index']; |
||
35 | $managerName = strtolower($managerName); |
||
36 | |||
37 | $managerDefinition = new Definition( |
||
38 | 'ONGR\ElasticsearchBundle\Service\Manager', |
||
39 | [ |
||
40 | $managerName, |
||
41 | $connection, |
||
42 | $manager, |
||
43 | ] |
||
44 | ); |
||
45 | $managerDefinition->setFactory( |
||
46 | [ |
||
47 | new Reference('es.manager_factory'), |
||
48 | 'createManager', |
||
49 | ] |
||
50 | ); |
||
51 | |||
52 | $container->setDefinition(sprintf('es.manager.%s', $managerName), $managerDefinition); |
||
53 | |||
54 | // Make es.manager.default as es.manager service. |
||
55 | if ($managerName === 'default') { |
||
56 | $container->setAlias('es.manager', 'es.manager.default'); |
||
57 | } |
||
58 | |||
59 | $mappings = $collector->getMappings($manager['mappings']); |
||
60 | |||
61 | // Building repository services. |
||
62 | foreach ($mappings as $repositoryType => $repositoryDetails) { |
||
63 | $repositoryDefinition = new Definition( |
||
64 | 'ONGR\ElasticsearchBundle\Service\Repository', |
||
65 | [$repositoryDetails['namespace']] |
||
66 | ); |
||
67 | $repositoryDefinition->setFactory( |
||
68 | [ |
||
69 | new Reference(sprintf('es.manager.%s', $managerName)), |
||
70 | 'getRepository', |
||
71 | ] |
||
72 | ); |
||
73 | |||
74 | $repositoryId = sprintf('es.manager.%s.%s', $managerName, $repositoryType); |
||
75 | $container->setDefinition($repositoryId, $repositoryDefinition); |
||
76 | } |
||
77 | } |
||
78 | } |
||
79 | } |
||
80 |