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