Conditions | 11 |
Paths | 14 |
Total Lines | 38 |
Code Lines | 19 |
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 |
||
19 | public static function patchMappings(array $mappings, $elasticRootVersion = 2) { |
||
20 | if (isset($mappings['properties'])) { |
||
21 | $propertiesMapping = $mappings['properties']; |
||
22 | } else { |
||
23 | foreach ($mappings as $key => $mapping) { |
||
24 | if (is_array($mapping)) { |
||
25 | $mappings[$key] = self::patchMappings($mapping, $elasticRootVersion); |
||
26 | } |
||
27 | } |
||
28 | |||
29 | return $mappings; |
||
30 | } |
||
31 | |||
32 | foreach ($propertiesMapping as $fieldName => $fieldMap) { |
||
33 | /** |
||
34 | * Elasticsearch 5.x support patch ('string' type deprecated) |
||
35 | */ |
||
36 | if ($fieldMap['type'] == 'string' && $elasticRootVersion >= 5) { |
||
37 | $propertiesMapping[$fieldName]['type'] = 'keyword'; |
||
38 | } |
||
39 | |||
40 | if (isset($fieldMap['type']) && in_array($fieldMap['type'], ['string', 'text', 'keyword'])) { |
||
41 | continue; |
||
42 | } |
||
43 | |||
44 | if (isset($propertiesMapping[$fieldName]['index'])) { |
||
45 | unset($propertiesMapping[$fieldName]['index']); |
||
46 | } |
||
47 | |||
48 | if (isset($propertiesMapping[$fieldName]['boost'])) { |
||
49 | unset($propertiesMapping[$fieldName]['boost']); |
||
50 | } |
||
51 | } |
||
52 | |||
53 | $mappings['properties'] = $propertiesMapping; |
||
54 | |||
55 | return $mappings; |
||
56 | } |
||
57 | |||
58 | } |