@@ -56,7 +56,8 @@ discard block |
||
56 | 56 | if (($pos = strrpos($name, '.')) !== false) { |
57 | 57 | $prefix = $this->quoteTableName(substr($name, 0, $pos)) . '.'; |
58 | 58 | $name = substr($name, $pos + 1); |
59 | - } else { |
|
59 | + } |
|
60 | + else { |
|
60 | 61 | $prefix = ''; |
61 | 62 | } |
62 | 63 | return $prefix . $this->quoteSimpleColumnName($name); |
@@ -134,13 +135,17 @@ discard block |
||
134 | 135 | { |
135 | 136 | if ($value instanceof IToSql) { |
136 | 137 | return $value->toSql(); |
137 | - } else if ($value === true || strtolower($value) === 'true') { |
|
138 | + } |
|
139 | + else if ($value === true || strtolower($value) === 'true') { |
|
138 | 140 | return 'TRUE'; |
139 | - } else if ($value === false || strtolower($value) === 'false') { |
|
141 | + } |
|
142 | + else if ($value === false || strtolower($value) === 'false') { |
|
140 | 143 | return 'FALSE'; |
141 | - } else if ($value === null || strtolower($value) === 'null') { |
|
144 | + } |
|
145 | + else if ($value === null || strtolower($value) === 'null') { |
|
142 | 146 | return 'NULL'; |
143 | - } else if (is_string($value) && $driver = $this->getDriver()) { |
|
147 | + } |
|
148 | + else if (is_string($value) && $driver = $this->getDriver()) { |
|
144 | 149 | return $driver->quote($value); |
145 | 150 | } |
146 | 151 | |
@@ -213,7 +218,8 @@ discard block |
||
213 | 218 | { |
214 | 219 | if ($rawValue === true || $rawValue === false || $rawValue === 'true' || $rawValue === 'false') { |
215 | 220 | return $this->getBoolean($rawValue); |
216 | - } else if ($rawValue === 'null' || $rawValue === null) { |
|
221 | + } |
|
222 | + else if ($rawValue === 'null' || $rawValue === null) { |
|
217 | 223 | return 'NULL'; |
218 | 224 | } |
219 | 225 | return $rawValue; |
@@ -267,7 +273,8 @@ discard block |
||
267 | 273 | foreach ($columns as $i => $column) { |
268 | 274 | if ($column instanceof Expression) { |
269 | 275 | $columns[$i] = $column->toSQL(); |
270 | - } else if (strpos($column, '(') === false) { |
|
276 | + } |
|
277 | + else if (strpos($column, '(') === false) { |
|
271 | 278 | $columns[$i] = $this->quoteColumn($column); |
272 | 279 | } |
273 | 280 | } |
@@ -417,12 +424,14 @@ discard block |
||
417 | 424 | foreach ($columns as $name => $type) { |
418 | 425 | if (is_string($name)) { |
419 | 426 | $cols[] = "\t" . $this->quoteColumn($name) . ' ' . $type; |
420 | - } else { |
|
427 | + } |
|
428 | + else { |
|
421 | 429 | $cols[] = "\t" . $type; |
422 | 430 | } |
423 | 431 | } |
424 | 432 | $sql = ($ifNotExists ? "CREATE TABLE IF NOT EXISTS " : "CREATE TABLE ") . $this->quoteTableName($tableName) . " (\n" . implode(",\n", $cols) . "\n)"; |
425 | - } else { |
|
433 | + } |
|
434 | + else { |
|
426 | 435 | $sql = ($ifNotExists ? "CREATE TABLE IF NOT EXISTS " : "CREATE TABLE ") . $this->quoteTableName($tableName) . " " . $this->quoteSql($columns); |
427 | 436 | } |
428 | 437 | return empty($options) ? $sql : $sql . ' ' . $options; |
@@ -472,11 +481,14 @@ discard block |
||
472 | 481 | { |
473 | 482 | if ($value === 'true' || $value === true) { |
474 | 483 | return 'TRUE'; |
475 | - } else if ($value === null || $value === 'null') { |
|
484 | + } |
|
485 | + else if ($value === null || $value === 'null') { |
|
476 | 486 | return 'NULL'; |
477 | - } else if ($value === false || $value === 'false') { |
|
487 | + } |
|
488 | + else if ($value === false || $value === 'false') { |
|
478 | 489 | return 'FALSE'; |
479 | - } else { |
|
490 | + } |
|
491 | + else { |
|
480 | 492 | return $value; |
481 | 493 | } |
482 | 494 | } |
@@ -604,12 +616,14 @@ discard block |
||
604 | 616 | foreach ($tables as $tableAlias => $table) { |
605 | 617 | if ($table instanceof QueryBuilder) { |
606 | 618 | $tableRaw = $table->toSQL(); |
607 | - } else { |
|
619 | + } |
|
620 | + else { |
|
608 | 621 | $tableRaw = $this->getRawTableName($table); |
609 | 622 | } |
610 | 623 | if (strpos($tableRaw, 'SELECT') !== false) { |
611 | 624 | $quotedTableNames[] = '(' . $tableRaw . ')' . (is_numeric($tableAlias) ? '' : ' AS ' . $this->quoteTableName($tableAlias)); |
612 | - } else { |
|
625 | + } |
|
626 | + else { |
|
613 | 627 | $quotedTableNames[] = $this->quoteTableName($tableRaw) . (is_numeric($tableAlias) ? '' : ' AS ' . $this->quoteTableName($tableAlias)); |
614 | 628 | } |
615 | 629 | } |
@@ -630,12 +644,15 @@ discard block |
||
630 | 644 | if (is_string($tableName) && $tableName = $this->getRawTableName($tableName)) { |
631 | 645 | if (strpos($tableName, 'SELECT') !== false) { |
632 | 646 | $toSql[] = '(' . $this->quoteSql($tableName) . ')' ; |
633 | - } else { |
|
647 | + } |
|
648 | + else { |
|
634 | 649 | $toSql[] = $this->quoteTableName($tableName); |
635 | 650 | } |
636 | - } else if ($tableName instanceof QueryBuilder) { |
|
651 | + } |
|
652 | + else if ($tableName instanceof QueryBuilder) { |
|
637 | 653 | $toSql[] = '(' . $this->quoteSql($tableName->toSQL()) . ')' ; |
638 | - } else { |
|
654 | + } |
|
655 | + else { |
|
639 | 656 | throw new QBException('Incorrect table name'); |
640 | 657 | } |
641 | 658 | |
@@ -647,11 +664,13 @@ discard block |
||
647 | 664 | $onSQL = []; |
648 | 665 | if (is_string($on)) { |
649 | 666 | $onSQL[] = $this->quoteSql($on); |
650 | - } else { |
|
667 | + } |
|
668 | + else { |
|
651 | 669 | foreach ($on as $leftColumn => $rightColumn) { |
652 | 670 | if ($rightColumn instanceof Expression) { |
653 | 671 | $onSQL[] = $this->quoteColumn($leftColumn) . '=' . $this->quoteSql($rightColumn->toSQL()); |
654 | - } else { |
|
672 | + } |
|
673 | + else { |
|
655 | 674 | $onSQL[] = $this->quoteColumn($leftColumn) . '=' . $this->quoteColumn($rightColumn); |
656 | 675 | } |
657 | 676 | } |
@@ -689,7 +708,8 @@ discard block |
||
689 | 708 | if ($having instanceof IToSql) { |
690 | 709 | $sql = $having |
691 | 710 | ->toSql(); |
692 | - } else { |
|
711 | + } |
|
712 | + else { |
|
693 | 713 | $sql = $this->quoteSql($having); |
694 | 714 | } |
695 | 715 | |
@@ -709,7 +729,8 @@ discard block |
||
709 | 729 | |
710 | 730 | if ($union instanceof QueryBuilderInterface) { |
711 | 731 | $unionSQL = $union->setOrder(null)->toSQL(); |
712 | - } else { |
|
732 | + } |
|
733 | + else { |
|
713 | 734 | $unionSQL = $this->quoteSql($union); |
714 | 735 | } |
715 | 736 |
@@ -182,7 +182,8 @@ discard block |
||
182 | 182 | $types = [static::TYPE_INSERT, static::TYPE_UPDATE, static::TYPE_DELETE, static::TYPE_SELECT]; |
183 | 183 | if (in_array($type, $types, true)) { |
184 | 184 | $this->_type = $type; |
185 | - } else { |
|
185 | + } |
|
186 | + else { |
|
186 | 187 | throw new QBException('Incorrect type'); |
187 | 188 | } |
188 | 189 | |
@@ -255,12 +256,15 @@ discard block |
||
255 | 256 | if ($newSelect === false) { |
256 | 257 | if ($tableAlias === null || $rawColumn === '*') { |
257 | 258 | $columns = $rawColumn; |
258 | - } elseif (strpos($rawColumn, '.') !== false) { |
|
259 | + } |
|
260 | + elseif (strpos($rawColumn, '.') !== false) { |
|
259 | 261 | $columns = $rawColumn; |
260 | - } else { |
|
262 | + } |
|
263 | + else { |
|
261 | 264 | $columns = $tableAlias . '.' . $rawColumn; |
262 | 265 | } |
263 | - } else { |
|
266 | + } |
|
267 | + else { |
|
264 | 268 | list($alias, $joinColumn) = $newSelect; |
265 | 269 | $columns = $alias . '.' . $joinColumn; |
266 | 270 | } |
@@ -286,17 +290,21 @@ discard block |
||
286 | 290 | foreach ($this->_select as $alias => $column) { |
287 | 291 | if ($column instanceof Aggregation) { |
288 | 292 | $select[$alias] = $this->buildSelectFromAggregation($column); |
289 | - } else if (is_string($column)) { |
|
293 | + } |
|
294 | + else if (is_string($column)) { |
|
290 | 295 | if (strpos($column, 'SELECT') !== false) { |
291 | 296 | $select[$alias] = $column; |
292 | - } else { |
|
297 | + } |
|
298 | + else { |
|
293 | 299 | $select[$alias] = $this->addColumnAlias($builder->fetchColumnName($column)); |
294 | 300 | } |
295 | - } else { |
|
301 | + } |
|
302 | + else { |
|
296 | 303 | $select[$alias] = $column; |
297 | 304 | } |
298 | 305 | } |
299 | - } else if (is_string($this->_select)) { |
|
306 | + } |
|
307 | + else if (is_string($this->_select)) { |
|
300 | 308 | $select = $this->addColumnAlias($this->_select); |
301 | 309 | } |
302 | 310 | return $this->getAdapter()->sqlSelect($select, $this->_queryOptions); |
@@ -316,7 +324,8 @@ discard block |
||
316 | 324 | |
317 | 325 | if ($alias) { |
318 | 326 | $this->_select[$alias] = $select; |
319 | - } else { |
|
327 | + } |
|
328 | + else { |
|
320 | 329 | $this->_select[] = $select; |
321 | 330 | } |
322 | 331 | |
@@ -333,7 +342,8 @@ discard block |
||
333 | 342 | if (is_string($select) && $newSelect = $this->getLookupBuilder()->buildJoin($this, $select)) { |
334 | 343 | list($t_alias, $column) = $newSelect; |
335 | 344 | $this->pushToSelect($t_alias . '.' . $column, $alias); |
336 | - } else { |
|
345 | + } |
|
346 | + else { |
|
337 | 347 | $this->pushToSelect( |
338 | 348 | $this->hydrate($select), |
339 | 349 | $alias |
@@ -359,7 +369,8 @@ discard block |
||
359 | 369 | foreach ($select as $key => $part) { |
360 | 370 | $this->addSelect($part, $key); |
361 | 371 | } |
362 | - } else { |
|
372 | + } |
|
373 | + else { |
|
363 | 374 | $this->addSelect($select); |
364 | 375 | } |
365 | 376 | |
@@ -473,10 +484,12 @@ discard block |
||
473 | 484 | { |
474 | 485 | if ($tableName instanceof QueryBuilderInterface) { |
475 | 486 | $this->_join[] = $this->getAdapter()->sqlJoin($joinType, $tableName, $on, $alias, $index); |
476 | - } else { |
|
487 | + } |
|
488 | + else { |
|
477 | 489 | if ($joinType === 'RAW' && !empty($tableName)) { |
478 | 490 | $join = $this->getAdapter()->quoteSql($tableName); |
479 | - } else { |
|
491 | + } |
|
492 | + else { |
|
480 | 493 | $join = $this->getAdapter()->sqlJoin($joinType, $tableName, $on, $alias); |
481 | 494 | } |
482 | 495 | |
@@ -548,7 +561,8 @@ discard block |
||
548 | 561 | foreach ($columns as $column) { |
549 | 562 | $this->addOrder($column); |
550 | 563 | } |
551 | - } else { |
|
564 | + } |
|
565 | + else { |
|
552 | 566 | $this->addOrder($columns); |
553 | 567 | } |
554 | 568 | |
@@ -582,11 +596,13 @@ discard block |
||
582 | 596 | } |
583 | 597 | |
584 | 598 | $this->_order[] = $_column; |
585 | - } else { |
|
599 | + } |
|
600 | + else { |
|
586 | 601 | $this->_order[] = current($temp); |
587 | 602 | } |
588 | 603 | } |
589 | - } else { |
|
604 | + } |
|
605 | + else { |
|
590 | 606 | $this->_order[] = $column; |
591 | 607 | } |
592 | 608 | |
@@ -675,14 +691,18 @@ discard block |
||
675 | 691 | if (is_numeric($key)) { |
676 | 692 | if ($value instanceof IToSql) { |
677 | 693 | $parts[] = $this->parseCondition($value, $operator); |
678 | - } elseif ($value instanceof QueryBuilder) { |
|
694 | + } |
|
695 | + elseif ($value instanceof QueryBuilder) { |
|
679 | 696 | $parts[] = $this->parseCondition($value, $operator); |
680 | - } else if (is_array($value)) { |
|
697 | + } |
|
698 | + else if (is_array($value)) { |
|
681 | 699 | $parts[] = $this->parseCondition($value, $operator); |
682 | - } else if (is_string($value)) { |
|
700 | + } |
|
701 | + else if (is_string($value)) { |
|
683 | 702 | $parts[] = $value; |
684 | 703 | } |
685 | - } else { |
|
704 | + } |
|
705 | + else { |
|
686 | 706 | $tableAlias = $this->getAlias(); |
687 | 707 | $value = $this->getAdapter()->prepareValue($value); |
688 | 708 | |
@@ -703,13 +723,16 @@ discard block |
||
703 | 723 | return '(' . implode(') ' . $operator . ' (', $parts) . ')'; |
704 | 724 | } |
705 | 725 | |
706 | - } else if ($condition instanceof IToSql) { |
|
726 | + } |
|
727 | + else if ($condition instanceof IToSql) { |
|
707 | 728 | return $condition |
708 | 729 | ->setQb($this) |
709 | 730 | ->toSql(); |
710 | - } else if ($condition instanceof QueryBuilder) { |
|
731 | + } |
|
732 | + else if ($condition instanceof QueryBuilder) { |
|
711 | 733 | return $condition->toSQL(); |
712 | - } else if (is_string($condition)) { |
|
734 | + } |
|
735 | + else if (is_string($condition)) { |
|
713 | 736 | return $condition; |
714 | 737 | } |
715 | 738 | |
@@ -722,7 +745,8 @@ discard block |
||
722 | 745 | foreach ($operands as $operand) { |
723 | 746 | if (is_array($operand)) { |
724 | 747 | $operand = $this->buildCondition($operand, $params); |
725 | - } else { |
|
748 | + } |
|
749 | + else { |
|
726 | 750 | $operand = $this->parseCondition($operand); |
727 | 751 | } |
728 | 752 | if ($operand !== '') { |
@@ -783,7 +807,8 @@ discard block |
||
783 | 807 | foreach ($this->_whereAnd as $condition) { |
784 | 808 | if (empty($where)) { |
785 | 809 | $where = ['and', $condition]; |
786 | - } else { |
|
810 | + } |
|
811 | + else { |
|
787 | 812 | $where = ['and', $where, ['and', $condition]]; |
788 | 813 | } |
789 | 814 | } |
@@ -791,7 +816,8 @@ discard block |
||
791 | 816 | foreach ($this->_whereOr as $condition) { |
792 | 817 | if (empty($where)) { |
793 | 818 | $where = ['or', $condition]; |
794 | - } else { |
|
819 | + } |
|
820 | + else { |
|
795 | 821 | $where = ['or', $where, ['and', $condition]]; |
796 | 822 | } |
797 | 823 | } |
@@ -1116,7 +1142,8 @@ discard block |
||
1116 | 1142 | { |
1117 | 1143 | if (strpos($order, '-') === false) { |
1118 | 1144 | $direction = 'ASC'; |
1119 | - } else { |
|
1145 | + } |
|
1146 | + else { |
|
1120 | 1147 | $direction = 'DESC'; |
1121 | 1148 | $order = substr($order, 1); |
1122 | 1149 | } |
@@ -1153,12 +1180,14 @@ discard block |
||
1153 | 1180 | } |
1154 | 1181 | else if ($column === '?') { |
1155 | 1182 | $order[] = $this->getAdapter()->getRandomOrder(); |
1156 | - } else { |
|
1183 | + } |
|
1184 | + else { |
|
1157 | 1185 | list($newColumn, $direction) = $this->buildOrderJoin($column); |
1158 | 1186 | $order[$this->applyTableAlias($newColumn)] = $direction; |
1159 | 1187 | } |
1160 | 1188 | } |
1161 | - } else { |
|
1189 | + } |
|
1190 | + else { |
|
1162 | 1191 | $order[] = $this->buildOrderJoin($this->_order); |
1163 | 1192 | } |
1164 | 1193 | |
@@ -1205,7 +1234,8 @@ discard block |
||
1205 | 1234 | { |
1206 | 1235 | if ($this->_alias !== null && !is_array($this->_from)) { |
1207 | 1236 | $from = [$this->_alias => $this->_from]; |
1208 | - } else { |
|
1237 | + } |
|
1238 | + else { |
|
1209 | 1239 | $from = $this->_from; |
1210 | 1240 | } |
1211 | 1241 | $sql = $this->getAdapter()->sqlFrom($from); |
@@ -843,7 +843,7 @@ discard block |
||
843 | 843 | |
844 | 844 | protected function generateDeleteSql() |
845 | 845 | { |
846 | - $options = $this->_queryOptions ; |
|
846 | + $options = $this->_queryOptions; |
|
847 | 847 | if ($options) { |
848 | 848 | $options = " {$options} "; |
849 | 849 | } |
@@ -979,7 +979,7 @@ discard block |
||
979 | 979 | $tableName = $this->getAdapter()->getRawTableName($table); |
980 | 980 | |
981 | 981 | if (strpos($tableName, '.') !== false) { |
982 | - $tableName = substr($tableName, strpos($tableName, '.')+1); |
|
982 | + $tableName = substr($tableName, strpos($tableName, '.') + 1); |
|
983 | 983 | } |
984 | 984 | |
985 | 985 | return strtr('{table}_{count}', [ |