| Conditions | 9 |
| Paths | 128 |
| Total Lines | 67 |
| Code Lines | 40 |
| 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 |
||
| 99 | public function createManager($managerName, $connection, $analysis, $managerConfig) |
||
| 100 | { |
||
| 101 | $managerAnalysis = []; |
||
| 102 | $mappings = $this->metadataCollector->getClientMapping($managerConfig['mappings']); |
||
| 103 | |||
| 104 | foreach ($mappings as $type) { |
||
|
|
|||
| 105 | $this->extractAnalysisFromProperties($type['properties'], $analysis, $managerAnalysis); |
||
| 106 | } |
||
| 107 | |||
| 108 | $connection['settings']['analysis'] = array_filter($managerAnalysis); |
||
| 109 | |||
| 110 | if (!isset($connection['settings']['number_of_replicas'])) { |
||
| 111 | $connection['settings']['number_of_replicas'] = 0; |
||
| 112 | } |
||
| 113 | |||
| 114 | if (!isset($connection['settings']['number_of_shards'])) { |
||
| 115 | $connection['settings']['number_of_shards'] = 1; |
||
| 116 | } |
||
| 117 | |||
| 118 | $mappings = $this->metadataCollector->getClientMapping($managerConfig['mappings']); |
||
| 119 | |||
| 120 | $client = ClientBuilder::create(); |
||
| 121 | $client->setHosts($connection['hosts']); |
||
| 122 | $client->setTracer($this->tracer); |
||
| 123 | |||
| 124 | if ($this->logger && $managerConfig['logger']['enabled']) { |
||
| 125 | $client->setLogger($this->logger); |
||
| 126 | } |
||
| 127 | |||
| 128 | $indexSettings = [ |
||
| 129 | 'index' => $connection['index_name'], |
||
| 130 | 'body' => array_filter( |
||
| 131 | [ |
||
| 132 | 'settings' => $connection['settings'], |
||
| 133 | 'mappings' => $mappings, |
||
| 134 | ] |
||
| 135 | ), |
||
| 136 | ]; |
||
| 137 | |||
| 138 | $this->eventDispatcher && |
||
| 139 | $this->eventDispatcher->dispatch( |
||
| 140 | Events::PRE_MANAGER_CREATE, |
||
| 141 | new PreCreateManagerEvent($client, $indexSettings) |
||
| 142 | ); |
||
| 143 | |||
| 144 | $manager = new Manager( |
||
| 145 | $managerName, |
||
| 146 | $managerConfig, |
||
| 147 | $client->build(), |
||
| 148 | $indexSettings, |
||
| 149 | $this->metadataCollector, |
||
| 150 | $this->converter |
||
| 151 | ); |
||
| 152 | |||
| 153 | if (isset($this->stopwatch)) { |
||
| 154 | $manager->setStopwatch($this->stopwatch); |
||
| 155 | } |
||
| 156 | |||
| 157 | $manager->setCommitMode($managerConfig['commit_mode']); |
||
| 158 | $manager->setEventDispatcher($this->eventDispatcher); |
||
| 159 | $manager->setBulkCommitSize($managerConfig['bulk_size']); |
||
| 160 | |||
| 161 | $this->eventDispatcher && |
||
| 162 | $this->eventDispatcher->dispatch(Events::POST_MANAGER_CREATE, new PostCreateManagerEvent($manager)); |
||
| 163 | |||
| 164 | return $manager; |
||
| 165 | } |
||
| 166 | |||
| 221 |
There are different options of fixing this problem.
If you want to be on the safe side, you can add an additional type-check:
If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:
Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.