GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( db31ee...a5f74a )
by Anderson
05:41
created

MappingHelper::patchMappings()   C

Complexity

Conditions 11
Paths 14

Size

Total Lines 38
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 38
rs 5.2653
c 0
b 0
f 0
cc 11
eloc 19
nc 14
nop 2

How to fix   Complexity   

Long Method

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:

1
<?php
2
3
4
namespace DoctrineElastic\Helper;
5
6
/**
7
 * Class MappingHelper
8
 * @author Andsalves <[email protected]>
9
 */
10
class MappingHelper {
11
12
    /**
13
     * Doing some fields mapping modification/adaptation for type/index creation
14
     *
15
     * @param array $mappings
16
     * @param int $elasticRootVersion
17
     * @return array
18
     */
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
}