Conditions | 35 |
Paths | 36 |
Total Lines | 73 |
Code Lines | 39 |
Lines | 6 |
Ratio | 8.22 % |
Changes | 2 | ||
Bugs | 0 | Features | 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 |
||
132 | private function lookForBaseExpression($sql, &$charPos, &$parsed, $key, &$backtracking) |
||
133 | { |
||
134 | if (!is_numeric($key)) { |
||
135 | if (($key === 'UNION' || $key === 'UNION ALL') |
||
136 | || ($key === 'expr_type' && $parsed === ExpressionType::EXPRESSION) |
||
137 | || ($key === 'expr_type' && $parsed === ExpressionType::SUBQUERY) |
||
138 | || ($key === 'expr_type' && $parsed === ExpressionType::BRACKET_EXPRESSION) |
||
139 | || ($key === 'expr_type' && $parsed === ExpressionType::TABLE_EXPRESSION) |
||
140 | || ($key === 'expr_type' && $parsed === ExpressionType::RECORD) |
||
141 | || ($key === 'expr_type' && $parsed === ExpressionType::IN_LIST) |
||
142 | || ($key === 'expr_type' && $parsed === ExpressionType::MATCH_ARGUMENTS) |
||
143 | || ($key === 'alias' && $parsed !== false)) { |
||
144 | # we hold the current position and come back after the next base_expr |
||
145 | # we do this, because the next base_expr contains the complete expression/subquery/record |
||
146 | # and we have to look into it too |
||
147 | $backtracking[] = $charPos; |
||
148 | } elseif (($key === 'ref_clause' || $key === 'columns') && $parsed !== false) { |
||
149 | # we hold the current position and come back after n base_expr(s) |
||
150 | # there is an array of sub-elements before (!) the base_expr clause of the current element |
||
151 | # so we go through the sub-elements and must come at the end |
||
152 | $backtracking[] = $charPos; |
||
153 | View Code Duplication | for ($i = 1; $i < count($parsed); ++$i) { |
|
154 | $backtracking[] = false; # backtracking only after n base_expr! |
||
155 | } |
||
156 | } elseif ($key === 'sub_tree' && $parsed !== false) { |
||
157 | # we prevent wrong backtracking on subtrees (too much array_pop()) |
||
158 | # there is an array of sub-elements after(!) the base_expr clause of the current element |
||
159 | # so we go through the sub-elements and must not come back at the end |
||
160 | View Code Duplication | for ($i = 1; $i < count($parsed); ++$i) { |
|
161 | $backtracking[] = false; |
||
162 | } |
||
163 | } else { |
||
164 | # move the current pos after the keyword |
||
165 | # SELECT, WHERE, INSERT etc. |
||
166 | if (in_array($key, parent::$reserved)) { |
||
167 | $charPos = stripos($sql, $key, $charPos); |
||
168 | $charPos += strlen($key); |
||
169 | } |
||
170 | } |
||
171 | } |
||
172 | |||
173 | if (!is_array($parsed)) { |
||
174 | return; |
||
175 | } |
||
176 | |||
177 | foreach ($parsed as $key => $value) { |
||
178 | if ($key === 'base_expr') { |
||
179 | |||
180 | #$this->printPos("0", $sql, $charPos, $key, $value, $backtracking); |
||
181 | |||
182 | $subject = substr($sql, $charPos); |
||
183 | $pos = $this->findPositionWithinString($subject, $value, |
||
184 | isset($parsed['expr_type']) ? $parsed['expr_type'] : 'alias'); |
||
185 | if ($pos === false) { |
||
186 | throw new UnableToCalculatePositionException($value, $subject); |
||
187 | } |
||
188 | |||
189 | $parsed['position'] = $charPos + $pos; |
||
190 | $charPos += $pos + strlen($value); |
||
191 | |||
192 | #$this->printPos("1", $sql, $charPos, $key, $value, $backtracking); |
||
193 | |||
194 | $oldPos = array_pop($backtracking); |
||
195 | if (isset($oldPos) && $oldPos !== false) { |
||
196 | $charPos = $oldPos; |
||
197 | } |
||
198 | |||
199 | #$this->printPos("2", $sql, $charPos, $key, $value, $backtracking); |
||
200 | } else { |
||
201 | $this->lookForBaseExpression($sql, $charPos, $parsed[$key], $key, $backtracking); |
||
202 | } |
||
203 | } |
||
204 | } |
||
205 | } |
||
206 |