Conditions | 7 |
Paths | 10 |
Total Lines | 66 |
Code Lines | 36 |
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 |
||
28 | public function process(ContainerBuilder $container) |
||
29 | { |
||
30 | $analysis = $container->getParameter('es.analysis'); |
||
31 | $connections = $container->getParameter('es.connections'); |
||
32 | $managers = $container->getParameter('es.managers'); |
||
33 | |||
34 | $collector = $container->get('es.metadata_collector'); |
||
35 | |||
36 | foreach ($managers as $managerName => $manager) { |
||
37 | if (!empty($manager['index'])) { |
||
38 | $connection = $manager['index']; |
||
39 | } else { |
||
40 | if (!isset($manager['connection']) || !isset($connections[$manager['connection']])) { |
||
41 | throw new InvalidConfigurationException( |
||
42 | 'There is an error in the ES connection configuration of the manager: ' . $managerName |
||
43 | ); |
||
44 | } |
||
45 | |||
46 | $connection = $connections[$manager['connection']]; |
||
47 | } |
||
48 | |||
49 | $managerName = strtolower($managerName); |
||
50 | |||
51 | $managerDefinition = new Definition( |
||
52 | 'ONGR\ElasticsearchBundle\Service\Manager', |
||
53 | [ |
||
54 | $managerName, |
||
55 | $connection, |
||
56 | $analysis, |
||
57 | $manager, |
||
58 | ] |
||
59 | ); |
||
60 | $managerDefinition->setFactory( |
||
61 | [ |
||
62 | new Reference('es.manager_factory'), |
||
63 | 'createManager', |
||
64 | ] |
||
65 | ); |
||
66 | |||
67 | $container->setDefinition(sprintf('es.manager.%s', $managerName), $managerDefinition); |
||
68 | |||
69 | // Make es.manager.default as es.manager service. |
||
70 | if ($managerName === 'default') { |
||
71 | $container->setAlias('es.manager', 'es.manager.default'); |
||
72 | } |
||
73 | |||
74 | $mappings = $collector->getMappings($manager['mappings']); |
||
75 | |||
76 | // Building repository services. |
||
77 | foreach ($mappings as $repositoryType => $repositoryDetails) { |
||
78 | $repositoryDefinition = new Definition( |
||
79 | 'ONGR\ElasticsearchBundle\Service\Repository', |
||
80 | [$repositoryDetails['namespace']] |
||
81 | ); |
||
82 | $repositoryDefinition->setFactory( |
||
83 | [ |
||
84 | new Reference(sprintf('es.manager.%s', $managerName)), |
||
85 | 'getRepository', |
||
86 | ] |
||
87 | ); |
||
88 | |||
89 | $repositoryId = sprintf('es.manager.%s.%s', $managerName, $repositoryType); |
||
90 | $container->setDefinition($repositoryId, $repositoryDefinition); |
||
91 | } |
||
92 | } |
||
93 | } |
||
94 | } |
||
95 |