In   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 15
c 1
b 0
f 0
dl 0
loc 24
rs 10
wmc 6

2 Methods

Rating   Name   Duplication   Size   Complexity  
A matches() 0 2 2
A getSql() 0 19 4
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