Completed
Push — 1.1 ( f00cd7...edfb57 )
by David
8s
created

WhenConditions::toSql()   A

Complexity

Conditions 4
Paths 6

Size

Total Lines 17
Code Lines 9

Duplication

Lines 3
Ratio 17.65 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 3
loc 17
rs 9.2
cc 4
eloc 9
nc 6
nop 4
1
<?php
2
3
namespace SQLParser\Node;
4
5
use Mouf\Utils\Common\ConditionInterface\ConditionTrait;
6
use Doctrine\DBAL\Connection;
7
use Mouf\MoufManager;
8
use Mouf\MoufInstanceDescriptor;
9
use SQLParser\Node\Traverser\NodeTraverser;
10
use SQLParser\Node\Traverser\VisitorInterface;
11
12
/**
13
 * This class represents a set of ... WHEN ... THEN ... construct (inside a CASE).
14
 *
15
 * @author David Négrier <[email protected]>
16
 */
17
class WhenConditions extends AbstractManyInstancesOperator
18
{
19
20
    private $value;
21
22
    public function getValue()
23
    {
24
        return $this->value;
25
    }
26
27
    /**
28
     * Sets the value.
29
     *
30
     * @Important
31
     *
32
     * @param NodeInterface|NodeInterface[]|string $value
33
     */
34
    public function setValue($value)
35
    {
36
        $this->value = $value;
37
    }
38
39
    /**
40
     * Renders the object as a SQL string.
41
     *
42
     * @param Connection $dbConnection
43
     * @param array      $parameters
44
     * @param number     $indent
45
     * @param int        $conditionsMode
46
     *
47
     * @return string
48
     */
49
    public function toSql(array $parameters = array(), Connection $dbConnection = null, $indent = 0, $conditionsMode = self::CONDITION_APPLY)
50
    {
51
        $fullSql = '';
52
53 View Code Duplication
        if ($this->value) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
54
            $fullSql = NodeFactory::toSql($this->value, $dbConnection, $parameters, ' ', false, $indent, $conditionsMode);
55
        }
56
57
        foreach ($this->getOperands() as $operand) {
58
            $sql = NodeFactory::toSql($operand, $dbConnection, $parameters, ' ', false, $indent, $conditionsMode);
59
            if ($sql != null) {
0 ignored issues
show
Bug introduced by
It seems like you are loosely comparing $sql of type null|string against null; this is ambiguous if the string can be empty. Consider using a strict comparison !== instead.
Loading history...
60
                $fullSql .= "\n".str_repeat(' ', $indent).'WHEN '.$sql;
61
            }
62
        }
63
64
        return $fullSql;
65
    }
66
67
    /**
68
     * Returns the symbol for this operator.
69
     *
70
     * @return string
71
     */
72
    protected function getOperatorSymbol()
73
    {
74
        return 'WHEN';
75
    }
76
}
77