Conditions | 5 |
Paths | 6 |
Total Lines | 61 |
Code Lines | 33 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
Bugs | 0 | Features | 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 |
||
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 (!isset($connections[$manager['connection']])) { |
||
38 | throw new InvalidConfigurationException( |
||
39 | 'There is no ES connection with the name: ' . $manager['connection'] |
||
40 | ); |
||
41 | } |
||
42 | |||
43 | $managerName = strtolower($managerName); |
||
44 | $connection = $connections[$manager['connection']]; |
||
45 | |||
46 | $managerDefinition = new Definition( |
||
47 | 'ONGR\ElasticsearchBundle\Service\Manager', |
||
48 | [ |
||
49 | $managerName, |
||
50 | $connection, |
||
51 | $analysis, |
||
52 | $manager, |
||
53 | ] |
||
54 | ); |
||
55 | $managerDefinition->setFactory( |
||
56 | [ |
||
57 | new Reference('es.manager_factory'), |
||
58 | 'createManager', |
||
59 | ] |
||
60 | ); |
||
61 | |||
62 | $container->setDefinition(sprintf('es.manager.%s', $managerName), $managerDefinition); |
||
63 | |||
64 | // Make es.manager.default as es.manager service. |
||
65 | if ($managerName === 'default') { |
||
66 | $container->setAlias('es.manager', 'es.manager.default'); |
||
67 | } |
||
68 | |||
69 | $mappings = $collector->getMappings($manager['mappings']); |
||
70 | |||
71 | // Building repository services. |
||
72 | foreach ($mappings as $repositoryType => $repositoryDetails) { |
||
73 | $repositoryDefinition = new Definition( |
||
74 | 'ONGR\ElasticsearchBundle\Service\Repository', |
||
75 | [$repositoryDetails['namespace']] |
||
76 | ); |
||
77 | $repositoryDefinition->setFactory( |
||
78 | [ |
||
79 | new Reference(sprintf('es.manager.%s', $managerName)), |
||
80 | 'getRepository', |
||
81 | ] |
||
82 | ); |
||
83 | |||
84 | $repositoryId = sprintf('es.manager.%s.%s', $managerName, $repositoryType); |
||
85 | $container->setDefinition($repositoryId, $repositoryDefinition); |
||
86 | } |
||
87 | } |
||
88 | } |
||
89 | } |
||
90 |