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   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 11
lcom 0
cbo 0
dl 0
loc 49
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
C patchMappings() 0 38 11
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
}