Passed
Push — master ( ecf49a...4e3a77 )
by Joao
02:50 queued 27s
created

ORMHelper::processLiteral()   B

Complexity

Conditions 4
Paths 4

Size

Total Lines 26
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 18
CRAP Score 4

Importance

Changes 0
Metric Value
dl 0
loc 26
ccs 18
cts 18
cp 1
rs 8.5806
c 0
b 0
f 0
cc 4
eloc 14
nc 4
nop 2
crap 4
1
<?php
2
/**
3
 * User: jg
4
 * Date: 19/05/17
5
 * Time: 16:54
6
 */
7
8
namespace ByJG\MicroOrm;
9
10
11
class ORMHelper
12
{
13 27
    public static function processLiteral($sql, &$params)
14
    {
15 27
        if (!is_array($params)) {
16 3
            return $sql;
17
        }
18
19 25
        foreach ($params as $field => $param) {
20 22
            if ($param instanceof Literal) {
21 6
                $literalValue = $param->getLiteralValue();
22 6
                $sql = preg_replace(
23
                    [
24 6
                        "/\\[\\[$field\\]\\]/",
25 6
                        "/:$field([^\\d\\w]|$)/"
26 6
                    ],
27
                    [
28 6
                        $literalValue,
29 6
                        "$literalValue\$1"
30 6
                    ],
31
                    $sql
32 6
                );
33 6
                unset($params[$field]);
34 6
            }
35 25
        }
36
37 25
        return $sql;
38
    }
39
}