Completed
Push — 1.1 ( 6ab797...def185 )
by David
03:11
created
src/Mouf/Database/MagicQuery/Twig/SqlTwigEnvironmentFactory.php 1 patch
Unused Use Statements   -2 removed lines patch added patch discarded remove patch
@@ -1,8 +1,6 @@
 block discarded – undo
1 1
 <?php
2 2
 namespace Mouf\Database\MagicQuery\Twig;
3 3
 
4
-use Doctrine\DBAL\Connection;
5
-
6 4
 /**
7 5
  * Class in charge of creating the Twig environment
8 6
  */
Please login to merge, or discard this patch.
src/Mouf/Database/QueryWriter/Condition/ParamNotAvailableCondition.php 1 patch
Doc Comments   -1 removed lines patch added patch discarded remove patch
@@ -24,7 +24,6 @@
 block discarded – undo
24 24
     }
25 25
 
26 26
     /**
27
-     * @param string $caller
28 27
      */
29 28
     public function isOk($parameters = null)
30 29
     {
Please login to merge, or discard this patch.
src/SQLParser/Node/NodeFactory.php 2 patches
Doc Comments   +4 added lines, -1 removed lines patch added patch discarded remove patch
@@ -635,6 +635,9 @@  discard block
 block discarded – undo
635 635
         });
636 636
     }
637 637
 
638
+    /**
639
+     * @param \Closure $callback
640
+     */
638 641
     private static function array_map_deep($array, $callback)
639 642
     {
640 643
         $new = array();
@@ -661,7 +664,7 @@  discard block
 block discarded – undo
661 664
      * @param array       $parameters
662 665
      * @param string      $delimiter
663 666
      * @param bool|string $wrapInBrackets
664
-     * @param int|number  $indent
667
+     * @param integer  $indent
665 668
      * @param int         $conditionsMode
666 669
      *
667 670
      * @return null|string
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -335,7 +335,7 @@  discard block
 block discarded – undo
335 335
             if (!empty($subTree) && !isset($subTree[0])) {
336 336
                 $subTree = StatementFactory::toObject($subTree);
337 337
             } else {
338
-                $subTree = array_map(function ($item) {
338
+                $subTree = array_map(function($item) {
339 339
                     if (is_array($item)) {
340 340
                         return self::toObject($item);
341 341
                     } else {
@@ -365,7 +365,7 @@  discard block
 block discarded – undo
365 365
             array('NOT'),
366 366
             array('&&', 'AND'),
367 367
             array('XOR'),
368
-            array('||', 'OR'), );
368
+            array('||', 'OR'),);
369 369
 
370 370
     private static $OPERATOR_TO_CLASS = array(
371 371
             '=' => 'SQLParser\Node\Equal',
@@ -626,7 +626,7 @@  discard block
 block discarded – undo
626 626
     {
627 627
         $instanceDescriptor = $moufManager->createInstance(get_called_class());
628 628
 
629
-        return self::array_map_deep($node, function ($item) use ($moufManager) {
629
+        return self::array_map_deep($node, function($item) use ($moufManager) {
630 630
             if ($item instanceof NodeInterface) {
631 631
                 return $item->toInstanceDescriptor($moufManager);
632 632
             } else {
@@ -670,7 +670,7 @@  discard block
 block discarded – undo
670 670
     {
671 671
         if (is_array($nodes)) {
672 672
             $elems = array();
673
-            array_walk_recursive($nodes, function ($item) use (&$elems, $dbConnection, $indent, $delimiter, $parameters, $conditionsMode) {
673
+            array_walk_recursive($nodes, function($item) use (&$elems, $dbConnection, $indent, $delimiter, $parameters, $conditionsMode) {
674 674
                 if ($item instanceof SqlRenderInterface) {
675 675
                     $itemSql = $item->toSql($parameters, $dbConnection, $indent, $conditionsMode);
676 676
                     if ($itemSql !== null) {
Please login to merge, or discard this patch.
src/SQLParser/Node/SubQuery.php 2 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -181,7 +181,7 @@
 block discarded – undo
181 181
      *
182 182
      * @param Connection $dbConnection
183 183
      * @param array $parameters
184
-     * @param number $indent
184
+     * @param integer $indent
185 185
      * @param int $conditionsMode
186 186
      *
187 187
      * @return string
Please login to merge, or discard this patch.
Unused Use Statements   -1 removed lines patch added patch discarded remove patch
@@ -39,7 +39,6 @@
 block discarded – undo
39 39
 use SQLParser\Query\Select;
40 40
 use Mouf\MoufInstanceDescriptor;
41 41
 use Mouf\MoufManager;
42
-use SQLParser\SqlRenderInterface;
43 42
 
44 43
 /**
45 44
  * This class represents a subquery (and optionally a JOIN .. ON expression in an SQL expression.
Please login to merge, or discard this patch.
src/SQLParser/OracleSQLTranslator.php 2 patches
Doc Comments   +13 added lines patch added patch discarded remove patch
@@ -57,6 +57,9 @@  discard block
 block discarded – undo
57 57
         $this->allTables = array();
58 58
     }
59 59
 
60
+    /**
61
+     * @param string $txt
62
+     */
60 63
     public static function dbgprint($txt)
61 64
     {
62 65
         if (isset($_ENV['DEBUG'])) {
@@ -95,6 +98,9 @@  discard block
 block discarded – undo
95 98
         return 'DELETE';
96 99
     }
97 100
 
101
+    /**
102
+     * @param string $column
103
+     */
98 104
     public static function getColumnNameFor($column)
99 105
     {
100 106
         if (strtolower($column) === 'uid') {
@@ -198,6 +204,10 @@  discard block
 block discarded – undo
198 204
         return ($res >= 1);
199 205
     }
200 206
 
207
+    /**
208
+     * @param string $table
209
+     * @param string $column
210
+     */
201 211
     protected function isCLOBColumn($table, $column)
202 212
     {
203 213
         $tables = end($this->allTables);
@@ -314,6 +324,9 @@  discard block
 block discarded – undo
314 324
         return 'SELECT '.$sql;
315 325
     }
316 326
 
327
+    /**
328
+     * @param string $sql
329
+     */
317 330
     private function correctColRefStatement($sql)
318 331
     {
319 332
         $alias = '';
Please login to merge, or discard this patch.
Switch Indentation   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -368,14 +368,14 @@
 block discarded – undo
368 368
     {
369 369
         $k = key($parsed);
370 370
         switch ($k) {
371
-        case 'USE':
372
-        # this statement is not an Oracle statement
373
-            $this->created = '';
374
-            break;
375
-
376
-        default:
377
-            $this->created = parent::create($parsed);
378
-            break;
371
+            case 'USE':
372
+            # this statement is not an Oracle statement
373
+                $this->created = '';
374
+                break;
375
+
376
+            default:
377
+                $this->created = parent::create($parsed);
378
+                break;
379 379
         }
380 380
 
381 381
         return $this->created;
Please login to merge, or discard this patch.
src/SQLParser/PHPSQLLexer.php 1 patch
Doc Comments   +4 added lines patch added patch discarded remove patch
@@ -237,6 +237,10 @@
 block discarded – undo
237 237
 
238 238
     # backticks are not balanced within one token, so we have
239 239
     # to re-combine some tokens
240
+
241
+    /**
242
+     * @param integer $idx
243
+     */
240 244
     private function balanceCharacter($tokens, $idx, $char)
241 245
     {
242 246
         $token_count = count($tokens);
Please login to merge, or discard this patch.
src/SQLParser/PHPSQLParserUtils.php 1 patch
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -43,7 +43,6 @@  discard block
 block discarded – undo
43 43
     /**
44 44
      * Prints an array only if debug mode is on.
45 45
      *
46
-     * @param array $s
47 46
      * @param bool  $return, if true, the formatted array is returned via return parameter
48 47
      */
49 48
     protected function preprint($arr, $return = false)
@@ -80,6 +79,7 @@  discard block
 block discarded – undo
80 79
 
81 80
     /**
82 81
      * Revokes the escaping characters from an expression.
82
+     * @param string $sql
83 83
      */
84 84
     protected function revokeEscaping($sql)
85 85
     {
Please login to merge, or discard this patch.
src/SQLParser/PositionCalculator.php 3 patches
Doc Comments   +7 added lines patch added patch discarded remove patch
@@ -73,6 +73,9 @@  discard block
 block discarded – undo
73 73
         return $parsed;
74 74
     }
75 75
 
76
+    /**
77
+     * @param string $sql
78
+     */
76 79
     private function findPositionWithinString($sql, $value, $expr_type)
77 80
     {
78 81
         $offset = 0;
@@ -130,6 +133,10 @@  discard block
 block discarded – undo
130 133
         return $pos;
131 134
     }
132 135
 
136
+    /**
137
+     * @param integer $charPos
138
+     * @param integer $key
139
+     */
133 140
     private function lookForBaseExpression($sql, &$charPos, &$parsed, $key, &$backtracking)
134 141
     {
135 142
         if (!is_numeric($key)) {
Please login to merge, or discard this patch.
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -44,7 +44,7 @@
 block discarded – undo
44 44
 {
45 45
     private static $allowedOnOperator = array("\t", "\n", "\r", ' ', ',', '(', ')', '_', "'", '"');
46 46
     private static $allowedOnOther = array("\t", "\n", "\r", ' ', ',', '(', ')', '<', '>', '*', '+', '-', '/', '|',
47
-                                           '&', '=', '!', ';', );
47
+                                            '&', '=', '!', ';', );
48 48
 
49 49
     private function printPos($text, $sql, $charPos, $key, $parsed, $backtracking)
50 50
     {
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -44,7 +44,7 @@
 block discarded – undo
44 44
 {
45 45
     private static $allowedOnOperator = array("\t", "\n", "\r", ' ', ',', '(', ')', '_', "'", '"');
46 46
     private static $allowedOnOther = array("\t", "\n", "\r", ' ', ',', '(', ')', '<', '>', '*', '+', '-', '/', '|',
47
-                                           '&', '=', '!', ';', );
47
+                                           '&', '=', '!', ';',);
48 48
 
49 49
     private function printPos($text, $sql, $charPos, $key, $parsed, $backtracking)
50 50
     {
Please login to merge, or discard this patch.
src/SQLParser/SQLParser.php 4 patches
Doc Comments   +15 added lines patch added patch discarded remove patch
@@ -51,6 +51,9 @@  discard block
 block discarded – undo
51 51
         }
52 52
     }
53 53
 
54
+    /**
55
+     * @param string|boolean $sql
56
+     */
54 57
     public function parse($sql, $calcPositions = false)
55 58
     {
56 59
         #lex the SQL statement
@@ -499,6 +502,9 @@  discard block
 block discarded – undo
499 502
         return $this->processSQLParts($out);
500 503
     }
501 504
 
505
+    /**
506
+     * @param boolean $out
507
+     */
502 508
     private function processSQLParts($out)
503 509
     {
504 510
         if (!$out) {
@@ -565,6 +571,7 @@  discard block
 block discarded – undo
565 571
     /**
566 572
      *  A SET list is simply a list of key = value expressions separated by comma (,).
567 573
      *  This function produces a list of the key/value expressions.
574
+     * @param string $base_expr
568 575
      */
569 576
     private function getAssignment($base_expr)
570 577
     {
@@ -574,6 +581,9 @@  discard block
 block discarded – undo
574 581
                      'sub_tree' => $assignment, );
575 582
     }
576 583
 
584
+    /**
585
+     * @param string $expression
586
+     */
577 587
     private function getVariableType($expression)
578 588
     {
579 589
         // $expression must contain only upper-case characters
@@ -601,6 +611,7 @@  discard block
 block discarded – undo
601 611
 
602 612
     /**
603 613
      * It can be UPDATE SET or SET alone.
614
+     * @param boolean $isUpdate
604 615
      */
605 616
     private function process_set_list($tokens, $isUpdate)
606 617
     {
@@ -730,6 +741,9 @@  discard block
 block discarded – undo
730 741
         return (trim($token) === '');
731 742
     }
732 743
 
744
+    /**
745
+     * @param string $token
746
+     */
733 747
     private function isCommentToken($token)
734 748
     {
735 749
         return isset($token[0]) && isset($token[1])
@@ -1490,6 +1504,7 @@  discard block
 block discarded – undo
1490 1504
 
1491 1505
     /**
1492 1506
      * This method handles INSERT and REPLACE statements.
1507
+     * @param string $token_category
1493 1508
      */
1494 1509
     private function processInsertOrReplace($tokenList, $token_category)
1495 1510
     {
Please login to merge, or discard this patch.
Indentation   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -571,7 +571,7 @@  discard block
 block discarded – undo
571 571
         $assignment = $this->process_expr_list($this->splitSQLIntoTokens($base_expr));
572 572
 
573 573
         return array('expr_type' => ExpressionType::EXPRESSION, 'base_expr' => trim($base_expr),
574
-                     'sub_tree' => $assignment, );
574
+                        'sub_tree' => $assignment, );
575 575
     }
576 576
 
577 577
     private function getVariableType($expression)
@@ -843,7 +843,7 @@  discard block
 block discarded – undo
843 843
                     || $this->isFunction($prev) || $this->isExpression($prev) || $this->isSubQuery($prev)
844 844
                     || $this->isColumnReference($prev) || $this->isBracketExpression($prev)) {
845 845
                 $alias = array('as' => false, 'name' => trim($last['base_expr']),
846
-                               'base_expr' => trim($last['base_expr']), );
846
+                                'base_expr' => trim($last['base_expr']), );
847 847
                 #remove the last token
848 848
                 array_pop($tokens);
849 849
                 $base_expr = implode('', $tokens);
@@ -873,7 +873,7 @@  discard block
 block discarded – undo
873 873
         }
874 874
 
875 875
         return array('expr_type' => $type, 'alias' => $alias, 'base_expr' => trim($base_expr),
876
-                     'sub_tree' => $processed, );
876
+                        'sub_tree' => $processed, );
877 877
     }
878 878
 
879 879
     /**
@@ -1013,9 +1013,9 @@  discard block
 block discarded – undo
1013 1013
         }
1014 1014
         # loop init
1015 1015
         return array('expression' => '', 'token_count' => 0, 'table' => '', 'alias' => false, 'join_type' => '',
1016
-                     'next_join_type' => '', 'saved_join_type' => $parseInfo['saved_join_type'],
1017
-                     'ref_type' => false, 'ref_expr' => false, 'base_expr' => false, 'sub_tree' => false,
1018
-                     'subquery' => '', );
1016
+                        'next_join_type' => '', 'saved_join_type' => $parseInfo['saved_join_type'],
1017
+                        'ref_type' => false, 'ref_expr' => false, 'base_expr' => false, 'sub_tree' => false,
1018
+                        'subquery' => '', );
1019 1019
     }
1020 1020
 
1021 1021
     private function processFromExpression(&$parseInfo)
@@ -1099,7 +1099,7 @@  discard block
 block discarded – undo
1099 1099
         }
1100 1100
 
1101 1101
         return array('expr_type' => $parseInfo['type'], 'base_expr' => $parseInfo['expr'],
1102
-                     'direction' => $parseInfo['dir'], );
1102
+                        'direction' => $parseInfo['dir'], );
1103 1103
     }
1104 1104
 
1105 1105
     private function initParseInfoForOrder()
Please login to merge, or discard this patch.
Switch Indentation   +468 added lines, -468 removed lines patch added patch discarded remove patch
@@ -245,246 +245,246 @@  discard block
 block discarded – undo
245 245
             switch ($upper) {
246 246
 
247 247
             /* Tokens that get their own sections. These keywords have subclauses. */
248
-            case 'SELECT':
249
-            case 'ORDER':
250
-            case 'LIMIT':
251
-            case 'SET':
252
-            case 'DUPLICATE':
253
-            case 'VALUES':
254
-            case 'GROUP':
255
-            case 'HAVING':
256
-            case 'WHERE':
257
-            case 'RENAME':
258
-            case 'CALL':
259
-            case 'PROCEDURE':
260
-            case 'FUNCTION':
261
-            case 'SERVER':
262
-            case 'LOGFILE':
263
-            case 'DEFINER':
264
-            case 'RETURNS':
265
-            case 'TABLESPACE':
266
-            case 'TRIGGER':
267
-            case 'DO':
268
-            case 'PLUGIN':
269
-            case 'FROM':
270
-            case 'FLUSH':
271
-            case 'KILL':
272
-            case 'RESET':
273
-            case 'START':
274
-            case 'STOP':
275
-            case 'PURGE':
276
-            case 'EXECUTE':
277
-            case 'PREPARE':
278
-            case 'DEALLOCATE':
279
-                if ($trim === 'DEALLOCATE') {
280
-                    $skip_next = true;
281
-                }
282
-                /* this FROM is different from FROM in other DML (not join related) */
283
-                if ($token_category === 'PREPARE' && $upper === 'FROM') {
284
-                    continue 2;
285
-                }
286
-
287
-                $token_category = $upper;
288
-                break;
289
-
290
-            case 'DATABASE':
291
-            case 'SCHEMA':
292
-                if ($prev_category === 'DROP') {
293
-                    continue;
294
-                }
295
-                $token_category = $upper;
296
-                break;
248
+                case 'SELECT':
249
+                case 'ORDER':
250
+                case 'LIMIT':
251
+                case 'SET':
252
+                case 'DUPLICATE':
253
+                case 'VALUES':
254
+                case 'GROUP':
255
+                case 'HAVING':
256
+                case 'WHERE':
257
+                case 'RENAME':
258
+                case 'CALL':
259
+                case 'PROCEDURE':
260
+                case 'FUNCTION':
261
+                case 'SERVER':
262
+                case 'LOGFILE':
263
+                case 'DEFINER':
264
+                case 'RETURNS':
265
+                case 'TABLESPACE':
266
+                case 'TRIGGER':
267
+                case 'DO':
268
+                case 'PLUGIN':
269
+                case 'FROM':
270
+                case 'FLUSH':
271
+                case 'KILL':
272
+                case 'RESET':
273
+                case 'START':
274
+                case 'STOP':
275
+                case 'PURGE':
276
+                case 'EXECUTE':
277
+                case 'PREPARE':
278
+                case 'DEALLOCATE':
279
+                    if ($trim === 'DEALLOCATE') {
280
+                        $skip_next = true;
281
+                    }
282
+                    /* this FROM is different from FROM in other DML (not join related) */
283
+                    if ($token_category === 'PREPARE' && $upper === 'FROM') {
284
+                        continue 2;
285
+                    }
297 286
 
298
-            case 'EVENT':
299
-            # issue 71
300
-                if ($prev_category === 'DROP' || $prev_category === 'ALTER' || $prev_category === 'CREATE') {
301 287
                     $token_category = $upper;
302
-                }
303
-                break;
288
+                    break;
304 289
 
305
-            case 'DATA':
306
-            # prevent wrong handling of DATA as keyword
307
-                if ($prev_category === 'LOAD') {
290
+                case 'DATABASE':
291
+                case 'SCHEMA':
292
+                    if ($prev_category === 'DROP') {
293
+                        continue;
294
+                    }
308 295
                     $token_category = $upper;
309
-                }
310
-                break;
296
+                    break;
311 297
 
312
-            case 'INTO':
313
-            # prevent wrong handling of CACHE within LOAD INDEX INTO CACHE...
314
-                if ($prev_category === 'LOAD') {
315
-                    $out[$prev_category][] = $upper;
316
-                    continue 2;
317
-                }
318
-                $token_category = $upper;
319
-                break;
298
+                case 'EVENT':
299
+                # issue 71
300
+                    if ($prev_category === 'DROP' || $prev_category === 'ALTER' || $prev_category === 'CREATE') {
301
+                        $token_category = $upper;
302
+                    }
303
+                    break;
320 304
 
321
-            case 'USER':
322
-            # prevent wrong processing as keyword
323
-                if ($prev_category === 'CREATE' || $prev_category === 'RENAME' || $prev_category === 'DROP') {
324
-                    $token_category = $upper;
325
-                }
326
-                break;
305
+                case 'DATA':
306
+                # prevent wrong handling of DATA as keyword
307
+                    if ($prev_category === 'LOAD') {
308
+                        $token_category = $upper;
309
+                    }
310
+                    break;
327 311
 
328
-            case 'VIEW':
329
-            # prevent wrong processing as keyword
330
-                if ($prev_category === 'CREATE' || $prev_category === 'ALTER' || $prev_category === 'DROP') {
312
+                case 'INTO':
313
+                # prevent wrong handling of CACHE within LOAD INDEX INTO CACHE...
314
+                    if ($prev_category === 'LOAD') {
315
+                        $out[$prev_category][] = $upper;
316
+                        continue 2;
317
+                    }
331 318
                     $token_category = $upper;
332
-                }
333
-                break;
319
+                    break;
334 320
 
335
-            /* These tokens get their own section, but have no subclauses.
321
+                case 'USER':
322
+                # prevent wrong processing as keyword
323
+                    if ($prev_category === 'CREATE' || $prev_category === 'RENAME' || $prev_category === 'DROP') {
324
+                        $token_category = $upper;
325
+                    }
326
+                    break;
327
+
328
+                case 'VIEW':
329
+                # prevent wrong processing as keyword
330
+                    if ($prev_category === 'CREATE' || $prev_category === 'ALTER' || $prev_category === 'DROP') {
331
+                        $token_category = $upper;
332
+                    }
333
+                    break;
334
+
335
+                /* These tokens get their own section, but have no subclauses.
336 336
              These tokens identify the statement but have no specific subclauses of their own. */
337
-            case 'DELETE':
338
-            case 'ALTER':
339
-            case 'INSERT':
340
-            case 'REPLACE':
341
-            case 'TRUNCATE':
342
-            case 'CREATE':
343
-            case 'TRUNCATE':
344
-            case 'OPTIMIZE':
345
-            case 'GRANT':
346
-            case 'REVOKE':
347
-            case 'SHOW':
348
-            case 'HANDLER':
349
-            case 'LOAD':
350
-            case 'ROLLBACK':
351
-            case 'SAVEPOINT':
352
-            case 'UNLOCK':
353
-            case 'INSTALL':
354
-            case 'UNINSTALL':
355
-            case 'ANALZYE':
356
-            case 'BACKUP':
357
-            case 'CHECK':
358
-            case 'CHECKSUM':
359
-            case 'REPAIR':
360
-            case 'RESTORE':
361
-            case 'DESCRIBE':
362
-            case 'EXPLAIN':
363
-            case 'USE':
364
-            case 'HELP':
365
-                $token_category = $upper; /* set the category in case these get subclauses
337
+                case 'DELETE':
338
+                case 'ALTER':
339
+                case 'INSERT':
340
+                case 'REPLACE':
341
+                case 'TRUNCATE':
342
+                case 'CREATE':
343
+                case 'TRUNCATE':
344
+                case 'OPTIMIZE':
345
+                case 'GRANT':
346
+                case 'REVOKE':
347
+                case 'SHOW':
348
+                case 'HANDLER':
349
+                case 'LOAD':
350
+                case 'ROLLBACK':
351
+                case 'SAVEPOINT':
352
+                case 'UNLOCK':
353
+                case 'INSTALL':
354
+                case 'UNINSTALL':
355
+                case 'ANALZYE':
356
+                case 'BACKUP':
357
+                case 'CHECK':
358
+                case 'CHECKSUM':
359
+                case 'REPAIR':
360
+                case 'RESTORE':
361
+                case 'DESCRIBE':
362
+                case 'EXPLAIN':
363
+                case 'USE':
364
+                case 'HELP':
365
+                    $token_category = $upper; /* set the category in case these get subclauses
366 366
                                           in a future version of MySQL */
367
-                $out[$upper][0] = $upper;
368
-                continue 2;
369
-                break;
370
-
371
-            case 'CACHE':
372
-                if ($prev_category === '' || $prev_category === 'RESET' || $prev_category === 'FLUSH'
373
-                        || $prev_category === 'LOAD') {
374
-                    $token_category = $upper;
367
+                    $out[$upper][0] = $upper;
375 368
                     continue 2;
376
-                }
377
-                break;
369
+                    break;
378 370
 
379
-            /* This is either LOCK TABLES or SELECT ... LOCK IN SHARE MODE*/
380
-            case 'LOCK':
381
-                if ($token_category === '') {
382
-                    $token_category = $upper;
383
-                    $out[$upper][0] = $upper;
384
-                } else {
385
-                    $trim = 'LOCK IN SHARE MODE';
386
-                    $skip_next = true;
387
-                    $out['OPTIONS'][] = $trim;
388
-                }
389
-                continue 2;
390
-                break;
371
+                case 'CACHE':
372
+                    if ($prev_category === '' || $prev_category === 'RESET' || $prev_category === 'FLUSH'
373
+                            || $prev_category === 'LOAD') {
374
+                        $token_category = $upper;
375
+                        continue 2;
376
+                    }
377
+                    break;
391 378
 
392
-            case 'USING': /* USING in FROM clause is different from USING w/ prepared statement*/
393
-                if ($token_category === 'EXECUTE') {
394
-                    $token_category = $upper;
395
-                    continue 2;
396
-                }
397
-                if ($token_category === 'FROM' && !empty($out['DELETE'])) {
398
-                    $token_category = $upper;
379
+                /* This is either LOCK TABLES or SELECT ... LOCK IN SHARE MODE*/
380
+                case 'LOCK':
381
+                    if ($token_category === '') {
382
+                        $token_category = $upper;
383
+                        $out[$upper][0] = $upper;
384
+                    } else {
385
+                        $trim = 'LOCK IN SHARE MODE';
386
+                        $skip_next = true;
387
+                        $out['OPTIONS'][] = $trim;
388
+                    }
399 389
                     continue 2;
400
-                }
401
-                break;
390
+                    break;
402 391
 
403
-            /* DROP TABLE is different from ALTER TABLE DROP ... */
404
-            case 'DROP':
405
-                if ($token_category !== 'ALTER') {
406
-                    $token_category = $upper;
407
-                    continue 2;
408
-                }
409
-                break;
392
+                case 'USING': /* USING in FROM clause is different from USING w/ prepared statement*/
393
+                    if ($token_category === 'EXECUTE') {
394
+                        $token_category = $upper;
395
+                        continue 2;
396
+                    }
397
+                    if ($token_category === 'FROM' && !empty($out['DELETE'])) {
398
+                        $token_category = $upper;
399
+                        continue 2;
400
+                    }
401
+                    break;
410 402
 
411
-            case 'FOR':
412
-                $skip_next = true;
413
-                $out['OPTIONS'][] = 'FOR UPDATE';
414
-                continue 2;
415
-                break;
403
+                /* DROP TABLE is different from ALTER TABLE DROP ... */
404
+                case 'DROP':
405
+                    if ($token_category !== 'ALTER') {
406
+                        $token_category = $upper;
407
+                        continue 2;
408
+                    }
409
+                    break;
416 410
 
417
-            case 'UPDATE':
418
-                if ($token_category === '') {
419
-                    $token_category = $upper;
420
-                    continue 2;
421
-                }
422
-                if ($token_category === 'DUPLICATE') {
411
+                case 'FOR':
412
+                    $skip_next = true;
413
+                    $out['OPTIONS'][] = 'FOR UPDATE';
423 414
                     continue 2;
424
-                }
425
-                break;
415
+                    break;
426 416
 
427
-            case 'START':
428
-                $trim = 'BEGIN';
429
-                $out[$upper][0] = $upper;
430
-                $skip_next = true;
431
-                break;
417
+                case 'UPDATE':
418
+                    if ($token_category === '') {
419
+                        $token_category = $upper;
420
+                        continue 2;
421
+                    }
422
+                    if ($token_category === 'DUPLICATE') {
423
+                        continue 2;
424
+                    }
425
+                    break;
432 426
 
433
-            /* These tokens are ignored. */
434
-            case 'BY':
435
-            case 'ALL':
436
-            case 'SHARE':
437
-            case 'MODE':
438
-            case 'TO':
439
-            case ';':
440
-                continue 2;
441
-                break;
427
+                case 'START':
428
+                    $trim = 'BEGIN';
429
+                    $out[$upper][0] = $upper;
430
+                    $skip_next = true;
431
+                    break;
442 432
 
443
-            case 'KEY':
444
-                if ($token_category === 'DUPLICATE') {
433
+                /* These tokens are ignored. */
434
+                case 'BY':
435
+                case 'ALL':
436
+                case 'SHARE':
437
+                case 'MODE':
438
+                case 'TO':
439
+                case ';':
445 440
                     continue 2;
446
-                }
447
-                break;
441
+                    break;
448 442
 
449
-            /* These tokens set particular options for the statement.  They never stand alone.*/
450
-            case 'DISTINCTROW':
451
-                $trim = 'DISTINCT';
452
-            case 'DISTINCT':
453
-            case 'HIGH_PRIORITY':
454
-            case 'LOW_PRIORITY':
455
-            case 'DELAYED':
456
-            case 'IGNORE':
457
-            case 'FORCE':
458
-            case 'STRAIGHT_JOIN':
459
-            case 'SQL_SMALL_RESULT':
460
-            case 'SQL_BIG_RESULT':
461
-            case 'QUICK':
462
-            case 'SQL_BUFFER_RESULT':
463
-            case 'SQL_CACHE':
464
-            case 'SQL_NO_CACHE':
465
-            case 'SQL_CALC_FOUND_ROWS':
466
-                $out['OPTIONS'][] = $upper;
467
-                continue 2;
468
-                break;
443
+                case 'KEY':
444
+                    if ($token_category === 'DUPLICATE') {
445
+                        continue 2;
446
+                    }
447
+                    break;
469 448
 
470
-            case 'WITH':
471
-                if ($token_category === 'GROUP') {
472
-                    $skip_next = true;
473
-                    $out['OPTIONS'][] = 'WITH ROLLUP';
449
+                /* These tokens set particular options for the statement.  They never stand alone.*/
450
+                case 'DISTINCTROW':
451
+                    $trim = 'DISTINCT';
452
+                case 'DISTINCT':
453
+                case 'HIGH_PRIORITY':
454
+                case 'LOW_PRIORITY':
455
+                case 'DELAYED':
456
+                case 'IGNORE':
457
+                case 'FORCE':
458
+                case 'STRAIGHT_JOIN':
459
+                case 'SQL_SMALL_RESULT':
460
+                case 'SQL_BIG_RESULT':
461
+                case 'QUICK':
462
+                case 'SQL_BUFFER_RESULT':
463
+                case 'SQL_CACHE':
464
+                case 'SQL_NO_CACHE':
465
+                case 'SQL_CALC_FOUND_ROWS':
466
+                    $out['OPTIONS'][] = $upper;
474 467
                     continue 2;
475
-                }
476
-                break;
468
+                    break;
477 469
 
478
-            case 'AS':
479
-                break;
470
+                case 'WITH':
471
+                    if ($token_category === 'GROUP') {
472
+                        $skip_next = true;
473
+                        $out['OPTIONS'][] = 'WITH ROLLUP';
474
+                        continue 2;
475
+                    }
476
+                    break;
480 477
 
481
-            case '':
482
-            case ',':
483
-            case ';':
484
-                break;
478
+                case 'AS':
479
+                    break;
485 480
 
486
-            default:
487
-                break;
481
+                case '':
482
+                case ',':
483
+                case ';':
484
+                    break;
485
+
486
+                default:
487
+                    break;
488 488
             }
489 489
 
490 490
             # remove obsolete category after union (empty category because of
@@ -584,16 +584,16 @@  discard block
 block discarded – undo
584 584
         $type = substr($expression, 2, strpos($expression, '.', 2));
585 585
 
586 586
         switch ($type) {
587
-        case 'GLOBAL':
588
-            $type = ExpressionType::GLOBAL_VARIABLE;
589
-            break;
590
-        case 'LOCAL':
591
-            $type = ExpressionType::LOCAL_VARIABLE;
592
-            break;
593
-        case 'SESSION':
594
-        default:
595
-            $type = ExpressionType::SESSION_VARIABLE;
596
-            break;
587
+            case 'GLOBAL':
588
+                $type = ExpressionType::GLOBAL_VARIABLE;
589
+                break;
590
+            case 'LOCAL':
591
+                $type = ExpressionType::LOCAL_VARIABLE;
592
+                break;
593
+            case 'SESSION':
594
+            default:
595
+                $type = ExpressionType::SESSION_VARIABLE;
596
+                break;
597 597
         }
598 598
 
599 599
         return $type;
@@ -613,27 +613,27 @@  discard block
 block discarded – undo
613 613
             $upper = strtoupper(trim($token));
614 614
 
615 615
             switch ($upper) {
616
-            case 'LOCAL':
617
-            case 'SESSION':
618
-            case 'GLOBAL':
619
-                if (!$isUpdate) {
620
-                    $varType = $this->getVariableType('@@'.$upper.'.');
616
+                case 'LOCAL':
617
+                case 'SESSION':
618
+                case 'GLOBAL':
619
+                    if (!$isUpdate) {
620
+                        $varType = $this->getVariableType('@@'.$upper.'.');
621
+                        $baseExpr = '';
622
+                        continue 2;
623
+                    }
624
+                    break;
625
+
626
+                case ',':
627
+                    $assignment = $this->getAssignment($baseExpr);
628
+                    if (!$isUpdate && $varType !== false) {
629
+                        $assignment['sub_tree'][0]['expr_type'] = $varType;
630
+                    }
631
+                    $result[] = $assignment;
621 632
                     $baseExpr = '';
633
+                    $varType = false;
622 634
                     continue 2;
623
-                }
624
-                break;
625
-
626
-            case ',':
627
-                $assignment = $this->getAssignment($baseExpr);
628
-                if (!$isUpdate && $varType !== false) {
629
-                    $assignment['sub_tree'][0]['expr_type'] = $varType;
630
-                }
631
-                $result[] = $assignment;
632
-                $baseExpr = '';
633
-                $varType = false;
634
-                continue 2;
635 635
 
636
-            default:
636
+                default:
637 637
             }
638 638
             $baseExpr .= $token;
639 639
         }
@@ -901,101 +901,101 @@  discard block
 block discarded – undo
901 901
             }
902 902
 
903 903
             switch ($upper) {
904
-            case 'OUTER':
905
-            case 'LEFT':
906
-            case 'RIGHT':
907
-            case 'NATURAL':
908
-            case 'CROSS':
909
-            case ',':
910
-            case 'JOIN':
911
-            case 'INNER':
912
-                break;
904
+                case 'OUTER':
905
+                case 'LEFT':
906
+                case 'RIGHT':
907
+                case 'NATURAL':
908
+                case 'CROSS':
909
+                case ',':
910
+                case 'JOIN':
911
+                case 'INNER':
912
+                    break;
913 913
 
914
-            default:
915
-                $parseInfo['expression'] .= $token;
916
-                if ($parseInfo['ref_type'] !== false) { # all after ON / USING
917
-                    $parseInfo['ref_expr'] .= $token;
918
-                }
919
-                break;
914
+                default:
915
+                    $parseInfo['expression'] .= $token;
916
+                    if ($parseInfo['ref_type'] !== false) { # all after ON / USING
917
+                        $parseInfo['ref_expr'] .= $token;
918
+                    }
919
+                    break;
920 920
             }
921 921
 
922 922
             switch ($upper) {
923
-            case 'AS':
924
-                $parseInfo['alias'] = array('as' => true, 'name' => '', 'base_expr' => $token);
925
-                ++$parseInfo['token_count'];
926
-                $n = 1;
927
-                $str = '';
928
-                while ($str == '') {
929
-                    $parseInfo['alias']['base_expr'] .= ($tokens[$i + $n] === '' ? ' ' : $tokens[$i + $n]);
930
-                    $str = trim($tokens[$i + $n]);
931
-                    ++$n;
932
-                }
933
-                $parseInfo['alias']['name'] = $str;
934
-                $parseInfo['alias']['base_expr'] = trim($parseInfo['alias']['base_expr']);
935
-                continue;
923
+                case 'AS':
924
+                    $parseInfo['alias'] = array('as' => true, 'name' => '', 'base_expr' => $token);
925
+                    ++$parseInfo['token_count'];
926
+                    $n = 1;
927
+                    $str = '';
928
+                    while ($str == '') {
929
+                        $parseInfo['alias']['base_expr'] .= ($tokens[$i + $n] === '' ? ' ' : $tokens[$i + $n]);
930
+                        $str = trim($tokens[$i + $n]);
931
+                        ++$n;
932
+                    }
933
+                    $parseInfo['alias']['name'] = $str;
934
+                    $parseInfo['alias']['base_expr'] = trim($parseInfo['alias']['base_expr']);
935
+                    continue;
936 936
 
937
-            case 'INDEX':
938
-                if ($token_category == 'CREATE') {
939
-                    $token_category = $upper;
940
-                    continue 2;
941
-                }
937
+                case 'INDEX':
938
+                    if ($token_category == 'CREATE') {
939
+                        $token_category = $upper;
940
+                        continue 2;
941
+                    }
942 942
 
943
-                break;
943
+                    break;
944 944
 
945
-            case 'USING':
946
-            case 'ON':
947
-                $parseInfo['ref_type'] = $upper;
948
-                $parseInfo['ref_expr'] = '';
949
-
950
-            case 'CROSS':
951
-            case 'USE':
952
-            case 'FORCE':
953
-            case 'IGNORE':
954
-            case 'INNER':
955
-            case 'OUTER':
956
-                $parseInfo['token_count']++;
957
-                continue;
958
-                break;
945
+                case 'USING':
946
+                case 'ON':
947
+                    $parseInfo['ref_type'] = $upper;
948
+                    $parseInfo['ref_expr'] = '';
949
+
950
+                case 'CROSS':
951
+                case 'USE':
952
+                case 'FORCE':
953
+                case 'IGNORE':
954
+                case 'INNER':
955
+                case 'OUTER':
956
+                    $parseInfo['token_count']++;
957
+                    continue;
958
+                    break;
959 959
 
960
-            case 'FOR':
961
-                $parseInfo['token_count']++;
962
-                $skip_next = true;
963
-                continue;
964
-                break;
960
+                case 'FOR':
961
+                    $parseInfo['token_count']++;
962
+                    $skip_next = true;
963
+                    continue;
964
+                    break;
965 965
 
966
-            case 'LEFT':
967
-            case 'RIGHT':
968
-            case 'STRAIGHT_JOIN':
969
-                $parseInfo['next_join_type'] = $upper;
970
-                break;
966
+                case 'LEFT':
967
+                case 'RIGHT':
968
+                case 'STRAIGHT_JOIN':
969
+                    $parseInfo['next_join_type'] = $upper;
970
+                    break;
971 971
 
972
-            case ',':
973
-                $parseInfo['next_join_type'] = 'CROSS';
972
+                case ',':
973
+                    $parseInfo['next_join_type'] = 'CROSS';
974 974
 
975
-            case 'JOIN':
976
-                if ($parseInfo['subquery']) {
977
-                    $parseInfo['sub_tree'] = $this->parse($this->removeParenthesisFromStart($parseInfo['subquery']));
978
-                    $parseInfo['expression'] = $parseInfo['subquery'];
979
-                }
975
+                case 'JOIN':
976
+                    if ($parseInfo['subquery']) {
977
+                        $parseInfo['sub_tree'] = $this->parse($this->removeParenthesisFromStart($parseInfo['subquery']));
978
+                        $parseInfo['expression'] = $parseInfo['subquery'];
979
+                    }
980 980
 
981
-                $expr[] = $this->processFromExpression($parseInfo);
982
-                $parseInfo = $this->initParseInfoForFrom($parseInfo);
983
-                break;
981
+                    $expr[] = $this->processFromExpression($parseInfo);
982
+                    $parseInfo = $this->initParseInfoForFrom($parseInfo);
983
+                    break;
984 984
 
985
-            default:
986
-                if ($upper === '') {
987
-                    continue; # ends the switch statement!
988
-                }
985
+                default:
986
+                    if ($upper === '') {
987
+                        continue; # ends the switch statement!
988
+                    }
989 989
 
990
-                if ($parseInfo['token_count'] === 0) {
991
-                    if ($parseInfo['table'] === '') {
992
-                        $parseInfo['table'] = $token;
990
+                    if ($parseInfo['token_count'] === 0) {
991
+                        if ($parseInfo['table'] === '') {
992
+                            $parseInfo['table'] = $token;
993
+                        }
994
+                    } elseif ($parseInfo['token_count'] === 1) {
995
+                        $parseInfo['alias'] = array('as' => false, 'name' => trim($token), 'base_expr' => trim($token));
993 996
                     }
994
-                } elseif ($parseInfo['token_count'] === 1) {
995
-                    $parseInfo['alias'] = array('as' => false, 'name' => trim($token), 'base_expr' => trim($token));
996
-                }
997
-                ++$parseInfo['token_count'];
998
-                break;
997
+                    ++$parseInfo['token_count'];
998
+                    break;
999 999
             }
1000 1000
             ++$i;
1001 1001
         }
@@ -1122,21 +1122,21 @@  discard block
 block discarded – undo
1122 1122
         foreach ($tokens as $token) {
1123 1123
             $upper = strtoupper(trim($token));
1124 1124
             switch ($upper) {
1125
-            case ',':
1126
-                $out[] = $this->processOrderExpression($parseInfo, $select);
1127
-                $parseInfo = $this->initParseInfoForOrder();
1128
-                break;
1125
+                case ',':
1126
+                    $out[] = $this->processOrderExpression($parseInfo, $select);
1127
+                    $parseInfo = $this->initParseInfoForOrder();
1128
+                    break;
1129 1129
 
1130
-            case 'DESC':
1131
-                $parseInfo['dir'] = 'DESC';
1132
-                break;
1130
+                case 'DESC':
1131
+                    $parseInfo['dir'] = 'DESC';
1132
+                    break;
1133 1133
 
1134
-            case 'ASC':
1135
-                $parseInfo['dir'] = 'ASC';
1136
-                break;
1134
+                case 'ASC':
1135
+                    $parseInfo['dir'] = 'ASC';
1136
+                    break;
1137 1137
 
1138
-            default:
1139
-                $parseInfo['expr'] .= $token;
1138
+                default:
1139
+                    $parseInfo['expr'] .= $token;
1140 1140
 
1141 1141
             }
1142 1142
         }
@@ -1161,15 +1161,15 @@  discard block
 block discarded – undo
1161 1161
         foreach ($tokens as $token) {
1162 1162
             $trim = strtoupper(trim($token));
1163 1163
             switch ($trim) {
1164
-            case ',':
1165
-                $parsed = $this->processOrderExpression($parseInfo, $select);
1166
-                unset($parsed['direction']);
1164
+                case ',':
1165
+                    $parsed = $this->processOrderExpression($parseInfo, $select);
1166
+                    unset($parsed['direction']);
1167 1167
 
1168
-                $out[] = $parsed;
1169
-                $parseInfo = $this->initParseInfoForOrder();
1170
-                break;
1171
-            default:
1172
-                $parseInfo['expr'] .= $token;
1168
+                    $out[] = $parsed;
1169
+                    $parseInfo = $this->initParseInfoForOrder();
1170
+                    break;
1171
+                default:
1172
+                    $parseInfo['expr'] .= $token;
1173 1173
 
1174 1174
             }
1175 1175
         }
@@ -1229,14 +1229,14 @@  discard block
 block discarded – undo
1229 1229
                     foreach ($localTokenList as $k => $v) {
1230 1230
                         $tmpToken = new ExpressionToken($k, $v);
1231 1231
                         switch ($tmpToken->getUpper()) {
1232
-                        case 'WITH':
1233
-                            $match_mode = 'WITH QUERY EXPANSION';
1234
-                            break;
1235
-                        case 'IN':
1236
-                            $match_mode = 'IN BOOLEAN MODE';
1237
-                            break;
1238
-
1239
-                        default:
1232
+                            case 'WITH':
1233
+                                $match_mode = 'WITH QUERY EXPANSION';
1234
+                                break;
1235
+                            case 'IN':
1236
+                                $match_mode = 'IN BOOLEAN MODE';
1237
+                                break;
1238
+
1239
+                            default:
1240 1240
                         }
1241 1241
 
1242 1242
                         if ($match_mode !== false) {
@@ -1291,117 +1291,117 @@  discard block
 block discarded – undo
1291 1291
                 /* it is either an operator, a colref or a constant */
1292 1292
                 switch ($curr->getUpper()) {
1293 1293
 
1294
-                case '*':
1295
-                    $curr->setSubTree(false); #no subtree
1296
-
1297
-                    # single or first element of expression list -> all-column-alias
1298
-                    if (empty($resultList)) {
1299
-                        $curr->setTokenType(ExpressionType::COLREF);
1300
-                        break;
1301
-                    }
1302
-
1303
-                    # if the last token is colref, const or expression
1304
-                    # then * is an operator
1305
-                    # but if the previous colref ends with a dot, the * is the all-columns-alias
1306
-                    if (!$prev->isColumnReference() && !$prev->isConstant() && !$prev->isExpression()
1307
-                            && !$prev->isBracketExpression()) {
1308
-                        $curr->setTokenType(ExpressionType::COLREF);
1309
-                        break;
1310
-                    }
1311
-
1312
-                    if ($prev->isColumnReference() && $prev->endsWith('.')) {
1313
-                        $prev->addToken('*'); # tablealias dot *
1314
-                        continue 2; # skip the current token
1315
-                    }
1316
-
1317
-                    $curr->setTokenType(ExpressionType::OPERATOR);
1318
-                    break;
1294
+                    case '*':
1295
+                        $curr->setSubTree(false); #no subtree
1319 1296
 
1320
-                case 'AND':
1321
-                case '&&':
1322
-                case 'BETWEEN':
1323
-                case 'AND':
1324
-                case 'BINARY':
1325
-                case '&':
1326
-                case '~':
1327
-                case '|':
1328
-                case '^':
1329
-                case 'DIV':
1330
-                case '/':
1331
-                case '<=>':
1332
-                case '=':
1333
-                case '>=':
1334
-                case '>':
1335
-                case 'IS':
1336
-                case 'NOT':
1337
-                case '<<':
1338
-                case '<=':
1339
-                case '<':
1340
-                case 'LIKE':
1341
-                case '%':
1342
-                case '!=':
1343
-                case '<>':
1344
-                case 'REGEXP':
1345
-                case '!':
1346
-                case '||':
1347
-                case 'OR':
1348
-                case '>>':
1349
-                case 'RLIKE':
1350
-                case 'SOUNDS':
1351
-                case 'XOR':
1352
-                case 'IN':
1353
-                    $curr->setSubTree(false);
1354
-                    $curr->setTokenType(ExpressionType::OPERATOR);
1355
-                    break;
1297
+                        # single or first element of expression list -> all-column-alias
1298
+                        if (empty($resultList)) {
1299
+                            $curr->setTokenType(ExpressionType::COLREF);
1300
+                            break;
1301
+                        }
1356 1302
 
1357
-                case 'NULL':
1358
-                    $curr->setSubTree(false);
1359
-                    $curr->setTokenType(ExpressionType::CONSTANT);
1360
-                    break;
1303
+                        # if the last token is colref, const or expression
1304
+                        # then * is an operator
1305
+                        # but if the previous colref ends with a dot, the * is the all-columns-alias
1306
+                        if (!$prev->isColumnReference() && !$prev->isConstant() && !$prev->isExpression()
1307
+                                && !$prev->isBracketExpression()) {
1308
+                            $curr->setTokenType(ExpressionType::COLREF);
1309
+                            break;
1310
+                        }
1361 1311
 
1362
-                case '-':
1363
-                case '+':
1364
-                // differ between preceding sign and operator
1365
-                    $curr->setSubTree(false);
1312
+                        if ($prev->isColumnReference() && $prev->endsWith('.')) {
1313
+                            $prev->addToken('*'); # tablealias dot *
1314
+                            continue 2; # skip the current token
1315
+                        }
1366 1316
 
1367
-                    if ($prev->isColumnReference() || $prev->isFunction() || $prev->isAggregateFunction()
1368
-                            || $prev->isConstant() || $prev->isSubQuery() || $prev->isExpression()
1369
-                            || $prev->isBracketExpression()) {
1370 1317
                         $curr->setTokenType(ExpressionType::OPERATOR);
1371
-                    } else {
1372
-                        $curr->setTokenType(ExpressionType::SIGN);
1373
-                    }
1374
-                    break;
1318
+                        break;
1375 1319
 
1376
-                default:
1377
-                    $curr->setSubTree(false);
1320
+                    case 'AND':
1321
+                    case '&&':
1322
+                    case 'BETWEEN':
1323
+                    case 'AND':
1324
+                    case 'BINARY':
1325
+                    case '&':
1326
+                    case '~':
1327
+                    case '|':
1328
+                    case '^':
1329
+                    case 'DIV':
1330
+                    case '/':
1331
+                    case '<=>':
1332
+                    case '=':
1333
+                    case '>=':
1334
+                    case '>':
1335
+                    case 'IS':
1336
+                    case 'NOT':
1337
+                    case '<<':
1338
+                    case '<=':
1339
+                    case '<':
1340
+                    case 'LIKE':
1341
+                    case '%':
1342
+                    case '!=':
1343
+                    case '<>':
1344
+                    case 'REGEXP':
1345
+                    case '!':
1346
+                    case '||':
1347
+                    case 'OR':
1348
+                    case '>>':
1349
+                    case 'RLIKE':
1350
+                    case 'SOUNDS':
1351
+                    case 'XOR':
1352
+                    case 'IN':
1353
+                        $curr->setSubTree(false);
1354
+                        $curr->setTokenType(ExpressionType::OPERATOR);
1355
+                        break;
1378 1356
 
1379
-                    switch ($curr->getToken(0)) {
1380
-                    case "'":
1381
-                    case '"':
1382
-                    # it is a string literal
1357
+                    case 'NULL':
1358
+                        $curr->setSubTree(false);
1383 1359
                         $curr->setTokenType(ExpressionType::CONSTANT);
1384 1360
                         break;
1385
-                    case '`':
1386
-                    # it is an escaped colum name
1387
-                        $curr->setTokenType(ExpressionType::COLREF);
1361
+
1362
+                    case '-':
1363
+                    case '+':
1364
+                    // differ between preceding sign and operator
1365
+                        $curr->setSubTree(false);
1366
+
1367
+                        if ($prev->isColumnReference() || $prev->isFunction() || $prev->isAggregateFunction()
1368
+                                || $prev->isConstant() || $prev->isSubQuery() || $prev->isExpression()
1369
+                                || $prev->isBracketExpression()) {
1370
+                            $curr->setTokenType(ExpressionType::OPERATOR);
1371
+                        } else {
1372
+                            $curr->setTokenType(ExpressionType::SIGN);
1373
+                        }
1388 1374
                         break;
1389 1375
 
1390 1376
                     default:
1391
-                        if (is_numeric($curr->getToken())) {
1392
-                            if ($prev->isSign()) {
1393
-                                $prev->addToken($curr->getToken()); # it is a negative numeric constant
1394
-                                $prev->setTokenType(ExpressionType::CONSTANT);
1395
-                                continue 3;
1396
-                                # skip current token
1397
-                            } else {
1377
+                        $curr->setSubTree(false);
1378
+
1379
+                        switch ($curr->getToken(0)) {
1380
+                            case "'":
1381
+                            case '"':
1382
+                            # it is a string literal
1398 1383
                                 $curr->setTokenType(ExpressionType::CONSTANT);
1399
-                            }
1400
-                        } else {
1401
-                            $curr->setTokenType(ExpressionType::COLREF);
1384
+                                break;
1385
+                            case '`':
1386
+                            # it is an escaped colum name
1387
+                                $curr->setTokenType(ExpressionType::COLREF);
1388
+                                break;
1389
+
1390
+                            default:
1391
+                                if (is_numeric($curr->getToken())) {
1392
+                                    if ($prev->isSign()) {
1393
+                                        $prev->addToken($curr->getToken()); # it is a negative numeric constant
1394
+                                        $prev->setTokenType(ExpressionType::CONSTANT);
1395
+                                        continue 3;
1396
+                                        # skip current token
1397
+                                    } else {
1398
+                                        $curr->setTokenType(ExpressionType::CONSTANT);
1399
+                                    }
1400
+                                } else {
1401
+                                    $curr->setTokenType(ExpressionType::COLREF);
1402
+                                }
1403
+                                break;
1402 1404
                         }
1403
-                        break;
1404
-                    }
1405 1405
                 }
1406 1406
             }
1407 1407
 
@@ -1607,35 +1607,35 @@  discard block
 block discarded – undo
1607 1607
             }
1608 1608
 
1609 1609
             switch ($token->getUpper()) {
1610
-            case 'VIEW':
1611
-            case 'SCHEMA':
1612
-            case 'DATABASE':
1613
-            case 'TABLE':
1614
-                $expr_type = strtolower($token->getTrim());
1615
-                break;
1610
+                case 'VIEW':
1611
+                case 'SCHEMA':
1612
+                case 'DATABASE':
1613
+                case 'TABLE':
1614
+                    $expr_type = strtolower($token->getTrim());
1615
+                    break;
1616 1616
 
1617
-            case 'IF':
1618
-                $warning = false;
1619
-                $skip = true;
1620
-                break;
1617
+                case 'IF':
1618
+                    $warning = false;
1619
+                    $skip = true;
1620
+                    break;
1621 1621
 
1622
-            case 'TEMPORARY':
1623
-                $expr_type = ExpressionType::TEMPORARY_TABLE;
1624
-                $skip = true;
1625
-                break;
1622
+                case 'TEMPORARY':
1623
+                    $expr_type = ExpressionType::TEMPORARY_TABLE;
1624
+                    $skip = true;
1625
+                    break;
1626 1626
 
1627
-            case 'RESTRICT':
1628
-            case 'CASCADE':
1629
-                $option = $token->getUpper();
1630
-                break;
1627
+                case 'RESTRICT':
1628
+                case 'CASCADE':
1629
+                    $option = $token->getUpper();
1630
+                    break;
1631 1631
 
1632
-            case ',':
1633
-                $resultList[] = array('expr_type' => $expr_type, 'base_expr' => $base_expr);
1634
-                $base_expr = '';
1635
-                break;
1632
+                case ',':
1633
+                    $resultList[] = array('expr_type' => $expr_type, 'base_expr' => $base_expr);
1634
+                    $base_expr = '';
1635
+                    break;
1636 1636
 
1637
-            default:
1638
-                $base_expr .= $token->getToken();
1637
+                default:
1638
+                    $base_expr .= $token->getToken();
1639 1639
             }
1640 1640
         }
1641 1641
 
Please login to merge, or discard this patch.
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -571,7 +571,7 @@  discard block
 block discarded – undo
571 571
         $assignment = $this->process_expr_list($this->splitSQLIntoTokens($base_expr));
572 572
 
573 573
         return array('expr_type' => ExpressionType::EXPRESSION, 'base_expr' => trim($base_expr),
574
-                     'sub_tree' => $assignment, );
574
+                     'sub_tree' => $assignment,);
575 575
     }
576 576
 
577 577
     private function getVariableType($expression)
@@ -692,8 +692,8 @@  discard block
 block discarded – undo
692 692
         }
693 693
 
694 694
         return [
695
-            ['expr_type' => 'limit_const', 'base_expr' => trim($offset), 'sub_tree' => false ],
696
-            ['expr_type' => 'limit_const', 'base_expr' => trim($rowcount), 'sub_tree' => false ]
695
+            ['expr_type' => 'limit_const', 'base_expr' => trim($offset), 'sub_tree' => false],
696
+            ['expr_type' => 'limit_const', 'base_expr' => trim($rowcount), 'sub_tree' => false]
697 697
         ];
698 698
     }
699 699
 
@@ -846,7 +846,7 @@  discard block
 block discarded – undo
846 846
                     || $this->isFunction($prev) || $this->isExpression($prev) || $this->isSubQuery($prev)
847 847
                     || $this->isColumnReference($prev) || $this->isBracketExpression($prev)) {
848 848
                 $alias = array('as' => false, 'name' => trim($last['base_expr']),
849
-                               'base_expr' => trim($last['base_expr']), );
849
+                               'base_expr' => trim($last['base_expr']),);
850 850
                 #remove the last token
851 851
                 array_pop($tokens);
852 852
                 $base_expr = implode('', $tokens);
@@ -876,7 +876,7 @@  discard block
 block discarded – undo
876 876
         }
877 877
 
878 878
         return array('expr_type' => $type, 'alias' => $alias, 'base_expr' => trim($base_expr),
879
-                     'sub_tree' => $processed, );
879
+                     'sub_tree' => $processed,);
880 880
     }
881 881
 
882 882
     /**
@@ -1018,7 +1018,7 @@  discard block
 block discarded – undo
1018 1018
         return array('expression' => '', 'token_count' => 0, 'table' => '', 'alias' => false, 'join_type' => '',
1019 1019
                      'next_join_type' => '', 'saved_join_type' => $parseInfo['saved_join_type'],
1020 1020
                      'ref_type' => false, 'ref_expr' => false, 'base_expr' => false, 'sub_tree' => false,
1021
-                     'subquery' => '', );
1021
+                     'subquery' => '',);
1022 1022
     }
1023 1023
 
1024 1024
     private function processFromExpression(&$parseInfo)
@@ -1102,7 +1102,7 @@  discard block
 block discarded – undo
1102 1102
         }
1103 1103
 
1104 1104
         return array('expr_type' => $parseInfo['type'], 'base_expr' => $parseInfo['expr'],
1105
-                     'direction' => $parseInfo['dir'], );
1105
+                     'direction' => $parseInfo['dir'],);
1106 1106
     }
1107 1107
 
1108 1108
     private function initParseInfoForOrder()
@@ -1562,7 +1562,7 @@  discard block
 block discarded – undo
1562 1562
                 unset($values[$k]);
1563 1563
             } else {
1564 1564
                 $values[$k] = array('expr_type' => ExpressionType::RECORD, 'base_expr' => $v,
1565
-                                    'data' => $this->process_record($v), );
1565
+                                    'data' => $this->process_record($v),);
1566 1566
             }
1567 1567
         }
1568 1568
 
Please login to merge, or discard this patch.