Completed
Push — master ( ea9cfc...8dc8d9 )
by Raffael
12:43 queued 03:57
created

QueryTransformer::transform()   B

Complexity

Conditions 6
Paths 6

Size

Total Lines 29

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 42

Importance

Changes 0
Metric Value
dl 0
loc 29
ccs 0
cts 22
cp 0
rs 8.8337
c 0
b 0
f 0
cc 6
nc 6
nop 1
crap 42
1
<?php
2
3
declare(strict_types=1);
4
5
/**
6
 * tubee.io
7
 *
8
 * @copyright   Copryright (c) 2017-2018 gyselroth GmbH (https://gyselroth.com)
9
 * @license     GPL-3.0 https://opensource.org/licenses/GPL-3.0
10
 */
11
12
namespace Tubee\Endpoint\Xml;
13
14
class QueryTransformer
15
{
16
    /**
17
     * Convert mongodb like query to xpath.
18
     */
19
    public static function transform(array $query): string
20
    {
21
        $result = '';
22
23
        foreach ($query as $key => $value) {
24
            switch ($key) {
25
                case '$and':
26
                    //$result .= 'and';
27
                    foreach ($value as $sub) {
28
                        $result .= self::transform($sub);
29
                    }
30
31
                break;
32
                case '$or':
33
                    //$result .= 'or';
34
                    foreach ($value as $sub) {
35
                        $result .= self::transform($sub);
36
                    }
37
38
                break;
39
                default:
40
                    $result .= $key.'="'.$value.'"';
41
42
                break;
43
            }
44
        }
45
46
        return $result;
47
    }
48
}
49