ORMHelper::processLiteral()   A
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 25
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 14
CRAP Score 4.9586

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
eloc 13
c 1
b 0
f 0
nc 4
nop 2
dl 0
loc 25
ccs 14
cts 23
cp 0.6087
crap 4.9586
rs 9.8333
1
<?php
2
3
namespace ByJG\MicroOrm;
4
5
class ORMHelper
6
{
7
    /**
8
     * @param string $sql
9
     * @param array $params
10
     * @return string
11
     */
12 46
    public static function processLiteral($sql, &$params)
13
    {
14 46
        if (!is_array($params)) {
0 ignored issues
show
introduced by
The condition is_array($params) is always true.
Loading history...
15 6
            return $sql;
16
        }
17
18 42
        foreach ($params as $field => $param) {
19 38
            if ($param instanceof Literal) {
20 12
                $literalValue = $param->getLiteralValue();
21 12
                $sql = preg_replace(
22
                    [
23 12
                        "/\\[\\[$field\\]\\]/",
24 12
                        "/:$field([^\\d\\w]|$)/"
25
                    ],
26
                    [
27 12
                        $literalValue,
28 12
                        "$literalValue\$1"
29
                    ],
30 12
                    $sql
31
                );
32 38
                unset($params[$field]);
33
            }
34
        }
35
36 42
        return $sql;
37
    }
38
}
39