diff options
author | Dan Ungureanu <udan1107@gmail.com> | 2016-02-21 16:09:44 +0200 |
---|---|---|
committer | Dan Ungureanu <udan1107@gmail.com> | 2016-02-21 16:09:44 +0200 |
commit | 802733fc701437b7b421ab66757c26d5f2b756da (patch) | |
tree | e507d7baf4ce0c2f3530b38ab2379024becbd878 /src | |
parent | bc47af8d0702a004a743a6abb473c27cd3b6010d (diff) | |
download | sql-parser-802733fc701437b7b421ab66757c26d5f2b756da.zip sql-parser-802733fc701437b7b421ab66757c26d5f2b756da.tar.gz sql-parser-802733fc701437b7b421ab66757c26d5f2b756da.tar.bz2 |
Misc: Fixed some more issues reported by Scrutinizer.
Signed-off-by: Dan Ungureanu <udan1107@gmail.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/Components/ArrayObj.php | 2 | ||||
-rw-r--r-- | src/Components/JoinKeyword.php | 3 | ||||
-rw-r--r-- | src/Components/Key.php | 2 | ||||
-rw-r--r-- | src/Components/OrderKeyword.php | 8 | ||||
-rw-r--r-- | src/Components/SetOperation.php | 5 | ||||
-rw-r--r-- | src/Statements/AlterStatement.php | 4 | ||||
-rw-r--r-- | src/Token.php | 8 | ||||
-rw-r--r-- | src/Utils/Formatter.php | 19 |
8 files changed, 30 insertions, 21 deletions
diff --git a/src/Components/ArrayObj.php b/src/Components/ArrayObj.php index 56c7247..627f8c7 100644 --- a/src/Components/ArrayObj.php +++ b/src/Components/ArrayObj.php @@ -108,7 +108,7 @@ class ArrayObj extends Component || ($token->type === Token::TYPE_COMMENT) ) { $lastRaw .= $token->token; - $lastValue = trim($lastValue) .' '; + $lastValue = trim($lastValue) . ' '; continue; } diff --git a/src/Components/JoinKeyword.php b/src/Components/JoinKeyword.php index 7546b56..75ecca6 100644 --- a/src/Components/JoinKeyword.php +++ b/src/Components/JoinKeyword.php @@ -62,6 +62,7 @@ class JoinKeyword extends Component * @var Condition[] */ public $on; + /** * Columns in Using clause * @@ -180,7 +181,7 @@ class JoinKeyword extends Component $ret = array(); foreach ($component as $c) { $ret[] = array_search($c->type, static::$JOINS) . ' ' . $c->expr - . (! empty($c->on) + . (!empty($c->on) ? ' ON ' . Condition::build($c->on) : ' USING ' . ArrayObj::build($c->using)); } diff --git a/src/Components/Key.php b/src/Components/Key.php index 161dfc6..ef066dd 100644 --- a/src/Components/Key.php +++ b/src/Components/Key.php @@ -93,7 +93,7 @@ class Key extends Component * @param TokensList $list The list of tokens that are being parsed. * @param array $options Parameters for parsing. * - * @return Key[] + * @return Key */ public static function parse(Parser $parser, TokensList $list, array $options = array()) { diff --git a/src/Components/OrderKeyword.php b/src/Components/OrderKeyword.php index fc226f0..7d23013 100644 --- a/src/Components/OrderKeyword.php +++ b/src/Components/OrderKeyword.php @@ -100,9 +100,13 @@ class OrderKeyword extends Component $expr->expr = Expression::parse($parser, $list); $state = 1; } elseif ($state === 1) { - if (($token->type === Token::TYPE_KEYWORD) && (($token->value === 'ASC') || ($token->value === 'DESC'))) { + if (($token->type === Token::TYPE_KEYWORD) + && (($token->value === 'ASC') || ($token->value === 'DESC')) + ) { $expr->type = $token->value; - } elseif (($token->type === Token::TYPE_OPERATOR) && ($token->value === ',')) { + } elseif (($token->type === Token::TYPE_OPERATOR) + && ($token->value === ',') + ) { if (!empty($expr->expr)) { $ret[] = $expr; } diff --git a/src/Components/SetOperation.php b/src/Components/SetOperation.php index ad43d1c..ffe754a 100644 --- a/src/Components/SetOperation.php +++ b/src/Components/SetOperation.php @@ -85,7 +85,10 @@ class SetOperation extends Component } // No keyword is expected. - if (($token->type === Token::TYPE_KEYWORD) && ($token->flags & Token::FLAG_KEYWORD_RESERVED) && ($state == 0)) { + if (($token->type === Token::TYPE_KEYWORD) + && ($token->flags & Token::FLAG_KEYWORD_RESERVED) + && ($state == 0) + ) { break; } diff --git a/src/Statements/AlterStatement.php b/src/Statements/AlterStatement.php index 4aea0d6..e765999 100644 --- a/src/Statements/AlterStatement.php +++ b/src/Statements/AlterStatement.php @@ -151,7 +151,7 @@ class AlterStatement extends Statement } return 'ALTER ' . OptionsArray::build($this->options) - . ' ' . Expression::build($this->table) - . ' ' . implode(', ', $tmp); + . ' ' . Expression::build($this->table) + . ' ' . implode(', ', $tmp); } } diff --git a/src/Token.php b/src/Token.php index 9659672..18ffec7 100644 --- a/src/Token.php +++ b/src/Token.php @@ -235,17 +235,17 @@ class Token if ($this->flags & Token::FLAG_NUMBER_HEX) { if ($this->flags & Token::FLAG_NUMBER_NEGATIVE) { $ret = str_replace('-', '', $this->token); - sscanf($ret, "%x", $ret); + sscanf($ret, '%x', $ret); $ret = -$ret; } else { - sscanf($ret, "%x", $ret); + sscanf($ret, '%x', $ret); } } elseif (($this->flags & Token::FLAG_NUMBER_APPROXIMATE) || ($this->flags & Token::FLAG_NUMBER_FLOAT) ) { - sscanf($ret, "%f", $ret); + sscanf($ret, '%f', $ret); } else { - sscanf($ret, "%d", $ret); + sscanf($ret, '%d', $ret); } return $ret; case Token::TYPE_STRING: diff --git a/src/Utils/Formatter.php b/src/Utils/Formatter.php index 266440b..2ac7e3b 100644 --- a/src/Utils/Formatter.php +++ b/src/Utils/Formatter.php @@ -80,7 +80,7 @@ class Formatter * * @var string */ - 'indentation' => " ", + 'indentation' => ' ', /** * Whether comments should be removed or not. @@ -122,49 +122,49 @@ class Formatter 'type' => Token::TYPE_KEYWORD, 'flags' => Token::FLAG_KEYWORD_RESERVED, 'html' => 'class="sql-reserved"', - 'cli' => "\e[35m", + 'cli' => "\e[35m", 'function' => 'strtoupper', ), array( 'type' => Token::TYPE_KEYWORD, 'flags' => 0, 'html' => 'class="sql-keyword"', - 'cli' => "\e[95m", + 'cli' => "\e[95m", 'function' => 'strtoupper', ), array( 'type' => Token::TYPE_COMMENT, 'flags' => 0, 'html' => 'class="sql-comment"', - 'cli' => "\e[37m", + 'cli' => "\e[37m", 'function' => '', ), array( 'type' => Token::TYPE_BOOL, 'flags' => 0, 'html' => 'class="sql-atom"', - 'cli' => "\e[36m", + 'cli' => "\e[36m", 'function' => 'strtoupper', ), array( 'type' => Token::TYPE_NUMBER, 'flags' => 0, 'html' => 'class="sql-number"', - 'cli' => "\e[92m", + 'cli' => "\e[92m", 'function' => 'strtolower', ), array( 'type' => Token::TYPE_STRING, 'flags' => 0, 'html' => 'class="sql-string"', - 'cli' => "\e[91m", + 'cli' => "\e[91m", 'function' => '', ), array( 'type' => Token::TYPE_SYMBOL, 'flags' => 0, 'html' => 'class="sql-variable"', - 'cli' => "\e[36m", + 'cli' => "\e[36m", 'function' => '', ), ) @@ -387,7 +387,8 @@ class Formatter // Also, some tokens do not have spaces before or after them. if (!((($prev->type === Token::TYPE_OPERATOR) && (($prev->value === '.') || ($prev->value === '('))) // No space after . ( - || (($curr->type === Token::TYPE_OPERATOR) && (($curr->value === '.') || ($curr->value === ',') || ($curr->value === '(') || ($curr->value === ')'))) + || (($curr->type === Token::TYPE_OPERATOR) && (($curr->value === '.') || ($curr->value === ',') + || ($curr->value === '(') || ($curr->value === ')'))) // No space before . , ( ) || (($curr->type === Token::TYPE_DELIMITER)) && (mb_strlen($curr->value, 'UTF-8') < 2)) // A space after delimiters that are longer than 2 characters. |