| Conditions | 8 |
| Paths | 64 |
| Total Lines | 61 |
| Code Lines | 37 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 5 | ||
| Bugs | 0 | Features | 2 |
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 |
||
| 98 | public function createManager($managerName, $connection, $managerConfig) |
||
| 99 | { |
||
| 100 | $connection['settings']['analysis'] = $this->metadataCollector |
||
| 101 | ->getManagerAnalysis($managerName, $managerConfig['mappings']); |
||
| 102 | |||
| 103 | if (!isset($connection['settings']['number_of_replicas'])) { |
||
| 104 | $connection['settings']['number_of_replicas'] = 0; |
||
| 105 | } |
||
| 106 | |||
| 107 | if (!isset($connection['settings']['number_of_shards'])) { |
||
| 108 | $connection['settings']['number_of_shards'] = 1; |
||
| 109 | } |
||
| 110 | |||
| 111 | $mappings = $this->metadataCollector->getClientMapping($managerConfig['mappings']); |
||
| 112 | |||
| 113 | $client = ClientBuilder::create(); |
||
| 114 | $client->setHosts($connection['hosts']); |
||
| 115 | $client->setTracer($this->tracer); |
||
| 116 | |||
| 117 | if ($this->logger && $managerConfig['logger']['enabled']) { |
||
| 118 | $client->setLogger($this->logger); |
||
| 119 | } |
||
| 120 | |||
| 121 | $indexSettings = [ |
||
| 122 | 'index' => $connection['index_name'], |
||
| 123 | 'body' => array_filter( |
||
| 124 | [ |
||
| 125 | 'settings' => $connection['settings'], |
||
| 126 | 'mappings' => $mappings, |
||
| 127 | ] |
||
| 128 | ), |
||
| 129 | ]; |
||
| 130 | |||
| 131 | $this->eventDispatcher && |
||
| 132 | $this->eventDispatcher->dispatch( |
||
| 133 | Events::PRE_MANAGER_CREATE, |
||
| 134 | new PreCreateManagerEvent($client, $indexSettings) |
||
| 135 | ); |
||
| 136 | |||
| 137 | $manager = new Manager( |
||
| 138 | $managerName, |
||
| 139 | $managerConfig, |
||
| 140 | $client->build(), |
||
| 141 | $indexSettings, |
||
| 142 | $this->metadataCollector, |
||
| 143 | $this->converter |
||
| 144 | ); |
||
| 145 | |||
| 146 | if (isset($this->stopwatch)) { |
||
| 147 | $manager->setStopwatch($this->stopwatch); |
||
| 148 | } |
||
| 149 | |||
| 150 | $manager->setCommitMode($managerConfig['commit_mode']); |
||
| 151 | $manager->setEventDispatcher($this->eventDispatcher); |
||
| 152 | $manager->setBulkCommitSize($managerConfig['bulk_size']); |
||
| 153 | |||
| 154 | $this->eventDispatcher && |
||
| 155 | $this->eventDispatcher->dispatch(Events::POST_MANAGER_CREATE, new PostCreateManagerEvent($manager)); |
||
| 156 | |||
| 157 | return $manager; |
||
| 158 | } |
||
| 159 | } |
||
| 160 |