Conditions | 8 |
Paths | 48 |
Total Lines | 55 |
Code Lines | 32 |
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 |
||
82 | public function createManager($managerName, $connection, $analysis, $managerConfig) |
||
83 | { |
||
84 | foreach (array_keys($analysis) as $analyzerType) { |
||
85 | foreach ($connection['analysis'][$analyzerType] as $name) { |
||
86 | $connection['settings']['analysis'][$analyzerType][$name] = $analysis[$analyzerType][$name]; |
||
87 | } |
||
88 | } |
||
89 | unset($connection['analysis']); |
||
90 | |||
91 | if (!isset($connection['settings']['number_of_replicas'])) { |
||
92 | $connection['settings']['number_of_replicas'] = 0; |
||
93 | } |
||
94 | |||
95 | if (!isset($connection['settings']['number_of_shards'])) { |
||
96 | $connection['settings']['number_of_shards'] = 1; |
||
97 | } |
||
98 | |||
99 | $mappings = $this->metadataCollector->getClientMapping($managerConfig['mappings']); |
||
100 | |||
101 | $client = ClientBuilder::create(); |
||
102 | $client->setHosts($connection['hosts']); |
||
103 | $client->setTracer($this->tracer); |
||
104 | |||
105 | if ($this->logger && $managerConfig['logger']['enabled']) { |
||
106 | $client->setLogger($this->logger); |
||
107 | } |
||
108 | |||
109 | $indexSettings = [ |
||
110 | 'index' => $connection['index_name'], |
||
111 | 'body' => array_filter( |
||
112 | [ |
||
113 | 'settings' => $connection['settings'], |
||
114 | 'mappings' => $mappings, |
||
115 | ] |
||
116 | ), |
||
117 | ]; |
||
118 | |||
119 | $manager = new Manager( |
||
120 | $managerName, |
||
121 | $managerConfig, |
||
122 | $client->build(), |
||
123 | $indexSettings, |
||
124 | $this->metadataCollector, |
||
125 | $this->converter |
||
126 | ); |
||
127 | |||
128 | if (isset($this->stopwatch)) { |
||
129 | $manager->setStopwatch($this->stopwatch); |
||
130 | } |
||
131 | |||
132 | $manager->setCommitMode($managerConfig['commit_mode']); |
||
133 | $manager->setBulkCommitSize($managerConfig['bulk_size']); |
||
134 | |||
135 | return $manager; |
||
136 | } |
||
137 | } |
||
138 |