Conditions | 8 |
Paths | 48 |
Total Lines | 56 |
Code Lines | 33 |
Lines | 0 |
Ratio | 0 % |
Changes | 4 | ||
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 |
||
96 | public function createManager($managerName, $connection, $analysis, $managerConfig) |
||
97 | { |
||
98 | foreach (array_keys($analysis) as $analyzerType) { |
||
99 | foreach ($connection['analysis'][$analyzerType] as $name) { |
||
100 | $connection['settings']['analysis'][$analyzerType][$name] = $analysis[$analyzerType][$name]; |
||
101 | } |
||
102 | } |
||
103 | unset($connection['analysis']); |
||
104 | |||
105 | if (!isset($connection['settings']['number_of_replicas'])) { |
||
106 | $connection['settings']['number_of_replicas'] = 0; |
||
107 | } |
||
108 | |||
109 | if (!isset($connection['settings']['number_of_shards'])) { |
||
110 | $connection['settings']['number_of_shards'] = 1; |
||
111 | } |
||
112 | |||
113 | $mappings = $this->metadataCollector->getClientMapping($managerConfig['mappings']); |
||
114 | |||
115 | $client = ClientBuilder::create(); |
||
116 | $client->setHosts($connection['hosts']); |
||
117 | $client->setTracer($this->tracer); |
||
118 | |||
119 | if ($this->logger && $managerConfig['logger']['enabled']) { |
||
120 | $client->setLogger($this->logger); |
||
121 | } |
||
122 | |||
123 | $indexSettings = [ |
||
124 | 'index' => $connection['index_name'], |
||
125 | 'body' => array_filter( |
||
126 | [ |
||
127 | 'settings' => $connection['settings'], |
||
128 | 'mappings' => $mappings, |
||
129 | ] |
||
130 | ), |
||
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->setBulkCommitSize($managerConfig['bulk_size']); |
||
149 | |||
150 | return $manager; |
||
151 | } |
||
152 | } |
||
153 |