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