Different   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 32
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 5
c 3
b 0
f 0
lcom 1
cbo 3
dl 32
loc 32
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getOperatorSymbol() 4 4 1
A getSql() 19 19 4

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace SQLParser\Node;
4
5
use Doctrine\DBAL\Connection;
6
7
/**
8
 * This class represents a Is operation in an SQL expression.
9
 *
10
 * @author David Négrier <[email protected]>
11
 */
12 View Code Duplication
class Different 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
     * @return string
18
     */
19
    protected function getOperatorSymbol()
20
    {
21
        return '<>';
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 && !isset($parameters[$rightOperand->getName()])) {
28
            $isNull = true;
29
        } else {
30
            $isNull = false;
31
        }
32
33
        $sql = NodeFactory::toSql($this->getLeftOperand(), $dbConnection, $parameters, ' ', false, $indent, $conditionsMode);
34
        if ($isNull) {
35
            $sql .= ' IS NOT null';
36
        } else {
37
            $sql .= ' '.$this->getOperatorSymbol().' ';
38
            $sql .= NodeFactory::toSql($rightOperand, $dbConnection, $parameters, ' ', false, $indent, $conditionsMode);
39
        }
40
41
        return $sql;
42
    }
43
}
44