Reserved   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 105
Duplicated Lines 7.62 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 3
Bugs 0 Features 1
Metric Value
wmc 10
c 3
b 0
f 1
lcom 1
cbo 2
dl 8
loc 105
rs 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A getBaseExpression() 0 4 1
A setBaseExpression() 0 4 1
A hasBrackets() 0 4 1
A setBrackets() 0 4 1
A toInstanceDescriptor() 0 8 1
A toSql() 0 14 3
A walk() 8 10 2

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
/**
4
 * expression-types.php.
5
 *
6
 *
7
 * Copyright (c) 2010-2013, Justin Swanhart
8
 * with contributions by André Rothe <[email protected], [email protected]>
9
 * and David Négrier <[email protected]>
10
 *
11
 * All rights reserved.
12
 *
13
 * Redistribution and use in source and binary forms, with or without modification,
14
 * are permitted provided that the following conditions are met:
15
 *
16
 *   * Redistributions of source code must retain the above copyright notice,
17
 *     this list of conditions and the following disclaimer.
18
 *   * Redistributions in binary form must reproduce the above copyright notice,
19
 *     this list of conditions and the following disclaimer in the documentation
20
 *     and/or other materials provided with the distribution.
21
 *
22
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
23
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
24
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
25
 * SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
27
 * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
28
 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
30
 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
31
 * DAMAGE.
32
 */
33
namespace SQLParser\Node;
34
35
use Doctrine\DBAL\Connection;
36
use Mouf\MoufInstanceDescriptor;
37
use Mouf\MoufManager;
38
use SQLParser\Node\Traverser\VisitorInterface;
39
40
/**
41
 * This class represents a node that is an SQL expression.
42
 *
43
 * @author David Négrier <[email protected]>
44
 */
45
class Reserved implements NodeInterface
46
{
47
    private $baseExpression;
48
49
    /**
50
     * Returns the base expression (the string that generated this expression).
51
     *
52
     * @return string
53
     */
54
    public function getBaseExpression()
55
    {
56
        return $this->baseExpression;
57
    }
58
59
    /**
60
     * Sets the base expression (the string that generated this expression).
61
     *
62
     * @param string $baseExpression
63
     */
64
    public function setBaseExpression($baseExpression)
65
    {
66
        $this->baseExpression = $baseExpression;
67
    }
68
69
    private $brackets = false;
70
71
    /**
72
     * Returns true if the expression is between brackets.
73
     *
74
     * @return bool
75
     */
76
    public function hasBrackets()
77
    {
78
        return $this->brackets;
79
    }
80
81
    /**
82
     * Sets to true if the expression is between brackets.
83
     *
84
     * @Important
85
     *
86
     * @param bool $brackets
87
     */
88
    public function setBrackets($brackets)
89
    {
90
        $this->brackets = $brackets;
91
    }
92
93
    /**
94
     * Returns a Mouf instance descriptor describing this object.
95
     *
96
     * @param MoufManager $moufManager
97
     *
98
     * @return MoufInstanceDescriptor
99
     */
100
    public function toInstanceDescriptor(MoufManager $moufManager)
101
    {
102
        $instanceDescriptor = $moufManager->createInstance(get_called_class());
103
        $instanceDescriptor->getProperty('baseExpression')->setValue(NodeFactory::nodeToInstanceDescriptor($this->baseExpression, $moufManager));
104
        $instanceDescriptor->getProperty('brackets')->setValue(NodeFactory::nodeToInstanceDescriptor($this->brackets, $moufManager));
105
106
        return $instanceDescriptor;
107
    }
108
109
    /**
110
     * Renders the object as a SQL string.
111
     *
112
     * @param array      $parameters
113
     * @param Connection $dbConnection
114
     * @param int|number $indent
115
     * @param int        $conditionsMode
116
     *
117
     * @return string
118
     */
119
    public function toSql(array $parameters = array(), Connection $dbConnection = null, $indent = 0, $conditionsMode = self::CONDITION_APPLY)
120
    {
121
        $sql = '';
122
123
        if ($this->baseExpression) {
124
            $sql .= ' '.$this->baseExpression.' ';
125
        }
126
127
        if ($this->brackets) {
128
            $sql = '('.$sql.')';
129
        }
130
131
        return $sql;
132
    }
133
134
    /**
135
     * Walks the tree of nodes, calling the visitor passed in parameter.
136
     *
137
     * @param VisitorInterface $visitor
138
     */
139 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...
140
    {
141
        $node = $this;
142
        $result = $visitor->enterNode($node);
143
        if ($result instanceof NodeInterface) {
144
            $node = $result;
145
        }
146
147
        return $visitor->leaveNode($node);
148
    }
149
}
150