| 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\NodeTraverser; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  | use SQLParser\Node\Traverser\VisitorInterface; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |  * This class represents a node that is an SQL expression. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |  * @author David Négrier <[email protected]> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  | class Expression implements NodeInterface | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |     private $baseExpression; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |      * Returns the base expression (the string that generated this expression). | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |      * @return string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |     public function getBaseExpression() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |         return $this->baseExpression; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |      * Sets the base expression (the string that generated this expression). | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |      * @param string $baseExpression | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |     public function setBaseExpression($baseExpression) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |         $this->baseExpression = $baseExpression; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |     private $subTree; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |     public function getSubTree() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |         return $this->subTree; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |      * Sets the subtree. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |      * @Important | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |      * @param array<NodeInterface>|NodeInterface $subTree | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |     public function setSubTree($subTree) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |         $this->subTree = $subTree; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |         $this->subTree = NodeFactory::simplify($this->subTree); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  |     private $alias; | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 91 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 92 |  |  |     public function getAlias() | 
            
                                                                        
                            
            
                                    
            
            
                | 93 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 94 |  |  |         return $this->alias; | 
            
                                                                        
                            
            
                                    
            
            
                | 95 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  |      * Sets the alias. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  |      * @Important | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  |      * @param string $alias | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  |     public function setAlias($alias) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 |  |  |         $this->alias = $alias; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 109 |  |  |     private $direction; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 110 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 111 |  |  |     public function getDiretion() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 112 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 113 |  |  |         return $this->direction; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 114 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 115 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 116 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 117 |  |  |      * Sets the direction. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 118 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 119 |  |  |      * @Important | 
            
                                                                                                            
                            
            
                                    
            
            
                | 120 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 121 |  |  |      * @param string $direction | 
            
                                                                                                            
                            
            
                                    
            
            
                | 122 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 123 |  |  |     public function setDirection($direction) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 124 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 125 |  |  |         $this->direction = $direction; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 126 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 127 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 128 |  |  |     private $brackets = false; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 129 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 130 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 131 |  |  |      * Returns true if the expression is between brackets. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 132 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 133 |  |  |      * @return bool | 
            
                                                                                                            
                            
            
                                    
            
            
                | 134 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 135 |  |  |     public function hasBrackets() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 136 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 137 |  |  |         return $this->brackets; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 138 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 139 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 140 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 141 |  |  |      * Sets to true if the expression is between brackets. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 142 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 143 |  |  |      * @Important | 
            
                                                                                                            
                            
            
                                    
            
            
                | 144 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 145 |  |  |      * @param bool $brackets | 
            
                                                                                                            
                            
            
                                    
            
            
                | 146 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 147 |  |  |     public function setBrackets($brackets) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 148 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 149 |  |  |         $this->brackets = $brackets; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 150 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 151 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 152 |  |  |     private $delimiter = ' '; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 153 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 154 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 155 |  |  |      * @return string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 156 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 157 |  |  |     public function getDelimiter() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 158 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 159 |  |  |         return $this->delimiter; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 160 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 161 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 162 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 163 |  |  |      * Sets the delimiter for the list. Defaults to ' '. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 164 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 165 |  |  |      * @param string $delimiter | 
            
                                                                                                            
                            
            
                                    
            
            
                | 166 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 167 |  |  |     public function setDelimiter($delimiter) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 168 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 169 |  |  |         $this->delimiter = $delimiter; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 170 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 171 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 172 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 173 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 174 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 175 |  |  |      * Returns a Mouf instance descriptor describing this object. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 176 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 177 |  |  |      * @param MoufManager $moufManager | 
            
                                                                                                            
                            
            
                                    
            
            
                | 178 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 179 |  |  |      * @return MoufInstanceDescriptor | 
            
                                                                                                            
                            
            
                                    
            
            
                | 180 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 181 |  |  |     public function toInstanceDescriptor(MoufManager $moufManager) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 182 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 183 |  |  |         $instanceDescriptor = $moufManager->createInstance(get_called_class()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 184 |  |  |         $instanceDescriptor->getProperty('baseExpression')->setValue(NodeFactory::nodeToInstanceDescriptor($this->baseExpression, $moufManager)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 185 |  |  |         $instanceDescriptor->getProperty('subTree')->setValue(NodeFactory::nodeToInstanceDescriptor($this->subTree, $moufManager)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 186 |  |  |         $instanceDescriptor->getProperty('alias')->setValue(NodeFactory::nodeToInstanceDescriptor($this->alias, $moufManager)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 187 |  |  |         $instanceDescriptor->getProperty('direction')->setValue(NodeFactory::nodeToInstanceDescriptor($this->direction, $moufManager)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 188 |  |  |         $instanceDescriptor->getProperty('brackets')->setValue(NodeFactory::nodeToInstanceDescriptor($this->brackets, $moufManager)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 189 |  |  |         $instanceDescriptor->getProperty('delimiter')->setValue(NodeFactory::nodeToInstanceDescriptor($this->delimiter, $moufManager)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 190 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 191 |  |  |         return $instanceDescriptor; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 192 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 193 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 194 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 195 |  |  |      * Renders the object as a SQL string. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 196 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 197 |  |  |      * @param Connection $dbConnection | 
            
                                                                                                            
                            
            
                                    
            
            
                | 198 |  |  |      * @param array      $parameters | 
            
                                                                                                            
                            
            
                                    
            
            
                | 199 |  |  |      * @param number     $indent | 
            
                                                                                                            
                            
            
                                    
            
            
                | 200 |  |  |      * @param int        $conditionsMode | 
            
                                                                                                            
                            
            
                                    
            
            
                | 201 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 202 |  |  |      * @return string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 203 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 204 |  |  |     public function toSql(array $parameters = array(), Connection $dbConnection = null, $indent = 0, $conditionsMode = self::CONDITION_APPLY) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 205 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 206 |  |  |         $sql = NodeFactory::toSql($this->subTree, $dbConnection, $parameters, $this->delimiter, false, $indent, $conditionsMode); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 207 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 208 |  |  |         if ($sql === null) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 209 |  |  |             return null; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 210 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 211 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 212 |  |  |         if ($this->alias) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 213 |  |  |             $sql .= ' AS '.$this->alias; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 214 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 215 |  |  |         if ($this->direction) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 216 |  |  |             $sql .= ' '.$this->direction; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 217 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 218 |  |  |         if ($this->brackets) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 219 |  |  |             $sql = '('.$sql.')'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 220 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 221 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 222 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 223 |  |  |         return $sql; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 224 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 225 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 226 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 227 |  |  |      * Walks the tree of nodes, calling the visitor passed in parameter. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 228 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 229 |  |  |      * @param VisitorInterface $visitor | 
            
                                                                                                            
                            
            
                                    
            
            
                | 230 |  |  |      */ | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 231 |  | View Code Duplication |     public function walk(VisitorInterface $visitor) | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 232 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 233 |  |  |         $node = $this; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 234 |  |  |         $result = $visitor->enterNode($node); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 235 |  |  |         if ($result instanceof NodeInterface) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 236 |  |  |             $node = $result; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 237 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 238 |  |  |         if ($result !== NodeTraverser::DONT_TRAVERSE_CHILDREN) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 239 |  |  |             if (is_array($this->subTree)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 240 |  |  |                 foreach ($this->subTree as $key => $operand) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 241 |  |  |                     $result2 = $operand->walk($visitor); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 242 |  |  |                     if ($result2 === NodeTraverser::REMOVE_NODE) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 243 |  |  |                         unset($this->subTree[$key]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 244 |  |  |                     } elseif ($result2 instanceof NodeInterface) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 245 |  |  |                         $this->subTree[$key] = $result2; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 246 |  |  |                     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 247 |  |  |                 } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 248 |  |  |             } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 249 |  |  |                 $result2 = $this->subTree->walk($visitor); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 250 |  |  |                 if ($result2 === NodeTraverser::REMOVE_NODE) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 251 |  |  |                     $this->subTree = []; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 252 |  |  |                 } elseif ($result2 instanceof NodeInterface) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 253 |  |  |                     $this->subTree = $result2; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 254 |  |  |                 } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 255 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 256 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 257 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 258 |  |  |         return $visitor->leaveNode($node); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 259 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 260 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 261 |  |  |  | 
            
                        
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.