LimitNode   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 81
Duplicated Lines 18.52 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 9
c 2
b 0
f 0
lcom 1
cbo 3
dl 15
loc 81
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getValue() 0 4 1
A setValue() 0 4 1
A toInstanceDescriptor() 7 7 1
A toSql() 0 14 4
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\MoufManager;
37
use Mouf\MoufInstanceDescriptor;
38
use SQLParser\Node\Traverser\VisitorInterface;
39
40
/**
41
 * This class represents a constant of a LIMIT in an SQL expression.
42
 *
43
 * @author David MAECHLER <[email protected]>
44
 */
45
class LimitNode implements NodeInterface
46
{
47
    private $value;
48
49
    public function getValue()
50
    {
51
        return $this->value;
52
    }
53
54
    /**
55
     * Sets the value.
56
     *
57
     * @Important
58
     *
59
     * @param string $value
60
     */
61
    public function setValue($value)
62
    {
63
        $this->value = $value;
64
    }
65
66
    /**
67
     * Returns a Mouf instance descriptor describing this object.
68
     *
69
     * @param MoufManager $moufManager
70
     *
71
     * @return MoufInstanceDescriptor
72
     */
73 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...
74
    {
75
        $instanceDescriptor = $moufManager->createInstance(get_called_class());
76
        $instanceDescriptor->getProperty('value')->setValue(NodeFactory::nodeToInstanceDescriptor($this->value, $moufManager));
77
78
        return $instanceDescriptor;
79
    }
80
81
    /**
82
     * Renders the object as a SQL string.
83
     *
84
     * @param array      $parameters
85
     * @param Connection $dbConnection
86
     * @param int|number $indent
87
     * @param int        $conditionsMode
88
     *
89
     * @return string
90
     *
91
     * @throws \Exception
92
     */
93
    public function toSql(array $parameters = array(), Connection $dbConnection = null, $indent = 0, $conditionsMode = self::CONDITION_APPLY)
94
    {
95
        if ($this->value === null) {
96
            throw new \Exception('A limit parameter must be an integer');
97
        }
98
99
        if (is_numeric($this->value)) {
100
            return (int) $this->value;
101
        } elseif ($dbConnection != null) {
102
            return $dbConnection->quote($this->value);
103
        } else {
104
            return addslashes($this->value);
105
        }
106
    }
107
108
    /**
109
     * Walks the tree of nodes, calling the visitor passed in parameter.
110
     *
111
     * @param VisitorInterface $visitor
112
     *
113
     * @return NodeInterface|null|string Can return null if nothing is to be done or a node that should replace this node, or NodeTraverser::REMOVE_NODE to remove the node
114
     */
115 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...
116
    {
117
        $node = $this;
118
        $result = $visitor->enterNode($node);
119
        if ($result instanceof NodeInterface) {
120
            $node = $result;
121
        }
122
123
        return $visitor->leaveNode($node);
124
    }
125
}
126