Passed
Push — master ( b7f728...dee1f4 )
by Edgard
18:46
created

InConditionBuilder::buildCompositeInCondition()   C

Complexity

Conditions 10
Paths 18

Size

Total Lines 22
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 22
rs 6.1368
cc 10
eloc 15
nc 18
nop 4

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
/**
3
 * @link http://www.yiiframework.com/
4
 * @copyright Copyright (c) 2008 Yii Software LLC
5
 * @license http://www.yiiframework.com/license/
6
 */
7
8
namespace edgardmessias\db\firebird\conditions;
9
10
/**
11
 * {@inheritdoc}
12
 */
13
class InConditionBuilder extends \yii\db\conditions\InConditionBuilder
14
{
15
    /**
16
     * {@inheritdoc}
17
     */
18
    protected function buildCompositeInCondition($operator, $columns, $values, &$params)
19
    {
20
        $quotedColumns = [];
21
        foreach ($columns as $i => $column) {
22
            $quotedColumns[$i] = strpos($column, '(') === false ? $this->queryBuilder->db->quoteColumnName($column) : $column;
23
        }
24
        $vss = [];
25
        foreach ($values as $value) {
26
            $vs = [];
27
            foreach ($columns as $i => $column) {
28
                if (isset($value[$column])) {
29
                    $phName = $this->queryBuilder->bindParam($value[$column], $params);
30
                    $vs[] = $quotedColumns[$i] . ($operator === 'IN' ? ' = ' : ' != ') . $phName;
31
                } else {
32
                    $vs[] = $quotedColumns[$i] . ($operator === 'IN' ? ' IS' : ' IS NOT') . ' NULL';
33
                }
34
            }
35
            $vss[] = '(' . implode($operator === 'IN' ? ' AND ' : ' OR ', $vs) . ')';
36
        }
37
38
        return '(' . implode($operator === 'IN' ? ' OR ' : ' AND ', $vss) . ')';
39
    }
40
}
41