Completed
Push — 1.1 ( 88a35e...ec6eee )
by David
7s
created

In::getSql()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 14
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
c 1
b 1
f 0
dl 0
loc 14
rs 9.2
cc 4
eloc 8
nc 4
nop 4
1
<?php
2
3
namespace SQLParser\Node;
4
use Doctrine\DBAL\Connection;
5
use Mouf\Database\MagicQueryException;
6
7
/**
8
 * This class represents an In operation in an SQL expression.
9
 *
10
 * @author David Négrier <[email protected]>
11
 */
12
class In extends AbstractTwoOperandsOperator
13
{
14
    /**
15
     * Returns the symbol for this operator.
16
     *
17
     * @return string
18
     */
19
    protected function getOperatorSymbol()
20
    {
21
        return 'IN';
22
    }
23
24
    protected function getSql(array $parameters = array(), Connection $dbConnection = null, $indent = 0, $conditionsMode = self::CONDITION_APPLY)
25
    {
26
        $rightOperand = $this->getRightOperand();
27
        if ($rightOperand instanceof Parameter) {
28
            if (!isset($parameters[$rightOperand->getName()])) {
29
                throw new MagicQueryException("Missing parameter '" . $rightOperand->getName() . "' for 'IN' operand.");
30
            }
31
            if ($parameters[$rightOperand->getName()] === []) {
32
                return "FALSE";
33
            }
34
        }
35
36
        return parent::getSql($parameters, $dbConnection, $indent, $conditionsMode);
37
    }
38
}
39