QueryBuilder::where()   A
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 20

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 4

Importance

Changes 0
Metric Value
dl 0
loc 20
ccs 11
cts 11
cp 1
rs 9.6
c 0
b 0
f 0
cc 4
nc 4
nop 2
crap 4
1
<?php
2
3
namespace Reduce\Db\Query;
4
5
use Doctrine\DBAL\Query\QueryBuilder as DBALQueryBuilder;
6
7
class QueryBuilder extends DBALQueryBuilder
8
{
9 6
    public function where($predicate, $value = null)
10
    {
11 6
        if ($value) {
12 5
            $this->andWhere($this->normalizePredicate($predicate));
13 5
            $this->createPositionalParameter($value);
14 5
            return $this;
15
        }
16
        
17 2
        if (is_array($predicate)) {
18 1
            foreach ($predicate as $key => $value) {
19 1
                $this->where($this->normalizePredicate($key), $value);
20
            }
21
22 1
            return $this;
23
        }
24
25 1
        $this->andWhere($predicate);
26
        
27 1
        return $this;
28
    }
29
    
30 5
    protected function normalizePredicate($predicate)
31
    {
32 5
        if (strpos($predicate, '?') === false) {
33 3
            $predicate .= ' = ?';
34
        }
35
        
36 5
        return $predicate;
37
    }
38
}
39