Completed
Push — master ( abe227...316baf )
by Raffael
13:55 queued 08:01
created

QueryTransformer::transform()   B

Complexity

Conditions 6
Paths 6

Size

Total Lines 31

Duplication

Lines 31
Ratio 100 %

Code Coverage

Tests 0
CRAP Score 42

Importance

Changes 0
Metric Value
dl 31
loc 31
ccs 0
cts 26
cp 0
rs 8.8017
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-2019 gyselroth GmbH (https://gyselroth.com)
9
 * @license     GPL-3.0 https://opensource.org/licenses/GPL-3.0
10
 */
11
12
namespace Tubee\Endpoint\Ucs;
13
14 View Code Duplication
class QueryTransformer
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
15
{
16
    /**
17
     * Convert mongodb like query to ldap query.
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
                    $result .= ')';
31
32
                break;
33
                case '$or':
34
                    $result .= 'or (';
35
                    foreach ($value as $sub) {
36
                        $result .= self::transform($sub);
37
                    }
38
                    $result .= ')';
39
40
                break;
41
                default:
42
                    $result .= $key.' eq '.'\''.$value.'\'';
43
44
                break;
45
            }
46
        }
47
48
        return $result;
49
    }
50
}
51