Conditions | 41 |
Paths | 22 |
Total Lines | 177 |
Code Lines | 111 |
Lines | 32 |
Ratio | 18.08 % |
Changes | 1 | ||
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 |
||
153 | public function parse(Parser $parser, TokensList $list) |
||
154 | { |
||
155 | ++$list->idx; // Skipping `DELETE`. |
||
156 | |||
157 | // parse any options if provided |
||
158 | $this->options = OptionsArray::parse( |
||
159 | $parser, |
||
160 | $list, |
||
161 | static::$OPTIONS |
||
162 | ); |
||
163 | ++$list->idx; |
||
164 | |||
165 | /** |
||
166 | * The state of the parser. |
||
167 | * |
||
168 | * Below are the states of the parser. |
||
169 | * |
||
170 | * 0 ---------------------------------[ FROM ]----------------------------------> 2 |
||
171 | * 0 ------------------------------[ table[.*] ]--------------------------------> 1 |
||
172 | * 1 ---------------------------------[ FROM ]----------------------------------> 2 |
||
173 | * 2 --------------------------------[ USING ]----------------------------------> 3 |
||
174 | * 2 --------------------------------[ WHERE ]----------------------------------> 4 |
||
175 | * 2 --------------------------------[ ORDER ]----------------------------------> 5 |
||
176 | * 2 --------------------------------[ LIMIT ]----------------------------------> 6 |
||
177 | * |
||
178 | * @var int $state |
||
179 | */ |
||
180 | $state = 0; |
||
181 | |||
182 | /** |
||
183 | * If the query is multi-table or not |
||
184 | * |
||
185 | * @var bool $multiTable |
||
186 | */ |
||
187 | $multiTable = false; |
||
188 | |||
189 | for (; $list->idx < $list->count; ++$list->idx) { |
||
190 | /** |
||
191 | * Token parsed at this moment. |
||
192 | * |
||
193 | * @var Token $token |
||
194 | */ |
||
195 | $token = $list->tokens[$list->idx]; |
||
196 | |||
197 | // End of statement. |
||
198 | if ($token->type === Token::TYPE_DELIMITER) { |
||
199 | break; |
||
200 | } |
||
201 | |||
202 | if ($state === 0) { |
||
203 | if ($token->type === Token::TYPE_KEYWORD |
||
204 | && $token->value !== 'FROM' |
||
205 | ) { |
||
206 | $parser->error(__('Unexpected keyword.'), $token); |
||
207 | break; |
||
208 | } elseif ($token->type === Token::TYPE_KEYWORD |
||
209 | && $token->value === 'FROM' |
||
210 | ) { |
||
211 | ++$list->idx; // Skip 'FROM' |
||
212 | $this->from = ExpressionArray::parse($parser, $list); |
||
213 | $state = 2; |
||
214 | } else { |
||
215 | $this->columns = ExpressionArray::parse($parser, $list); |
||
216 | $state = 1; |
||
217 | } |
||
218 | View Code Duplication | } elseif ($state === 1) { |
|
219 | if ($token->type === Token::TYPE_KEYWORD |
||
220 | && $token->value !== 'FROM' |
||
221 | ) { |
||
222 | $parser->error(__('Unexpected keyword.'), $token); |
||
223 | break; |
||
224 | } elseif ($token->type === Token::TYPE_KEYWORD |
||
225 | && $token->value === 'FROM' |
||
226 | ) { |
||
227 | ++$list->idx; // Skip 'FROM' |
||
228 | $this->from = ExpressionArray::parse($parser, $list); |
||
229 | $state = 2; |
||
230 | } else { |
||
231 | $parser->error(__('Unexpected token.'), $token); |
||
232 | break; |
||
233 | } |
||
234 | } elseif ($state === 2) { |
||
235 | if ($token->type === Token::TYPE_KEYWORD |
||
236 | && $token->value === 'USING' |
||
237 | ) { |
||
238 | ++$list->idx; // Skip 'USING' |
||
239 | $this->using = ExpressionArray::parse($parser, $list); |
||
240 | $state = 3; |
||
241 | |||
242 | $multiTable = true; |
||
243 | } elseif ($token->type === Token::TYPE_KEYWORD |
||
244 | && $token->value === 'WHERE' |
||
245 | ) { |
||
246 | ++$list->idx; // Skip 'WHERE' |
||
247 | $this->where = Condition::parse($parser, $list); |
||
248 | $state = 4; |
||
249 | } elseif ($token->type === Token::TYPE_KEYWORD |
||
250 | && $token->value === 'ORDER BY' |
||
251 | ) { |
||
252 | ++$list->idx; // Skip 'ORDER BY' |
||
253 | $this->order = OrderKeyword::parse($parser, $list); |
||
254 | $state = 5; |
||
255 | } elseif ($token->type === Token::TYPE_KEYWORD |
||
256 | && $token->value === 'LIMIT' |
||
257 | ) { |
||
258 | ++$list->idx; // Skip 'LIMIT' |
||
259 | $this->limit = Limit::parse($parser, $list); |
||
260 | $state = 6; |
||
261 | } elseif ($token->type === Token::TYPE_KEYWORD) { |
||
262 | $parser->error(__('Unexpected keyword.'), $token); |
||
263 | break; |
||
264 | } |
||
265 | View Code Duplication | } elseif ($state === 3) { |
|
266 | if ($token->type === Token::TYPE_KEYWORD |
||
267 | && $token->value === 'WHERE' |
||
268 | ) { |
||
269 | ++$list->idx; // Skip 'WHERE' |
||
270 | $this->where = Condition::parse($parser, $list); |
||
271 | $state = 4; |
||
272 | } elseif ($token->type === Token::TYPE_KEYWORD) { |
||
273 | $parser->error(__('Unexpected keyword.'), $token); |
||
274 | break; |
||
275 | } else { |
||
276 | $parser->error(__('Unexpected token.'), $token); |
||
277 | break; |
||
278 | } |
||
279 | } elseif ($state === 4) { |
||
280 | if ($multiTable === true |
||
281 | && $token->type === Token::TYPE_KEYWORD |
||
282 | ) { |
||
283 | $parser->error( |
||
284 | __('This type of clause is not valid in Multi-table queries.'), |
||
285 | $token |
||
286 | ); |
||
287 | break; |
||
288 | } |
||
289 | |||
290 | if ($token->type === Token::TYPE_KEYWORD |
||
291 | && $token->value === 'ORDER BY' |
||
292 | ) { |
||
293 | ++$list->idx; // Skip 'ORDER BY' |
||
294 | $this->order = OrderKeyword::parse($parser, $list); |
||
295 | $state = 5; |
||
296 | } elseif ($token->type === Token::TYPE_KEYWORD |
||
297 | && $token->value === 'LIMIT' |
||
298 | ) { |
||
299 | ++$list->idx; // Skip 'LIMIT' |
||
300 | $this->limit = Limit::parse($parser, $list); |
||
301 | $state = 6; |
||
302 | } elseif ($token->type === Token::TYPE_KEYWORD) { |
||
303 | $parser->error(__('Unexpected keyword.'), $token); |
||
304 | break; |
||
305 | } |
||
306 | } elseif ($state === 5) { |
||
307 | if ($token->type === Token::TYPE_KEYWORD |
||
308 | && $token->value === 'LIMIT' |
||
309 | ) { |
||
310 | ++$list->idx; // Skip 'LIMIT' |
||
311 | $this->limit = Limit::parse($parser, $list); |
||
312 | $state = 6; |
||
313 | } elseif ($token->type === Token::TYPE_KEYWORD) { |
||
314 | $parser->error(__('Unexpected keyword.'), $token); |
||
315 | break; |
||
316 | } |
||
317 | } |
||
318 | } |
||
319 | |||
320 | if ($state >= 2) { |
||
321 | foreach ($this->from as $from_expr) { |
||
322 | $from_expr->database = $from_expr->table; |
||
323 | $from_expr->table = $from_expr->column; |
||
324 | $from_expr->column = null; |
||
325 | } |
||
326 | } |
||
327 | |||
328 | --$list->idx; |
||
329 | } |
||
330 | } |
||
331 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: