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