| Conditions | 8 |
| Paths | 26 |
| Total Lines | 55 |
| Code Lines | 30 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
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 declare(strict_types=1); |
||
| 109 | private function createNewFieldsInIndices(array $newCreatedFields): void |
||
| 110 | { |
||
| 111 | $indices = $this->indexDetector->getAllUsedIndices(); |
||
| 112 | |||
| 113 | $enabledMultilingualIndex = $this->elasticsearchHelper->enabledMultilingualIndex(); |
||
|
|
|||
| 114 | $languageIds = $enabledMultilingualIndex ? $this->connection->fetchFirstColumn('SELECT LOWER(HEX(`id`)) FROM language') : []; |
||
| 115 | |||
| 116 | foreach ($indices as $indexName) { |
||
| 117 | // Check if index is old language based index |
||
| 118 | $isLanguageBasedIndex = true; |
||
| 119 | |||
| 120 | $body = [ |
||
| 121 | 'properties' => [ |
||
| 122 | 'customFields' => [ |
||
| 123 | 'properties' => [], |
||
| 124 | ], |
||
| 125 | ], |
||
| 126 | ]; |
||
| 127 | |||
| 128 | // @deprecated tag:v6.6.0 - Remove this check as old language based indexes will be removed |
||
| 129 | foreach ($languageIds as $languageId) { |
||
| 130 | if (str_contains($indexName, $languageId)) { |
||
| 131 | $isLanguageBasedIndex = true; |
||
| 132 | |||
| 133 | break; |
||
| 134 | } |
||
| 135 | |||
| 136 | $isLanguageBasedIndex = false; |
||
| 137 | } |
||
| 138 | |||
| 139 | if ($isLanguageBasedIndex) { |
||
| 140 | $body['properties']['customFields']['properties'] = $newCreatedFields; |
||
| 141 | } else { |
||
| 142 | foreach ($languageIds as $languageId) { |
||
| 143 | $body['properties']['customFields']['properties'][$languageId] = [ |
||
| 144 | 'type' => 'object', |
||
| 145 | 'dynamic' => true, |
||
| 146 | 'properties' => $newCreatedFields, |
||
| 147 | ]; |
||
| 148 | } |
||
| 149 | } |
||
| 150 | |||
| 151 | // For some reason, we need to include the includes to prevent merge conflicts. |
||
| 152 | // This error can happen for example after updating from version <6.4. |
||
| 153 | $current = $this->client->indices()->get(['index' => $indexName]); |
||
| 154 | $includes = $current[$indexName]['mappings']['_source']['includes'] ?? []; |
||
| 155 | if ($includes !== []) { |
||
| 156 | $body['_source'] = [ |
||
| 157 | 'includes' => $includes, |
||
| 158 | ]; |
||
| 159 | } |
||
| 160 | |||
| 161 | $this->client->indices()->putMapping([ |
||
| 162 | 'index' => $indexName, |
||
| 163 | 'body' => $body, |
||
| 164 | ]); |
||
| 168 |
This function has been deprecated. The supplier of the function has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.