@@ -95,7 +95,7 @@ discard block |
||
95 | 95 | * @param TokensList $list the list of tokens that are being parsed |
96 | 96 | * @param array<string, mixed> $options parameters for parsing |
97 | 97 | */ |
98 | - public static function parse(Parser $parser, TokensList $list, array $options = []): DataType|null |
|
98 | + public static function parse(Parser $parser, TokensList $list, array $options = []): DataType | null |
|
99 | 99 | { |
100 | 100 | $ret = new static(); |
101 | 101 | |
@@ -125,7 +125,7 @@ discard block |
||
125 | 125 | |
126 | 126 | if ($state === 0) { |
127 | 127 | $ret->name = strtoupper((string) $token->value); |
128 | - if (($token->type !== TokenType::Keyword) || (! ($token->flags & Token::FLAG_KEYWORD_DATA_TYPE))) { |
|
128 | + if (($token->type !== TokenType::Keyword) || (!($token->flags & Token::FLAG_KEYWORD_DATA_TYPE))) { |
|
129 | 129 | $parser->error('Unrecognized data type.', $token); |
130 | 130 | } |
131 | 131 |
@@ -199,7 +199,7 @@ discard block |
||
199 | 199 | |
200 | 200 | // Handle optional AS keyword before alias |
201 | 201 | if ($token->type === TokenType::Keyword && $token->keyword === 'AS') { |
202 | - if ($asFound || ! empty($ret->alias)) { |
|
202 | + if ($asFound || !empty($ret->alias)) { |
|
203 | 203 | $parser->error('Potential duplicate alias of CASE expression.', $token); |
204 | 204 | break; |
205 | 205 | } |
@@ -221,11 +221,11 @@ discard block |
||
221 | 221 | if ( |
222 | 222 | $asFound |
223 | 223 | || $token->type === TokenType::String |
224 | - || ($token->type === TokenType::Symbol && ! $token->flags & Token::FLAG_SYMBOL_VARIABLE) |
|
224 | + || ($token->type === TokenType::Symbol && !$token->flags & Token::FLAG_SYMBOL_VARIABLE) |
|
225 | 225 | || $token->type === TokenType::None |
226 | 226 | ) { |
227 | 227 | // An alias is expected (the keyword `AS` was previously found). |
228 | - if (! empty($ret->alias)) { |
|
228 | + if (!empty($ret->alias)) { |
|
229 | 229 | $parser->error('An alias was previously found.', $token); |
230 | 230 | break; |
231 | 231 | } |
@@ -87,7 +87,7 @@ |
||
87 | 87 | if ($token->type === TokenType::Operator && $token->value === '(') { |
88 | 88 | --$list->idx; // ArrayObj needs to start with `(` |
89 | 89 | $state = 1; |
90 | - continue;// do not add this token to the name |
|
90 | + continue; // do not add this token to the name |
|
91 | 91 | } |
92 | 92 | |
93 | 93 | $ret->name .= $token->value; |
@@ -243,7 +243,7 @@ discard block |
||
243 | 243 | $state = 4; |
244 | 244 | } elseif ($token->type === TokenType::Symbol || $token->type === TokenType::None) { |
245 | 245 | $expr->name = $token->value; |
246 | - if (! $expr->isConstraint) { |
|
246 | + if (!$expr->isConstraint) { |
|
247 | 247 | $state = 2; |
248 | 248 | } |
249 | 249 | } elseif ($token->type === TokenType::Keyword) { |
@@ -284,7 +284,7 @@ discard block |
||
284 | 284 | |
285 | 285 | $state = 5; |
286 | 286 | } elseif ($state === 5) { |
287 | - if (! empty($expr->type) || ! empty($expr->key)) { |
|
287 | + if (!empty($expr->type) || !empty($expr->key)) { |
|
288 | 288 | $ret[] = $expr; |
289 | 289 | } |
290 | 290 | |
@@ -304,7 +304,7 @@ discard block |
||
304 | 304 | } |
305 | 305 | |
306 | 306 | // Last iteration was not saved. |
307 | - if (! empty($expr->type) || ! empty($expr->key)) { |
|
307 | + if (!empty($expr->type) || !empty($expr->key)) { |
|
308 | 308 | $ret[] = $expr; |
309 | 309 | } |
310 | 310 | |
@@ -332,16 +332,16 @@ discard block |
||
332 | 332 | $tmp .= Context::escape($component->name) . ' '; |
333 | 333 | } |
334 | 334 | |
335 | - if (! empty($component->type)) { |
|
335 | + if (!empty($component->type)) { |
|
336 | 336 | $component->type->lowercase = true; |
337 | 337 | $tmp .= DataType::build($component->type) . ' '; |
338 | 338 | } |
339 | 339 | |
340 | - if (! empty($component->key)) { |
|
340 | + if (!empty($component->key)) { |
|
341 | 341 | $tmp .= $component->key . ' '; |
342 | 342 | } |
343 | 343 | |
344 | - if (! empty($component->references)) { |
|
344 | + if (!empty($component->references)) { |
|
345 | 345 | $tmp .= 'REFERENCES ' . $component->references . ' '; |
346 | 346 | } |
347 | 347 |
@@ -157,7 +157,7 @@ discard block |
||
157 | 157 | * |
158 | 158 | * @throws ParserException |
159 | 159 | */ |
160 | - public static function parse(Parser $parser, TokensList $list, array $options = []): Expression|null |
|
160 | + public static function parse(Parser $parser, TokensList $list, array $options = []): Expression | null |
|
161 | 161 | { |
162 | 162 | $ret = new static(); |
163 | 163 | |
@@ -200,7 +200,7 @@ discard block |
||
200 | 200 | ]; |
201 | 201 | |
202 | 202 | // When a field is parsed, no parentheses are expected. |
203 | - if (! empty($options['parseField'])) { |
|
203 | + if (!empty($options['parseField'])) { |
|
204 | 204 | $options['breakOnParentheses'] = true; |
205 | 205 | $options['field'] = $options['parseField']; |
206 | 206 | } |
@@ -227,14 +227,14 @@ discard block |
||
227 | 227 | } |
228 | 228 | |
229 | 229 | if ($token->type === TokenType::Keyword) { |
230 | - if (($brackets > 0) && empty($ret->subquery) && ! empty(Parser::$statementParsers[$token->keyword])) { |
|
230 | + if (($brackets > 0) && empty($ret->subquery) && !empty(Parser::$statementParsers[$token->keyword])) { |
|
231 | 231 | // A `(` was previously found and this keyword is the |
232 | 232 | // beginning of a statement, so this is a subquery. |
233 | 233 | $ret->subquery = $token->keyword; |
234 | 234 | } elseif ( |
235 | 235 | ($token->flags & Token::FLAG_KEYWORD_FUNCTION) |
236 | 236 | && (empty($options['parseField']) |
237 | - && ! $alias) |
|
237 | + && !$alias) |
|
238 | 238 | ) { |
239 | 239 | $isExpr = true; |
240 | 240 | } elseif (($token->flags & Token::FLAG_KEYWORD_RESERVED) && ($brackets === 0)) { |
@@ -246,7 +246,7 @@ discard block |
||
246 | 246 | } |
247 | 247 | |
248 | 248 | if ($token->keyword === 'AS') { |
249 | - if (! empty($options['breakOnAlias'])) { |
|
249 | + if (!empty($options['breakOnAlias'])) { |
|
250 | 250 | break; |
251 | 251 | } |
252 | 252 | |
@@ -269,7 +269,7 @@ discard block |
||
269 | 269 | } |
270 | 270 | |
271 | 271 | $isExpr = true; |
272 | - } elseif ($brackets === 0 && strlen((string) $ret->expr) > 0 && ! $alias) { |
|
272 | + } elseif ($brackets === 0 && strlen((string) $ret->expr) > 0 && !$alias) { |
|
273 | 273 | /* End of expression */ |
274 | 274 | break; |
275 | 275 | } |
@@ -285,7 +285,7 @@ discard block |
||
285 | 285 | || (($token->type === TokenType::Operator) |
286 | 286 | && ($token->value !== '.')) |
287 | 287 | ) { |
288 | - if (! empty($options['parseField'])) { |
|
288 | + if (!empty($options['parseField'])) { |
|
289 | 289 | break; |
290 | 290 | } |
291 | 291 | |
@@ -295,7 +295,7 @@ discard block |
||
295 | 295 | } |
296 | 296 | |
297 | 297 | if ($token->type === TokenType::Operator) { |
298 | - if (! empty($options['breakOnParentheses']) && (($token->value === '(') || ($token->value === ')'))) { |
|
298 | + if (!empty($options['breakOnParentheses']) && (($token->value === '(') || ($token->value === ')'))) { |
|
299 | 299 | // No brackets were expected. |
300 | 300 | break; |
301 | 301 | } |
@@ -319,7 +319,7 @@ discard block |
||
319 | 319 | |
320 | 320 | --$brackets; |
321 | 321 | if ($brackets === 0) { |
322 | - if (! empty($options['parenthesesDelimited'])) { |
|
322 | + if (!empty($options['parenthesesDelimited'])) { |
|
323 | 323 | // The current token is the last bracket, the next |
324 | 324 | // one will be outside the expression. |
325 | 325 | $ret->expr .= $token->token; |
@@ -345,7 +345,7 @@ discard block |
||
345 | 345 | |
346 | 346 | if ($alias) { |
347 | 347 | // An alias is expected (the keyword `AS` was previously found). |
348 | - if (! empty($ret->alias)) { |
|
348 | + if (!empty($ret->alias)) { |
|
349 | 349 | $parser->error('An alias was previously found.', $token); |
350 | 350 | break; |
351 | 351 | } |
@@ -359,14 +359,14 @@ discard block |
||
359 | 359 | && ($prev[0] === null |
360 | 360 | || (($prev[0]->type !== TokenType::Operator || $prev[0]->token === ')') |
361 | 361 | && ($prev[0]->type !== TokenType::Keyword |
362 | - || ! ($prev[0]->flags & Token::FLAG_KEYWORD_RESERVED)))) |
|
362 | + || !($prev[0]->flags & Token::FLAG_KEYWORD_RESERVED)))) |
|
363 | 363 | && (($prev[1]->type === TokenType::String) |
364 | 364 | || ($prev[1]->type === TokenType::Symbol |
365 | - && ! ($prev[1]->flags & Token::FLAG_SYMBOL_VARIABLE)) |
|
365 | + && !($prev[1]->flags & Token::FLAG_SYMBOL_VARIABLE)) |
|
366 | 366 | || ($prev[1]->type === TokenType::None |
367 | 367 | && $prev[1]->token !== 'OVER')) |
368 | 368 | ) { |
369 | - if (! empty($ret->alias)) { |
|
369 | + if (!empty($ret->alias)) { |
|
370 | 370 | $parser->error('An alias was previously found.', $token); |
371 | 371 | break; |
372 | 372 | } |
@@ -397,7 +397,7 @@ discard block |
||
397 | 397 | // Found a `.` which means we expect a column name and |
398 | 398 | // the column name we parsed is actually the table name |
399 | 399 | // and the table name is actually a database name. |
400 | - if (! empty($ret->database) || $dot) { |
|
400 | + if (!empty($ret->database) || $dot) { |
|
401 | 401 | $parser->error('Unexpected dot.', $token); |
402 | 402 | } |
403 | 403 | |
@@ -414,11 +414,11 @@ discard block |
||
414 | 414 | $dot = false; |
415 | 415 | } else { |
416 | 416 | // No alias is expected. |
417 | - if (! empty($options['breakOnAlias'])) { |
|
417 | + if (!empty($options['breakOnAlias'])) { |
|
418 | 418 | break; |
419 | 419 | } |
420 | 420 | |
421 | - if (! empty($ret->alias)) { |
|
421 | + if (!empty($ret->alias)) { |
|
422 | 422 | $parser->error('An alias was previously found.', $token); |
423 | 423 | break; |
424 | 424 | } |
@@ -469,7 +469,7 @@ discard block |
||
469 | 469 | $ret = implode('.', Context::escapeAll($fields)); |
470 | 470 | } |
471 | 471 | |
472 | - if (! empty($component->alias)) { |
|
472 | + if (!empty($component->alias)) { |
|
473 | 473 | $ret .= ' AS ' . Context::escape($component->alias); |
474 | 474 | } |
475 | 475 |
@@ -93,7 +93,7 @@ discard block |
||
93 | 93 | ) { |
94 | 94 | $expr->type = $token->keyword; |
95 | 95 | } elseif (($token->type === TokenType::Operator) && ($token->value === ',')) { |
96 | - if (! empty($expr->expr)) { |
|
96 | + if (!empty($expr->expr)) { |
|
97 | 97 | $ret[] = $expr; |
98 | 98 | } |
99 | 99 | |
@@ -106,7 +106,7 @@ discard block |
||
106 | 106 | } |
107 | 107 | |
108 | 108 | // Last iteration was not processed. |
109 | - if (! empty($expr->expr)) { |
|
109 | + if (!empty($expr->expr)) { |
|
110 | 110 | $ret[] = $expr; |
111 | 111 | } |
112 | 112 |
@@ -177,9 +177,9 @@ discard block |
||
177 | 177 | } elseif ($state === 1) { |
178 | 178 | if (($token->type === TokenType::Operator) && ($token->value === '(')) { |
179 | 179 | $positionBeforeSearch = $list->idx; |
180 | - $list->idx++;// Ignore the current token "(" or the search condition will always be true |
|
180 | + $list->idx++; // Ignore the current token "(" or the search condition will always be true |
|
181 | 181 | $nextToken = $list->getNext(); |
182 | - $list->idx = $positionBeforeSearch;// Restore the position |
|
182 | + $list->idx = $positionBeforeSearch; // Restore the position |
|
183 | 183 | |
184 | 184 | if ($nextToken !== null && $nextToken->value === '(') { |
185 | 185 | // Switch to expression mode |
@@ -228,7 +228,7 @@ discard block |
||
228 | 228 | if ($token->type === TokenType::Operator) { |
229 | 229 | // This got back to here and we reached the end of the expression |
230 | 230 | if ($token->value === ')') { |
231 | - $state = 4;// go back to state 4 to fetch options |
|
231 | + $state = 4; // go back to state 4 to fetch options |
|
232 | 232 | continue; |
233 | 233 | } |
234 | 234 | |
@@ -267,7 +267,7 @@ discard block |
||
267 | 267 | public static function build($component): string |
268 | 268 | { |
269 | 269 | $ret = $component->type . ' '; |
270 | - if (! empty($component->name)) { |
|
270 | + if (!empty($component->name)) { |
|
271 | 271 | $ret .= Context::escape($component->name) . ' '; |
272 | 272 | } |
273 | 273 |
@@ -435,7 +435,7 @@ discard block |
||
435 | 435 | // The options of a clause should stay on the same line and everything that follows. |
436 | 436 | if ( |
437 | 437 | $this->options['parts_newline'] |
438 | - && ! $formattedOptions |
|
438 | + && !$formattedOptions |
|
439 | 439 | && empty(self::$inlineClauses[$lastClause]) |
440 | 440 | && ( |
441 | 441 | $curr->type !== TokenType::Keyword |
@@ -492,7 +492,7 @@ discard block |
||
492 | 492 | end($blocksLineEndings) === true |
493 | 493 | || ( |
494 | 494 | empty(self::$inlineClauses[$lastClause]) |
495 | - && ! $shortGroup |
|
495 | + && !$shortGroup |
|
496 | 496 | && $this->options['parts_newline'] |
497 | 497 | ) |
498 | 498 | ) { |
@@ -528,7 +528,7 @@ discard block |
||
528 | 528 | $lineEnded = false; |
529 | 529 | } elseif ( |
530 | 530 | $prev->keyword === 'DELIMITER' |
531 | - || ! ( |
|
531 | + || !( |
|
532 | 532 | ($prev->type === TokenType::Operator && ($prev->value === '.' || $prev->value === '(')) |
533 | 533 | // No space after . ( |
534 | 534 | || ($curr->type === TokenType::Operator |
@@ -643,13 +643,13 @@ discard block |
||
643 | 643 | |
644 | 644 | foreach ($this->options['formats'] as $format) { |
645 | 645 | if ( |
646 | - $token->type->value !== $format['type'] || ! (($token->flags & $format['flags']) === $format['flags']) |
|
646 | + $token->type->value !== $format['type'] || !(($token->flags & $format['flags']) === $format['flags']) |
|
647 | 647 | ) { |
648 | 648 | continue; |
649 | 649 | } |
650 | 650 | |
651 | 651 | // Running transformation function. |
652 | - if (! empty($format['function'])) { |
|
652 | + if (!empty($format['function'])) { |
|
653 | 653 | $func = $format['function']; |
654 | 654 | $text = $func($text); |
655 | 655 | } |
@@ -758,7 +758,7 @@ discard block |
||
758 | 758 | * |
759 | 759 | * @psalm-return 1|2|false |
760 | 760 | */ |
761 | - public static function isClause($token): int|false |
|
761 | + public static function isClause($token): int | false |
|
762 | 762 | { |
763 | 763 | if ( |
764 | 764 | ($token->type === TokenType::Keyword && isset(Parser::$statementParsers[$token->keyword])) |
@@ -300,23 +300,23 @@ discard block |
||
300 | 300 | $flags['distinct'] = true; |
301 | 301 | } |
302 | 302 | |
303 | - if (! empty($statement->group) || ! empty($statement->having)) { |
|
303 | + if (!empty($statement->group) || !empty($statement->having)) { |
|
304 | 304 | $flags['is_group'] = true; |
305 | 305 | } |
306 | 306 | |
307 | - if (! empty($statement->into) && ($statement->into->type === 'OUTFILE')) { |
|
307 | + if (!empty($statement->into) && ($statement->into->type === 'OUTFILE')) { |
|
308 | 308 | $flags['is_export'] = true; |
309 | 309 | } |
310 | 310 | |
311 | 311 | $expressions = $statement->expr; |
312 | - if (! empty($statement->join)) { |
|
312 | + if (!empty($statement->join)) { |
|
313 | 313 | foreach ($statement->join as $join) { |
314 | 314 | $expressions[] = $join->expr; |
315 | 315 | } |
316 | 316 | } |
317 | 317 | |
318 | 318 | foreach ($expressions as $expr) { |
319 | - if (! empty($expr->function)) { |
|
319 | + if (!empty($expr->function)) { |
|
320 | 320 | if ($expr->function === 'COUNT') { |
321 | 321 | $flags['is_count'] = true; |
322 | 322 | } elseif (in_array($expr->function, static::$functions)) { |
@@ -331,15 +331,15 @@ discard block |
||
331 | 331 | $flags['is_subquery'] = true; |
332 | 332 | } |
333 | 333 | |
334 | - if (! empty($statement->procedure) && ($statement->procedure->name === 'ANALYSE')) { |
|
334 | + if (!empty($statement->procedure) && ($statement->procedure->name === 'ANALYSE')) { |
|
335 | 335 | $flags['is_analyse'] = true; |
336 | 336 | } |
337 | 337 | |
338 | - if (! empty($statement->group)) { |
|
338 | + if (!empty($statement->group)) { |
|
339 | 339 | $flags['group'] = true; |
340 | 340 | } |
341 | 341 | |
342 | - if (! empty($statement->having)) { |
|
342 | + if (!empty($statement->having)) { |
|
343 | 343 | $flags['having'] = true; |
344 | 344 | } |
345 | 345 | |
@@ -347,7 +347,7 @@ discard block |
||
347 | 347 | $flags['union'] = true; |
348 | 348 | } |
349 | 349 | |
350 | - if (! empty($statement->join)) { |
|
350 | + if (!empty($statement->join)) { |
|
351 | 351 | $flags['join'] = true; |
352 | 352 | } |
353 | 353 | |
@@ -438,11 +438,11 @@ discard block |
||
438 | 438 | || ($statement instanceof UpdateStatement) |
439 | 439 | || ($statement instanceof DeleteStatement) |
440 | 440 | ) { |
441 | - if (! empty($statement->limit)) { |
|
441 | + if (!empty($statement->limit)) { |
|
442 | 442 | $flags['limit'] = true; |
443 | 443 | } |
444 | 444 | |
445 | - if (! empty($statement->order)) { |
|
445 | + if (!empty($statement->order)) { |
|
446 | 446 | $flags['order'] = true; |
447 | 447 | } |
448 | 448 | } |
@@ -492,7 +492,7 @@ discard block |
||
492 | 492 | // Finding tables' aliases and their associated real names. |
493 | 493 | $tableAliases = []; |
494 | 494 | foreach ($statement->from as $expr) { |
495 | - if (! isset($expr->table, $expr->alias) || ($expr->table === '') || ($expr->alias === '')) { |
|
495 | + if (!isset($expr->table, $expr->alias) || ($expr->table === '') || ($expr->alias === '')) { |
|
496 | 496 | continue; |
497 | 497 | } |
498 | 498 | |
@@ -517,7 +517,7 @@ discard block |
||
517 | 517 | ]; |
518 | 518 | } |
519 | 519 | |
520 | - if (! in_array($arr, $ret['select_tables'])) { |
|
520 | + if (!in_array($arr, $ret['select_tables'])) { |
|
521 | 521 | $ret['select_tables'][] = $arr; |
522 | 522 | } |
523 | 523 | } else { |
@@ -530,7 +530,7 @@ discard block |
||
530 | 530 | // extracted from the FROM clause. |
531 | 531 | if ($ret['select_tables'] === []) { |
532 | 532 | foreach ($statement->from as $expr) { |
533 | - if (! isset($expr->table) || ($expr->table === '')) { |
|
533 | + if (!isset($expr->table) || ($expr->table === '')) { |
|
534 | 534 | continue; |
535 | 535 | } |
536 | 536 | |
@@ -571,7 +571,7 @@ discard block |
||
571 | 571 | } elseif (($statement instanceof AlterStatement) || ($statement instanceof TruncateStatement)) { |
572 | 572 | $expressions = [$statement->table]; |
573 | 573 | } elseif ($statement instanceof DropStatement) { |
574 | - if (! $statement->options->has('TABLE')) { |
|
574 | + if (!$statement->options->has('TABLE')) { |
|
575 | 575 | // No tables are dropped. |
576 | 576 | return []; |
577 | 577 | } |
@@ -845,7 +845,7 @@ discard block |
||
845 | 845 | |
846 | 846 | $statement .= $token->token; |
847 | 847 | |
848 | - if (($token->type === TokenType::Delimiter) && ! empty($token->token)) { |
|
848 | + if (($token->type === TokenType::Delimiter) && !empty($token->token)) { |
|
849 | 849 | $delimiter = $token->token; |
850 | 850 | $fullStatement = true; |
851 | 851 | break; |
@@ -854,7 +854,7 @@ discard block |
||
854 | 854 | |
855 | 855 | // No statement was found so we return the entire query as being the |
856 | 856 | // remaining part. |
857 | - if (! $fullStatement) { |
|
857 | + if (!$fullStatement) { |
|
858 | 858 | return [ |
859 | 859 | null, |
860 | 860 | $query, |