Passed
Push — master ( 71d24f...562277 )
by Richard
01:37
created

Like::getSql()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 3
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
namespace Maphper\Lib\Sql;
3
use Maphper\Maphper;
4
5
class Like implements WhereConditional {
6
    public function matches($key, $value, $mode) {
7
        return (Maphper::FIND_LIKE | Maphper::FIND_STARTS |
8
                Maphper::FIND_ENDS | Maphper::FIND_NOCASE) & $mode;
9
    }
10
11
    public function getSql($key, $value, $mode) {
12
        return [
13
            'sql' => [$key . ' LIKE :' . $key],
14
            'args' => [$key => $this->getValue($value, $mode)]
15
        ];
16
    }
17
18
    private function getValue($value, $mode) {
19
        if ((Maphper::FIND_LIKE | Maphper::FIND_ENDS) & $mode) $value = '%' . $value;
20
        if ((Maphper::FIND_LIKE | Maphper::FIND_STARTS) & $mode) $value .= '%';
21
        return $value;
22
    }
23
}
24