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

CaseOperation::toInstanceDescriptor()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 7
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 7
loc 7
rs 9.4285
cc 1
eloc 4
nc 1
nop 1
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 CASE ... END statement.
14
 *
15
 * @author David Négrier <[email protected]>
16
 */
17
class CaseOperation implements NodeInterface
18
{
19
    private $operation;
20
21
    public function getOperation()
22
    {
23
        return $this->operation;
24
    }
25
26
    /**
27
     * Sets the operation.
28
     *
29
     * @Important
30
     *
31
     * @param NodeInterface|NodeInterface[]|string $operation
32
     */
33
    public function setOperation($operation)
34
    {
35
        $this->operation = $operation;
36
    }
37
38
    /**
39
     * Returns a Mouf instance descriptor describing this object.
40
     *
41
     * @param MoufManager $moufManager
42
     *
43
     * @return MoufInstanceDescriptor
44
     */
45 View Code Duplication
    public function toInstanceDescriptor(MoufManager $moufManager)
0 ignored issues
show
Duplication introduced by
This method 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...
46
    {
47
        $instanceDescriptor = $moufManager->createInstance(get_called_class());
48
        $instanceDescriptor->getProperty('operation')->setValue(NodeFactory::nodeToInstanceDescriptor($this->operation, $moufManager));
49
50
        return $instanceDescriptor;
51
    }
52
53
    /**
54
     * Renders the object as a SQL string.
55
     *
56
     * @param Connection $dbConnection
57
     * @param array      $parameters
58
     * @param number     $indent
59
     * @param int        $conditionsMode
60
     *
61
     * @return string
62
     */
63
    public function toSql(array $parameters = array(), Connection $dbConnection = null, $indent = 0, $conditionsMode = self::CONDITION_APPLY)
64
    {
65
66
        $sql = 'CASE '.NodeFactory::toSql($this->operation, $dbConnection, $parameters, ' ', false, $indent, $conditionsMode).' END';
67
68
        return $sql;
69
    }
70
71
    /**
72
     * Walks the tree of nodes, calling the visitor passed in parameter.
73
     *
74
     * @param VisitorInterface $visitor
75
     */
76 View Code Duplication
    public function walk(VisitorInterface $visitor) {
0 ignored issues
show
Duplication introduced by
This method 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...
77
        $node = $this;
78
        $result = $visitor->enterNode($node);
79
        if ($result instanceof NodeInterface) {
80
            $node = $result;
81
        }
82
        if ($result !== NodeTraverser::DONT_TRAVERSE_CHILDREN) {
83
            $result2 = $this->operation->walk($visitor);
84
            if ($result2 === NodeTraverser::REMOVE_NODE) {
85
                return NodeTraverser::REMOVE_NODE;
86
            } elseif ($result2 instanceof NodeInterface) {
87
                $this->operation = $result2;
88
            }
89
        }
90
        return $visitor->leaveNode($node);
91
    }
92
}
93