Passed
Push — 5.1 ( 5ffcfb...270c87 )
by liu
07:41
created
library/think/db/Builder.php 1 patch
Spacing   +63 added lines, -63 removed lines patch added patch discarded remove patch
@@ -132,23 +132,23 @@  discard block
 block discarded – undo
132 132
             if (false !== strpos($key, '->')) {
133 133
                 list($key, $name) = explode('->', $key);
134 134
                 $item             = $this->parseKey($query, $key);
135
-                $result[$item]    = 'json_set(' . $item . ', \'$.' . $name . '\', ' . $this->parseDataBind($query, $key, $val, $bind) . ')';
135
+                $result[$item]    = 'json_set('.$item.', \'$.'.$name.'\', '.$this->parseDataBind($query, $key, $val, $bind).')';
136 136
             } elseif ('*' == $options['field'] && false === strpos($key, '.') && !in_array($key, $fields, true)) {
137 137
                 if ($options['strict']) {
138
-                    throw new Exception('fields not exists:[' . $key . ']');
138
+                    throw new Exception('fields not exists:['.$key.']');
139 139
                 }
140 140
             } elseif (is_null($val)) {
141 141
                 $result[$item] = 'NULL';
142 142
             } elseif (is_array($val) && !empty($val)) {
143 143
                 switch (strtoupper($val[0])) {
144 144
                     case 'INC':
145
-                        $result[$item] = $item . ' + ' . floatval($val[1]);
145
+                        $result[$item] = $item.' + '.floatval($val[1]);
146 146
                         break;
147 147
                     case 'DEC':
148
-                        $result[$item] = $item . ' - ' . floatval($val[1]);
148
+                        $result[$item] = $item.' - '.floatval($val[1]);
149 149
                         break;
150 150
                     case 'EXP':
151
-                        throw new Exception('not support data:[' . $val[0] . ']');
151
+                        throw new Exception('not support data:['.$val[0].']');
152 152
                 }
153 153
             } elseif (is_scalar($val)) {
154 154
                 // 过滤非标量数据
@@ -176,7 +176,7 @@  discard block
 block discarded – undo
176 176
 
177 177
         $name = $query->bind($data, isset($bind[$key]) ? $bind[$key] : PDO::PARAM_STR);
178 178
 
179
-        return ':' . $name;
179
+        return ':'.$name;
180 180
     }
181 181
 
182 182
     /**
@@ -209,7 +209,7 @@  discard block
 block discarded – undo
209 209
 
210 210
             foreach ($fields as $key => $field) {
211 211
                 if (!is_numeric($key)) {
212
-                    $array[] = $this->parseKey($query, $key) . ' AS ' . $this->parseKey($query, $field, true);
212
+                    $array[] = $this->parseKey($query, $key).' AS '.$this->parseKey($query, $field, true);
213 213
                 } else {
214 214
                     $array[] = $this->parseKey($query, $field);
215 215
                 }
@@ -236,12 +236,12 @@  discard block
 block discarded – undo
236 236
         foreach ((array) $tables as $key => $table) {
237 237
             if (!is_numeric($key)) {
238 238
                 $key    = $this->connection->parseSqlTable($key);
239
-                $item[] = $this->parseKey($query, $key) . ' ' . $this->parseKey($query, $table);
239
+                $item[] = $this->parseKey($query, $key).' '.$this->parseKey($query, $table);
240 240
             } else {
241 241
                 $table = $this->connection->parseSqlTable($table);
242 242
 
243 243
                 if (isset($options['alias'][$table])) {
244
-                    $item[] = $this->parseKey($query, $table) . ' ' . $this->parseKey($query, $options['alias'][$table]);
244
+                    $item[] = $this->parseKey($query, $table).' '.$this->parseKey($query, $options['alias'][$table]);
245 245
                 } else {
246 246
                     $item[] = $this->parseKey($query, $table);
247 247
                 }
@@ -268,11 +268,11 @@  discard block
 block discarded – undo
268 268
             list($field, $condition) = $options['soft_delete'];
269 269
 
270 270
             $binds    = $this->connection->getFieldsBind($options['table']);
271
-            $whereStr = $whereStr ? '( ' . $whereStr . ' ) AND ' : '';
272
-            $whereStr = $whereStr . $this->parseWhereItem($query, $field, $condition, '', $binds);
271
+            $whereStr = $whereStr ? '( '.$whereStr.' ) AND ' : '';
272
+            $whereStr = $whereStr.$this->parseWhereItem($query, $field, $condition, '', $binds);
273 273
         }
274 274
 
275
-        return empty($whereStr) ? '' : ' WHERE ' . $whereStr;
275
+        return empty($whereStr) ? '' : ' WHERE '.$whereStr;
276 276
     }
277 277
 
278 278
     /**
@@ -296,17 +296,17 @@  discard block
 block discarded – undo
296 296
 
297 297
             foreach ($val as $value) {
298 298
                 if ($value instanceof Expression) {
299
-                    $str[] = ' ' . $logic . ' ( ' . $value->getValue() . ' )';
299
+                    $str[] = ' '.$logic.' ( '.$value->getValue().' )';
300 300
                     continue;
301 301
                 }
302 302
 
303 303
                 if (is_array($value)) {
304 304
                     if (key($value) !== 0) {
305
-                        throw new Exception('where express error:' . var_export($value, true));
305
+                        throw new Exception('where express error:'.var_export($value, true));
306 306
                     }
307 307
                     $field = array_shift($value);
308 308
                 } elseif (!($value instanceof \Closure)) {
309
-                    throw new Exception('where express error:' . var_export($value, true));
309
+                    throw new Exception('where express error:'.var_export($value, true));
310 310
                 }
311 311
 
312 312
                 if ($value instanceof \Closure) {
@@ -317,7 +317,7 @@  discard block
 block discarded – undo
317 317
 
318 318
                     if (!empty($whereClause)) {
319 319
                         $query->bind($newQuery->getBind(false));
320
-                        $str[] = ' ' . $logic . ' ( ' . $whereClause . ' )';
320
+                        $str[] = ' '.$logic.' ( '.$whereClause.' )';
321 321
                     }
322 322
                 } elseif (is_array($field)) {
323 323
                     array_unshift($value, $field);
@@ -326,7 +326,7 @@  discard block
 block discarded – undo
326 326
                         $str2[] = $this->parseWhereItem($query, array_shift($item), $item, $logic, $binds);
327 327
                     }
328 328
 
329
-                    $str[] = ' ' . $logic . ' ( ' . implode(' AND ', $str2) . ' )';
329
+                    $str[] = ' '.$logic.' ( '.implode(' AND ', $str2).' )';
330 330
                 } elseif (strpos($field, '|')) {
331 331
                     // 不同字段使用相同查询条件(OR)
332 332
                     $array = explode('|', $field);
@@ -336,7 +336,7 @@  discard block
 block discarded – undo
336 336
                         $item[] = $this->parseWhereItem($query, $k, $value, '', $binds);
337 337
                     }
338 338
 
339
-                    $str[] = ' ' . $logic . ' ( ' . implode(' OR ', $item) . ' )';
339
+                    $str[] = ' '.$logic.' ( '.implode(' OR ', $item).' )';
340 340
                 } elseif (strpos($field, '&')) {
341 341
                     // 不同字段使用相同查询条件(AND)
342 342
                     $array = explode('&', $field);
@@ -346,11 +346,11 @@  discard block
 block discarded – undo
346 346
                         $item[] = $this->parseWhereItem($query, $k, $value, '', $binds);
347 347
                     }
348 348
 
349
-                    $str[] = ' ' . $logic . ' ( ' . implode(' AND ', $item) . ' )';
349
+                    $str[] = ' '.$logic.' ( '.implode(' AND ', $item).' )';
350 350
                 } else {
351 351
                     // 对字段使用表达式查询
352 352
                     $field = is_string($field) ? $field : '';
353
-                    $str[] = ' ' . $logic . ' ' . $this->parseWhereItem($query, $field, $value, $logic, $binds);
353
+                    $str[] = ' '.$logic.' '.$this->parseWhereItem($query, $field, $value, $logic, $binds);
354 354
                 }
355 355
             }
356 356
 
@@ -388,7 +388,7 @@  discard block
 block discarded – undo
388 388
                 $str[] = $this->parseWhereItem($query, $field, $item, $rule, $binds);
389 389
             }
390 390
 
391
-            return '( ' . implode(' ' . $rule . ' ', $str) . ' )';
391
+            return '( '.implode(' '.$rule.' ', $str).' )';
392 392
         }
393 393
 
394 394
         // 检测操作符
@@ -415,7 +415,7 @@  discard block
 block discarded – undo
415 415
             if (0 === strpos($value, ':') && $query->isBind(substr($value, 1))) {
416 416
             } else {
417 417
                 $name  = $query->bind($value, $bindType);
418
-                $value = ':' . $name;
418
+                $value = ':'.$name;
419 419
             }
420 420
         }
421 421
 
@@ -428,7 +428,7 @@  discard block
 block discarded – undo
428 428
         }
429 429
 
430 430
         if (!isset($whereStr)) {
431
-            throw new Exception('where express error:' . $exp);
431
+            throw new Exception('where express error:'.$exp);
432 432
         }
433 433
 
434 434
         return $whereStr;
@@ -452,12 +452,12 @@  discard block
 block discarded – undo
452 452
         if (is_array($value)) {
453 453
             foreach ($value as $item) {
454 454
                 $name    = $query->bind($item, PDO::PARAM_STR);
455
-                $array[] = $key . ' ' . $exp . ' :' . $name;
455
+                $array[] = $key.' '.$exp.' :'.$name;
456 456
             }
457 457
 
458
-            $whereStr = '(' . implode(' ' . strtoupper($logic) . ' ', $array) . ')';
458
+            $whereStr = '('.implode(' '.strtoupper($logic).' ', $array).')';
459 459
         } else {
460
-            $whereStr = $key . ' ' . $exp . ' ' . $value;
460
+            $whereStr = $key.' '.$exp.' '.$value;
461 461
         }
462 462
 
463 463
         return $whereStr;
@@ -480,10 +480,10 @@  discard block
 block discarded – undo
480 480
         list($op, $field2) = $value;
481 481
 
482 482
         if (!in_array($op, ['=', '<>', '>', '>=', '<', '<='])) {
483
-            throw new Exception('where express error:' . var_export($value, true));
483
+            throw new Exception('where express error:'.var_export($value, true));
484 484
         }
485 485
 
486
-        return '( ' . $key . ' ' . $op . ' ' . $this->parseKey($query, $field2, true) . ' )';
486
+        return '( '.$key.' '.$op.' '.$this->parseKey($query, $field2, true).' )';
487 487
     }
488 488
 
489 489
     /**
@@ -500,7 +500,7 @@  discard block
 block discarded – undo
500 500
     protected function parseExp(Query $query, $key, $exp, Expression $value, $field, $bindType)
501 501
     {
502 502
         // 表达式查询
503
-        return '( ' . $key . ' ' . $value->getValue() . ' )';
503
+        return '( '.$key.' '.$value->getValue().' )';
504 504
     }
505 505
 
506 506
     /**
@@ -517,7 +517,7 @@  discard block
 block discarded – undo
517 517
     protected function parseNull(Query $query, $key, $exp, $value, $field, $bindType)
518 518
     {
519 519
         // NULL 查询
520
-        return $key . ' IS ' . $exp;
520
+        return $key.' IS '.$exp;
521 521
     }
522 522
 
523 523
     /**
@@ -539,7 +539,7 @@  discard block
 block discarded – undo
539 539
         $min = $query->bind($data[0], $bindType);
540 540
         $max = $query->bind($data[1], $bindType);
541 541
 
542
-        return $key . ' ' . $exp . ' :' . $min . ' AND :' . $max . ' ';
542
+        return $key.' '.$exp.' :'.$min.' AND :'.$max.' ';
543 543
     }
544 544
 
545 545
     /**
@@ -561,10 +561,10 @@  discard block
 block discarded – undo
561 561
         } elseif ($value instanceof Expression) {
562 562
             $value = $value->getValue();
563 563
         } else {
564
-            throw new Exception('where express error:' . $value);
564
+            throw new Exception('where express error:'.$value);
565 565
         }
566 566
 
567
-        return $exp . ' (' . $value . ')';
567
+        return $exp.' ('.$value.')';
568 568
     }
569 569
 
570 570
     /**
@@ -580,7 +580,7 @@  discard block
 block discarded – undo
580 580
      */
581 581
     protected function parseTime(Query $query, $key, $exp, $value, $field, $bindType)
582 582
     {
583
-        return $key . ' ' . substr($exp, 0, 2) . ' ' . $this->parseDateTime($query, $value, $field, $bindType);
583
+        return $key.' '.substr($exp, 0, 2).' '.$this->parseDateTime($query, $value, $field, $bindType);
584 584
     }
585 585
 
586 586
     /**
@@ -597,7 +597,7 @@  discard block
 block discarded – undo
597 597
     protected function parseCompare(Query $query, $key, $exp, $value, $field, $bindType)
598 598
     {
599 599
         if (is_array($value)) {
600
-            throw new Exception('where express error:' . $exp . var_export($value, true));
600
+            throw new Exception('where express error:'.$exp.var_export($value, true));
601 601
         }
602 602
 
603 603
         // 比较运算
@@ -606,10 +606,10 @@  discard block
 block discarded – undo
606 606
         }
607 607
 
608 608
         if ('=' == $exp && is_null($value)) {
609
-            return $key . ' IS NULL';
609
+            return $key.' IS NULL';
610 610
         }
611 611
 
612
-        return $key . ' ' . $exp . ' ' . $value;
612
+        return $key.' '.$exp.' '.$value;
613 613
     }
614 614
 
615 615
     /**
@@ -629,7 +629,7 @@  discard block
 block discarded – undo
629 629
             $value = explode(',', $value);
630 630
         }
631 631
 
632
-        return $key . ' ' . substr($exp, 0, -4)
632
+        return $key.' '.substr($exp, 0, -4)
633 633
         . $this->parseDateTime($query, $value[0], $field, $bindType)
634 634
         . ' AND '
635 635
         . $this->parseDateTime($query, $value[1], $field, $bindType);
@@ -660,18 +660,18 @@  discard block
 block discarded – undo
660 660
 
661 661
             foreach ($value as $k => $v) {
662 662
                 $name    = $query->bind($v, $bindType);
663
-                $array[] = ':' . $name;
663
+                $array[] = ':'.$name;
664 664
             }
665 665
 
666 666
             if (count($array) == 1) {
667
-                return $key . ('IN' == $exp ? ' = ' : ' <> ') . $array[0];
667
+                return $key.('IN' == $exp ? ' = ' : ' <> ').$array[0];
668 668
             } else {
669 669
                 $zone  = implode(',', $array);
670 670
                 $value = empty($zone) ? "''" : $zone;
671 671
             }
672 672
         }
673 673
 
674
-        return $key . ' ' . $exp . ' (' . $value . ')';
674
+        return $key.' '.$exp.' ('.$value.')';
675 675
     }
676 676
 
677 677
     /**
@@ -736,7 +736,7 @@  discard block
 block discarded – undo
736 736
 
737 737
         $name = $query->bind($value, $bindType);
738 738
 
739
-        return ':' . $name;
739
+        return ':'.$name;
740 740
     }
741 741
 
742 742
     /**
@@ -748,7 +748,7 @@  discard block
 block discarded – undo
748 748
      */
749 749
     protected function parseLimit(Query $query, $limit)
750 750
     {
751
-        return (!empty($limit) && false === strpos($limit, '(')) ? ' LIMIT ' . $limit . ' ' : '';
751
+        return (!empty($limit) && false === strpos($limit, '(')) ? ' LIMIT '.$limit.' ' : '';
752 752
     }
753 753
 
754 754
     /**
@@ -774,7 +774,7 @@  discard block
 block discarded – undo
774 774
                     } elseif (strpos($val, '=')) {
775 775
                         list($val1, $val2) = explode('=', $val, 2);
776 776
 
777
-                        $condition[] = $this->parseKey($query, $val1) . '=' . $this->parseKey($query, $val2);
777
+                        $condition[] = $this->parseKey($query, $val1).'='.$this->parseKey($query, $val2);
778 778
                     } else {
779 779
                         $condition[] = $val;
780 780
                     }
@@ -782,7 +782,7 @@  discard block
 block discarded – undo
782 782
 
783 783
                 $table = $this->parseTable($query, $table);
784 784
 
785
-                $joinStr .= ' ' . $type . ' JOIN ' . $table . ' ON ' . implode(' AND ', $condition);
785
+                $joinStr .= ' '.$type.' JOIN '.$table.' ON '.implode(' AND ', $condition);
786 786
             }
787 787
         }
788 788
 
@@ -807,22 +807,22 @@  discard block
 block discarded – undo
807 807
                 $array[] = $this->parseRand($query);
808 808
             } elseif (is_string($val)) {
809 809
                 if (is_numeric($key)) {
810
-                    list($key, $sort) = explode(' ', strpos($val, ' ') ? $val : $val . ' ');
810
+                    list($key, $sort) = explode(' ', strpos($val, ' ') ? $val : $val.' ');
811 811
                 } else {
812 812
                     $sort = $val;
813 813
                 }
814 814
 
815 815
                 if (preg_match('/^[\w\.]+$/', $key)) {
816 816
                     $sort    = strtoupper($sort);
817
-                    $sort    = in_array($sort, ['ASC', 'DESC'], true) ? ' ' . $sort : '';
818
-                    $array[] = $this->parseKey($query, $key, true) . $sort;
817
+                    $sort    = in_array($sort, ['ASC', 'DESC'], true) ? ' '.$sort : '';
818
+                    $array[] = $this->parseKey($query, $key, true).$sort;
819 819
                 } else {
820
-                    throw new Exception('order express error:' . $key);
820
+                    throw new Exception('order express error:'.$key);
821 821
                 }
822 822
             }
823 823
         }
824 824
 
825
-        return empty($array) ? '' : ' ORDER BY ' . implode(',', $array);
825
+        return empty($array) ? '' : ' ORDER BY '.implode(',', $array);
826 826
     }
827 827
 
828 828
     /**
@@ -843,7 +843,7 @@  discard block
 block discarded – undo
843 843
         }
844 844
 
845 845
         $sort = strtoupper($sort);
846
-        $sort = in_array($sort, ['ASC', 'DESC'], true) ? ' ' . $sort : '';
846
+        $sort = in_array($sort, ['ASC', 'DESC'], true) ? ' '.$sort : '';
847 847
 
848 848
         $options = $query->getOptions();
849 849
         $bind    = $this->connection->getFieldsBind($options['table']);
@@ -852,7 +852,7 @@  discard block
 block discarded – undo
852 852
             $val[$k] = $this->parseDataBind($query, $key, $item, $bind);
853 853
         }
854 854
 
855
-        return 'field(' . $this->parseKey($query, $key, true) . ',' . implode(',', $val) . ')' . $sort;
855
+        return 'field('.$this->parseKey($query, $key, true).','.implode(',', $val).')'.$sort;
856 856
     }
857 857
 
858 858
     /**
@@ -876,7 +876,7 @@  discard block
 block discarded – undo
876 876
             $val[] = $this->parseKey($query, $key);
877 877
         }
878 878
 
879
-        return ' GROUP BY ' . implode(',', $val);
879
+        return ' GROUP BY '.implode(',', $val);
880 880
     }
881 881
 
882 882
     /**
@@ -888,7 +888,7 @@  discard block
 block discarded – undo
888 888
      */
889 889
     protected function parseHaving(Query $query, $having)
890 890
     {
891
-        return !empty($having) ? ' HAVING ' . $having : '';
891
+        return !empty($having) ? ' HAVING '.$having : '';
892 892
     }
893 893
 
894 894
     /**
@@ -904,7 +904,7 @@  discard block
 block discarded – undo
904 904
             $comment = strstr($comment, '*/', true);
905 905
         }
906 906
 
907
-        return !empty($comment) ? ' /* ' . $comment . ' */' : '';
907
+        return !empty($comment) ? ' /* '.$comment.' */' : '';
908 908
     }
909 909
 
910 910
     /**
@@ -937,13 +937,13 @@  discard block
 block discarded – undo
937 937
 
938 938
         foreach ($union as $u) {
939 939
             if ($u instanceof \Closure) {
940
-                $sql[] = $type . ' ' . $this->parseClosure($query, $u);
940
+                $sql[] = $type.' '.$this->parseClosure($query, $u);
941 941
             } elseif (is_string($u)) {
942
-                $sql[] = $type . ' ( ' . $this->connection->parseSqlTable($u) . ' )';
942
+                $sql[] = $type.' ( '.$this->connection->parseSqlTable($u).' )';
943 943
             }
944 944
         }
945 945
 
946
-        return ' ' . implode(' ', $sql);
946
+        return ' '.implode(' ', $sql);
947 947
     }
948 948
 
949 949
     /**
@@ -974,7 +974,7 @@  discard block
 block discarded – undo
974 974
         if (is_bool($lock)) {
975 975
             return $lock ? ' FOR UPDATE ' : '';
976 976
         } elseif (is_string($lock) && !empty($lock)) {
977
-            return ' ' . trim($lock) . ' ';
977
+            return ' '.trim($lock).' ';
978 978
         }
979 979
     }
980 980
 
@@ -1065,7 +1065,7 @@  discard block
 block discarded – undo
1065 1065
         foreach ($dataSet as $data) {
1066 1066
             $data = $this->parseData($query, $data, $allowFields, $bind);
1067 1067
 
1068
-            $values[] = 'SELECT ' . implode(',', array_values($data));
1068
+            $values[] = 'SELECT '.implode(',', array_values($data));
1069 1069
 
1070 1070
             if (!isset($insertFields)) {
1071 1071
                 $insertFields = array_keys($data);
@@ -1108,7 +1108,7 @@  discard block
 block discarded – undo
1108 1108
             $field = $this->parseKey($query, $field, true);
1109 1109
         }
1110 1110
 
1111
-        return 'INSERT INTO ' . $this->parseTable($query, $table) . ' (' . implode(',', $fields) . ') ' . $this->select($query);
1111
+        return 'INSERT INTO '.$this->parseTable($query, $table).' ('.implode(',', $fields).') '.$this->select($query);
1112 1112
     }
1113 1113
 
1114 1114
     /**
@@ -1128,7 +1128,7 @@  discard block
 block discarded – undo
1128 1128
         }
1129 1129
 
1130 1130
         foreach ($data as $key => $val) {
1131
-            $set[] = $key . ' = ' . $val;
1131
+            $set[] = $key.' = '.$val;
1132 1132
         }
1133 1133
 
1134 1134
         return str_replace(
@@ -1160,7 +1160,7 @@  discard block
 block discarded – undo
1160 1160
             ['%TABLE%', '%USING%', '%JOIN%', '%WHERE%', '%ORDER%', '%LIMIT%', '%LOCK%', '%COMMENT%'],
1161 1161
             [
1162 1162
                 $this->parseTable($query, $options['table']),
1163
-                !empty($options['using']) ? ' USING ' . $this->parseTable($query, $options['using']) . ' ' : '',
1163
+                !empty($options['using']) ? ' USING '.$this->parseTable($query, $options['using']).' ' : '',
1164 1164
                 $this->parseJoin($query, $options['join']),
1165 1165
                 $this->parseWhere($query, $options['where']),
1166 1166
                 $this->parseOrder($query, $options['order']),
Please login to merge, or discard this patch.