| Conditions | 33 |
| Paths | 36 |
| Total Lines | 71 |
| Code Lines | 37 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 138 | private function lookForBaseExpression($sql, &$charPos, &$parsed, $key, &$backtracking) { |
||
| 139 | if (!is_numeric($key)) { |
||
| 140 | if (($key === 'UNION' || $key === 'UNION ALL') || ($key === 'expr_type' && $parsed === 'expression') |
||
| 141 | || ($key === 'expr_type' && $parsed === 'subquery') |
||
| 142 | || ($key === 'expr_type' && $parsed === 'bracket_expression') |
||
| 143 | || ($key === 'expr_type' && $parsed === 'table_expression') |
||
| 144 | || ($key === 'expr_type' && $parsed === 'record') |
||
| 145 | || ($key === 'expr_type' && $parsed === 'in-list') || ($key === 'alias' && $parsed !== false)) { |
||
| 146 | // we hold the current position and come back after the next base_expr |
||
| 147 | // we do this, because the next base_expr contains the complete expression/subquery/record |
||
| 148 | // and we have to look into it too |
||
| 149 | $backtracking[] = $charPos; |
||
| 150 | |||
| 151 | } elseif (($key === 'ref_clause' || $key === 'columns') && $parsed !== false) { |
||
| 152 | // we hold the current position and come back after n base_expr(s) |
||
| 153 | // there is an array of sub-elements before (!) the base_expr clause of the current element |
||
| 154 | // so we go through the sub-elements and must come at the end |
||
| 155 | $backtracking[] = $charPos; |
||
| 156 | $parsedCount = count($parsed); |
||
| 157 | for ($i = 1; $i < $parsedCount; $i++) { |
||
| 158 | $backtracking[] = false; // backtracking only after n base_expr! |
||
| 159 | } |
||
| 160 | } elseif ($key === 'sub_tree' && $parsed !== false) { |
||
| 161 | // we prevent wrong backtracking on subtrees (too much array_pop()) |
||
| 162 | // there is an array of sub-elements after(!) the base_expr clause of the current element |
||
| 163 | // so we go through the sub-elements and must not come back at the end |
||
| 164 | $parsedCount = count($parsed); |
||
| 165 | for ($i = 1; $i < $parsedCount; $i++) { |
||
| 166 | $backtracking[] = false; |
||
| 167 | } |
||
| 168 | } else { |
||
| 169 | // move the current pos after the keyword |
||
| 170 | // SELECT, WHERE, INSERT etc. |
||
| 171 | if (in_array($key, parent::$reserved)) { |
||
| 172 | $charPos = stripos($sql, $key, $charPos); |
||
| 173 | $charPos += strlen($key); |
||
| 174 | } |
||
| 175 | } |
||
| 176 | } |
||
| 177 | |||
| 178 | if (!is_array($parsed)) { |
||
| 179 | return; |
||
| 180 | } |
||
| 181 | |||
| 182 | foreach ($parsed as $key => $value) { |
||
| 183 | if ($key === 'base_expr') { |
||
| 184 | |||
| 185 | // $this->printPos("0", $sql, $charPos, $key, $value, $backtracking); |
||
| 186 | |||
| 187 | $subject = substr($sql, $charPos); |
||
| 188 | $pos = $this->findPositionWithinString($subject, $value, |
||
| 189 | isset($parsed['expr_type']) ? $parsed['expr_type'] : 'alias'); |
||
| 190 | if ($pos === false) { |
||
| 191 | throw new Exception("cannot calculate position of " . $value . " within " . $subject, 5); |
||
| 192 | |||
| 193 | } |
||
| 194 | |||
| 195 | $parsed['position'] = $charPos + $pos; |
||
| 196 | $charPos += $pos + strlen($value); |
||
| 197 | |||
| 198 | // $this->printPos("1", $sql, $charPos, $key, $value, $backtracking); |
||
| 199 | |||
| 200 | $oldPos = array_pop($backtracking); |
||
| 201 | if (isset($oldPos) && $oldPos !== false) { |
||
| 202 | $charPos = $oldPos; |
||
| 203 | } |
||
| 204 | |||
| 205 | // $this->printPos("2", $sql, $charPos, $key, $value, $backtracking); |
||
| 206 | |||
| 207 | } else { |
||
| 208 | $this->lookForBaseExpression($sql, $charPos, $parsed[$key], $key, $backtracking); |
||
| 209 | } |
||
| 213 |
This check looks for private methods that have been defined, but are not used inside the class.