Cancelled
Push — 1.1 ( edfb57...88a35e )
by David
593:13 queued 593:13
created

WhenConditions::setValue()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
namespace SQLParser\Node;
4
5
use Doctrine\DBAL\Connection;
6
7
/**
8
 * This class represents a set of ... WHEN ... THEN ... construct (inside a CASE).
9
 *
10
 * @author David Négrier <[email protected]>
11
 */
12
class WhenConditions extends AbstractManyInstancesOperator
13
{
14
    private $value;
15
16
    public function getValue()
17
    {
18
        return $this->value;
19
    }
20
21
    /**
22
     * Sets the value.
23
     *
24
     * @Important
25
     *
26
     * @param NodeInterface|NodeInterface[]|string $value
27
     */
28
    public function setValue($value)
29
    {
30
        $this->value = $value;
31
    }
32
33
    /**
34
     * Renders the object as a SQL string.
35
     *
36
     * @param Connection $dbConnection
37
     * @param array      $parameters
38
     * @param number     $indent
39
     * @param int        $conditionsMode
40
     *
41
     * @return string
42
     */
43
    public function toSql(array $parameters = array(), Connection $dbConnection = null, $indent = 0, $conditionsMode = self::CONDITION_APPLY)
44
    {
45
        $fullSql = '';
46
47 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...
48
            $fullSql = NodeFactory::toSql($this->value, $dbConnection, $parameters, ' ', false, $indent, $conditionsMode);
49
        }
50
51
        foreach ($this->getOperands() as $operand) {
52
            $sql = NodeFactory::toSql($operand, $dbConnection, $parameters, ' ', false, $indent, $conditionsMode);
53
            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...
54
                $fullSql .= "\n".str_repeat(' ', $indent).'WHEN '.$sql;
55
            }
56
        }
57
58
        return $fullSql;
59
    }
60
61
    /**
62
     * Returns the symbol for this operator.
63
     *
64
     * @return string
65
     */
66
    protected function getOperatorSymbol()
67
    {
68
        return 'WHEN';
69
    }
70
}
71