Passed
Pull Request — master (#14)
by Wilmer
25:49 queued 10:47
created

InConditionBuilder   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 18
dl 0
loc 32
rs 10
c 0
b 0
f 0
wmc 12

2 Methods

Rating   Name   Duplication   Size   Complexity  
A buildSubqueryInCondition() 0 7 2
B buildCompositeInCondition() 0 21 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Db\Mssql\Condition;
6
7
use Yiisoft\Db\Exception\NotSupportedException;
8
use Yiisoft\Db\Query\Conditions\InConditionBuilder as AbstractInConditionBuilder;
9
10
final class InConditionBuilder extends AbstractInConditionBuilder
11
{
12
    protected function buildSubqueryInCondition($operator, $columns, $values, &$params)
13
    {
14
        if (is_array($columns)) {
15
            throw new NotSupportedException(__METHOD__ . ' is not supported by MSSQL.');
16
        }
17
18
        return parent::buildSubqueryInCondition($operator, $columns, $values, $params);
19
    }
20
21
    protected function buildCompositeInCondition($operator, $columns, $values, &$params)
22
    {
23
        $quotedColumns = [];
24
        foreach ($columns as $i => $column) {
25
            $quotedColumns[$i] = strpos($column, '(') === false ? $this->queryBuilder->db->quoteColumnName($column) : $column;
0 ignored issues
show
Bug introduced by
The method quoteColumnName() does not exist on null. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

25
            $quotedColumns[$i] = strpos($column, '(') === false ? $this->queryBuilder->db->/** @scrutinizer ignore-call */ quoteColumnName($column) : $column;

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
Bug introduced by
The property db is declared protected in Yiisoft\Db\Query\QueryBuilder and cannot be accessed from this context.
Loading history...
26
        }
27
        $vss = [];
28
        foreach ($values as $value) {
29
            $vs = [];
30
            foreach ($columns as $i => $column) {
31
                if (isset($value[$column])) {
32
                    $phName = $this->queryBuilder->bindParam($value[$column], $params);
33
                    $vs[] = $quotedColumns[$i] . ($operator === 'IN' ? ' = ' : ' != ') . $phName;
34
                } else {
35
                    $vs[] = $quotedColumns[$i] . ($operator === 'IN' ? ' IS' : ' IS NOT') . ' NULL';
36
                }
37
            }
38
            $vss[] = '(' . implode($operator === 'IN' ? ' AND ' : ' OR ', $vs) . ')';
39
        }
40
41
        return '(' . implode($operator === 'IN' ? ' OR ' : ' AND ', $vss) . ')';
42
    }
43
}
44