Passed
Push — master ( 4a930e...4b35d1 )
by Timo
22:47
created

ParsingUtil   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Test Coverage

Coverage 90.91%

Importance

Changes 0
Metric Value
wmc 4
eloc 12
dl 0
loc 26
ccs 10
cts 11
cp 0.9091
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A getMapArrayFromFlatArray() 0 18 4
1
<?php
2
namespace ApacheSolrForTypo3\Solr\System\Solr;
3
4
/**
5
 * This class provides static helper functions that are helpful during the result parsing for solr.
6
 *
7
 * @package ApacheSolrForTypo3\Solr\System\Solr
8
 */
9
class ParsingUtil
10
{
11
    /**
12
     * This method is used to covert a array structure with json.nl=flat to have it as return with json.nl=map.
13
     *
14
     * @param $options
15
     * @return array
16
     */
17 43
    public static function getMapArrayFromFlatArray(array $options): array
18
    {
19 43
        $keyValueMap = [];
20 43
        $valueFromKeyNode = -1;
21 43
        foreach($options as $key => $value) {
22 40
            $isKeyNode = (($key % 2) == 0);
23 40
            if ($isKeyNode) {
24 40
                $valueFromKeyNode = $value;
25
            } else {
26 40
                if($valueFromKeyNode == -1) {
27
                    throw new \UnexpectedValueException('No optionValue before count value');
28
                }
29
                //we have a countNode
30 40
                $keyValueMap[$valueFromKeyNode] = $value;
31
            }
32
        }
33
34 43
        return $keyValueMap;
35
    }
36
}