In::getSql()   A
last analyzed

Complexity

Conditions 4
Paths 8

Size

Total Lines 19
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
eloc 13
c 1
b 0
f 0
nc 8
nop 3
dl 0
loc 19
rs 9.8333
1
<?php
2
namespace Maphper\Lib\Sql;
3
4
class In implements WhereConditional {
5
    public function matches($key, $value, $mode) {
6
        return !is_numeric($key) && is_array($value);
7
    }
8
9
    public function getSql($key, $value, $mode) {
10
        $args = [];
11
        $inSql = [];
12
        $count = count($value);
13
        $value = array_values($value); // fix numeric index being different than $i
14
        for ($i = 0; $i < $count; $i++) {
15
            $args[$key . $i] = $value[$i];
16
            $inSql[] = ':' . $key . $i;
17
        }
18
19
        $notText = '';
20
        if (\Maphper\Maphper::FIND_NOT & $mode) {
21
            $notText = ' NOT';
22
        }
23
24
        if (count($inSql) == 0) return ['args' => [], 'sql' => ''];
25
        else $sql = [$key . $notText . ' IN ( ' .  implode(', ', $inSql) . ')'];
26
27
        return ['args' => $args, 'sql' => $sql];
28
    }
29
}
30