Equal::getSql()   A
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 19
Code Lines 13

Duplication

Lines 19
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 19
loc 19
rs 9.2
cc 4
eloc 13
nc 4
nop 4
1
<?php
2
3
namespace SQLParser\Node;
4
5
use Doctrine\DBAL\Connection;
6
7
/**
8
 * This class represents an = operation in an SQL expression.
9
 *
10
 * @author David Négrier <[email protected]>
11
 */
12 View Code Duplication
class Equal extends AbstractTwoOperandsOperator
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
13
{
14
    /**
15
     * Returns the symbol for this operator.
16
     */
17
    protected function getOperatorSymbol()
18
    {
19
        return '=';
20
    }
21
22
    protected function getSql(array $parameters = array(), Connection $dbConnection = null, $indent = 0, $conditionsMode = self::CONDITION_APPLY)
23
    {
24
        $rightOperand = $this->getRightOperand();
25
        if ($rightOperand instanceof Parameter && !isset($parameters[$rightOperand->getName()])) {
26
            $isNull = true;
27
        } else {
28
            $isNull = false;
29
        }
30
31
        $sql = NodeFactory::toSql($this->getLeftOperand(), $dbConnection, $parameters, ' ', false, $indent, $conditionsMode);
32
        if ($isNull) {
33
            $sql .= ' IS null';
34
        } else {
35
            $sql .= ' '.$this->getOperatorSymbol().' ';
36
            $sql .= NodeFactory::toSql($rightOperand, $dbConnection, $parameters, ' ', false, $indent, $conditionsMode);
37
        }
38
39
        return $sql;
40
    }
41
}
42