CaseOperation   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 77
Duplicated Lines 29.87 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 9
c 2
b 0
f 0
lcom 1
cbo 2
dl 23
loc 77
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getOperation() 0 4 1
A setOperation() 0 4 1
A toInstanceDescriptor() 7 7 1
A toSql() 0 6 1
B walk() 16 18 5

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