Conditions | 8 |
Paths | 18 |
Total Lines | 75 |
Code Lines | 42 |
Lines | 0 |
Ratio | 0 % |
Changes | 4 | ||
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 | if (isset($connection['auth'])) { |
||
50 | trigger_error( |
||
51 | '`auth` usage in elasticsearch bundle configuration is deprecated, ' . |
||
52 | 'add your auth configuration directly in the host. This will be removed in v3.0. More: ' . |
||
53 | 'https://www.elastic.co/guide/en/elasticsearch/client/php-api/2.0/_security.html', |
||
54 | E_USER_DEPRECATED |
||
55 | ); |
||
56 | } |
||
57 | |||
58 | $managerName = strtolower($managerName); |
||
59 | |||
60 | $managerDefinition = new Definition( |
||
61 | 'ONGR\ElasticsearchBundle\Service\Manager', |
||
62 | [ |
||
63 | $managerName, |
||
64 | $connection, |
||
65 | $analysis, |
||
66 | $manager, |
||
67 | ] |
||
68 | ); |
||
69 | $managerDefinition->setFactory( |
||
70 | [ |
||
71 | new Reference('es.manager_factory'), |
||
72 | 'createManager', |
||
73 | ] |
||
74 | ); |
||
75 | |||
76 | $container->setDefinition(sprintf('es.manager.%s', $managerName), $managerDefinition); |
||
77 | |||
78 | // Make es.manager.default as es.manager service. |
||
79 | if ($managerName === 'default') { |
||
80 | $container->setAlias('es.manager', 'es.manager.default'); |
||
81 | } |
||
82 | |||
83 | $mappings = $collector->getMappings($manager['mappings']); |
||
84 | |||
85 | // Building repository services. |
||
86 | foreach ($mappings as $repositoryType => $repositoryDetails) { |
||
87 | $repositoryDefinition = new Definition( |
||
88 | 'ONGR\ElasticsearchBundle\Service\Repository', |
||
89 | [$repositoryDetails['namespace']] |
||
90 | ); |
||
91 | $repositoryDefinition->setFactory( |
||
92 | [ |
||
93 | new Reference(sprintf('es.manager.%s', $managerName)), |
||
94 | 'getRepository', |
||
95 | ] |
||
96 | ); |
||
97 | |||
98 | $repositoryId = sprintf('es.manager.%s.%s', $managerName, $repositoryType); |
||
99 | $container->setDefinition($repositoryId, $repositoryDefinition); |
||
100 | } |
||
101 | } |
||
102 | } |
||
103 | } |
||
104 |