summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBruno Perel <brunoperel@gmail.com>2018-11-26 20:02:58 +0100
committerBruno Perel <brunoperel@gmail.com>2018-11-26 20:09:00 +0100
commitef7968e5a80de41c2bbd5ad3d93b6f47fe3f9705 (patch)
treed1025e7c4f85973ef4a92789eafb825b70ce4472
parent513ed8175bdc0fc17a192ea29757cf8fee178c2a (diff)
downloadsql-parser-ef7968e5a80de41c2bbd5ad3d93b6f47fe3f9705.zip
sql-parser-ef7968e5a80de41c2bbd5ad3d93b6f47fe3f9705.tar.gz
sql-parser-ef7968e5a80de41c2bbd5ad3d93b6f47fe3f9705.tar.bz2
Use triple (in)equalities when type compatibility is ensured
-rw-r--r--src/Components/AlterOperation.php2
-rw-r--r--src/Components/Array2d.php2
-rw-r--r--src/Components/Condition.php2
-rw-r--r--src/Components/Expression.php2
-rw-r--r--src/Components/IntoKeyword.php4
-rw-r--r--src/Components/OptionsArray.php8
-rw-r--r--src/Components/SetOperation.php4
-rw-r--r--src/Context.php6
-rw-r--r--src/Statement.php10
-rw-r--r--src/Statements/CreateStatement.php18
-rw-r--r--src/Statements/DeleteStatement.php14
-rw-r--r--src/Statements/InsertStatement.php10
-rw-r--r--src/Statements/ReplaceStatement.php6
-rw-r--r--src/Utils/BufferedQuery.php4
-rw-r--r--src/Utils/CLI.php2
-rw-r--r--src/Utils/Formatter.php6
-rw-r--r--src/Utils/Query.php4
-rw-r--r--tools/ContextGenerator.php10
18 files changed, 56 insertions, 58 deletions
diff --git a/src/Components/AlterOperation.php b/src/Components/AlterOperation.php
index 9383eca..1ae28ae 100644
--- a/src/Components/AlterOperation.php
+++ b/src/Components/AlterOperation.php
@@ -236,7 +236,7 @@ class AlterOperation extends Component
// We have reached the end of ALTER operation and suddenly found
// a start to new statement, but have not find a delimiter between them
- if (!($token->value == 'SET' && $list->tokens[$list->idx - 1]->value == 'CHARACTER')) {
+ if (!($token->value === 'SET' && $list->tokens[$list->idx - 1]->value === 'CHARACTER')) {
$parser->error(
'A new statement was found, but no delimiter between it and the previous one.',
$token
diff --git a/src/Components/Array2d.php b/src/Components/Array2d.php
index 92d8b16..984179c 100644
--- a/src/Components/Array2d.php
+++ b/src/Components/Array2d.php
@@ -82,7 +82,7 @@ class Array2d extends Component
$arrCount = count($arr->values);
if ($count === -1) {
$count = $arrCount;
- } elseif ($arrCount != $count) {
+ } elseif ($arrCount !== $count) {
$parser->error(
sprintf(
Translator::gettext('%1$d values were expected, but found %2$d.'),
diff --git a/src/Components/Condition.php b/src/Components/Condition.php
index 4e12b3f..2be0abd 100644
--- a/src/Components/Condition.php
+++ b/src/Components/Condition.php
@@ -179,7 +179,7 @@ class Condition extends Component
if ($token->value === '(') {
++$brackets;
} elseif ($token->value === ')') {
- if ($brackets == 0) {
+ if ($brackets === 0) {
break;
}
--$brackets;
diff --git a/src/Components/Expression.php b/src/Components/Expression.php
index 4a83f63..5350e36 100644
--- a/src/Components/Expression.php
+++ b/src/Components/Expression.php
@@ -299,7 +299,7 @@ class Expression extends Component
$ret->function = $prev[1]->value;
}
} elseif ($token->value === ')') {
- if ($brackets == 0) {
+ if ($brackets === 0) {
// Not our bracket
break;
} else {
diff --git a/src/Components/IntoKeyword.php b/src/Components/IntoKeyword.php
index dd3f7f6..c0fa390 100644
--- a/src/Components/IntoKeyword.php
+++ b/src/Components/IntoKeyword.php
@@ -207,10 +207,10 @@ class IntoKeyword extends Component
$ret->dest = $token->value;
$state = 3;
- } elseif ($state == 3) {
+ } elseif ($state === 3) {
$ret->parseFileOptions($parser, $list, $token->value);
$state = 4;
- } elseif ($state == 4) {
+ } elseif ($state === 4) {
if ($token->type === Token::TYPE_KEYWORD && $token->keyword !== 'LINES') {
break;
}
diff --git a/src/Components/OptionsArray.php b/src/Components/OptionsArray.php
index 871772b..fd02d22 100644
--- a/src/Components/OptionsArray.php
+++ b/src/Components/OptionsArray.php
@@ -247,10 +247,10 @@ class OptionsArray extends Component
*/
if ($state === 1
&& $lastOption
- && ($lastOption[1] == 'expr'
- || $lastOption[1] == 'var'
- || $lastOption[1] == 'var='
- || $lastOption[1] == 'expr=')
+ && ($lastOption[1] === 'expr'
+ || $lastOption[1] === 'var'
+ || $lastOption[1] === 'var='
+ || $lastOption[1] === 'expr=')
) {
$parser->error(
sprintf(
diff --git a/src/Components/SetOperation.php b/src/Components/SetOperation.php
index 83f2e55..7dab0a1 100644
--- a/src/Components/SetOperation.php
+++ b/src/Components/SetOperation.php
@@ -94,7 +94,7 @@ class SetOperation extends Component
// No keyword is expected.
if (($token->type === Token::TYPE_KEYWORD)
&& ($token->flags & Token::FLAG_KEYWORD_RESERVED)
- && ($state == 0)
+ && ($state === 0)
) {
break;
}
@@ -113,7 +113,7 @@ class SetOperation extends Component
'breakOnAlias' => true,
)
);
- if ($tmp == null) {
+ if (is_null($tmp)) {
$parser->error('Missing expression.', $token);
break;
}
diff --git a/src/Context.php b/src/Context.php
index b381aa7..869a9bb 100644
--- a/src/Context.php
+++ b/src/Context.php
@@ -313,7 +313,7 @@ abstract class Context
public static function isComment($str, $end = false)
{
$len = strlen($str);
- if ($len == 0) {
+ if ($len === 0) {
return null;
}
if ($str[0] === '#') {
@@ -382,7 +382,7 @@ abstract class Context
*/
public static function isSymbol($str)
{
- if (strlen($str) == 0) {
+ if (strlen($str) === 0) {
return null;
}
if ($str[0] === '@') {
@@ -408,7 +408,7 @@ abstract class Context
*/
public static function isString($str)
{
- if (strlen($str) == 0) {
+ if (strlen($str) === 0) {
return null;
}
if ($str[0] === '\'') {
diff --git a/src/Statement.php b/src/Statement.php
index 50acb71..4186275 100644
--- a/src/Statement.php
+++ b/src/Statement.php
@@ -451,9 +451,7 @@ abstract class Statement
{
$clauses = array_flip(array_keys($this->getClauses()));
- if (empty($clauses)
- || count($clauses) == 0
- ) {
+ if (empty($clauses) || count($clauses) === 0) {
return true;
}
@@ -489,7 +487,7 @@ abstract class Statement
);
// Handle ordering of Multiple Joins in a query
- if ($clauseStartIdx != -1) {
+ if ($clauseStartIdx !== -1) {
if ($minJoin === 0 && stripos($clauseType, 'JOIN')) {
// First JOIN clause is detected
$minJoin = $maxJoin = $clauseStartIdx;
@@ -501,7 +499,7 @@ abstract class Statement
}
}
- if ($clauseStartIdx != -1 && $clauseStartIdx < $minIdx) {
+ if ($clauseStartIdx !== -1 && $clauseStartIdx < $minIdx) {
if ($minJoin === 0 || $error === 1) {
$token = $list->tokens[$clauseStartIdx];
$parser->error(
@@ -512,7 +510,7 @@ abstract class Statement
return false;
}
$minIdx = $clauseStartIdx;
- } elseif ($clauseStartIdx != -1) {
+ } elseif ($clauseStartIdx !== -1) {
$minIdx = $clauseStartIdx;
}
diff --git a/src/Statements/CreateStatement.php b/src/Statements/CreateStatement.php
index c164c25..3b705c3 100644
--- a/src/Statements/CreateStatement.php
+++ b/src/Statements/CreateStatement.php
@@ -388,7 +388,7 @@ class CreateStatement extends Statement
*/
$token = $list->tokens[$list->idx];
$nextidx = $list->idx + 1;
- while ($nextidx < $list->count && $list->tokens[$nextidx]->type == Token::TYPE_WHITESPACE) {
+ while ($nextidx < $list->count && $list->tokens[$nextidx]->type === Token::TYPE_WHITESPACE) {
++$nextidx;
}
@@ -399,18 +399,18 @@ class CreateStatement extends Statement
static::$DB_OPTIONS
);
} elseif ($this->options->has('TABLE')) {
- if (($token->type == Token::TYPE_KEYWORD)
- && ($token->keyword == 'SELECT')) {
+ if (($token->type === Token::TYPE_KEYWORD)
+ && ($token->keyword === 'SELECT')) {
/* CREATE TABLE ... SELECT */
$this->select = new SelectStatement($parser, $list);
- } elseif (($token->type == Token::TYPE_KEYWORD) && ($token->keyword == 'AS')
- && ($list->tokens[$nextidx]->type == Token::TYPE_KEYWORD)
- && ($list->tokens[$nextidx]->value == 'SELECT')) {
+ } elseif (($token->type === Token::TYPE_KEYWORD) && ($token->keyword === 'AS')
+ && ($list->tokens[$nextidx]->type === Token::TYPE_KEYWORD)
+ && ($list->tokens[$nextidx]->value === 'SELECT')) {
/* CREATE TABLE ... AS SELECT */
$list->idx = $nextidx;
$this->select = new SelectStatement($parser, $list);
- } elseif ($token->type == Token::TYPE_KEYWORD
- && $token->keyword == 'LIKE') {
+ } elseif ($token->type === Token::TYPE_KEYWORD
+ && $token->keyword === 'LIKE') {
/* CREATE TABLE `new_tbl` LIKE 'orig_tbl' */
$list->idx = $nextidx;
$this->like = Expression::parse(
@@ -422,7 +422,7 @@ class CreateStatement extends Statement
)
);
// The 'LIKE' keyword was found, but no table_name was found next to it
- if ($this->like == null) {
+ if (is_null($this->like)) {
$parser->error(
'A table name was expected.',
$list->tokens[$list->idx]
diff --git a/src/Statements/DeleteStatement.php b/src/Statements/DeleteStatement.php
index 20b6bcf..7ff0025 100644
--- a/src/Statements/DeleteStatement.php
+++ b/src/Statements/DeleteStatement.php
@@ -142,25 +142,25 @@ class DeleteStatement extends Statement
{
$ret = 'DELETE ' . OptionsArray::build($this->options);
- if ($this->columns != null && count($this->columns) > 0) {
+ if (!is_null($this->columns) && count($this->columns) > 0) {
$ret .= ' ' . ExpressionArray::build($this->columns);
}
- if ($this->from != null && count($this->from) > 0) {
+ if (!is_null($this->from) && count($this->from) > 0) {
$ret .= ' FROM ' . ExpressionArray::build($this->from);
}
- if ($this->join != null && count($this->join) > 0) {
+ if (!is_null($this->join) && count($this->join) > 0) {
$ret .= ' ' . JoinKeyword::build($this->join);
}
- if ($this->using != null && count($this->using) > 0) {
+ if (!is_null($this->using) && count($this->using) > 0) {
$ret .= ' USING ' . ExpressionArray::build($this->using);
}
- if ($this->where != null && count($this->where) > 0) {
+ if (!is_null($this->where) && count($this->where) > 0) {
$ret .= ' WHERE ' . Condition::build($this->where);
}
- if ($this->order != null && count($this->order) > 0) {
+ if (!is_null($this->order) && count($this->order) > 0) {
$ret .= ' ORDER BY ' . ExpressionArray::build($this->order);
}
- if ($this->limit != null && strlen($this->limit) > 0) {
+ if (!is_null($this->limit) && strlen($this->limit) > 0) {
$ret .= ' LIMIT ' . Limit::build($this->limit);
}
diff --git a/src/Statements/InsertStatement.php b/src/Statements/InsertStatement.php
index 1bdf73b..312b4e0 100644
--- a/src/Statements/InsertStatement.php
+++ b/src/Statements/InsertStatement.php
@@ -113,15 +113,15 @@ class InsertStatement extends Statement
$ret = 'INSERT ' . $this->options
. ' INTO ' . $this->into;
- if ($this->values != null && count($this->values) > 0) {
+ if (!is_null($this->values) && count($this->values) > 0) {
$ret .= ' VALUES ' . Array2d::build($this->values);
- } elseif ($this->set != null && count($this->set) > 0) {
+ } elseif (!is_null($this->set) && count($this->set) > 0) {
$ret .= ' SET ' . SetOperation::build($this->set);
- } elseif ($this->select != null && strlen($this->select) > 0) {
+ } elseif (!is_null($this->select) && strlen($this->select) > 0) {
$ret .= ' ' . $this->select->build();
}
- if ($this->onDuplicateSet != null && count($this->onDuplicateSet) > 0) {
+ if (!is_null($this->onDuplicateSet) && count($this->onDuplicateSet) > 0) {
$ret .= ' ON DUPLICATE KEY UPDATE ' . SetOperation::build($this->onDuplicateSet);
}
@@ -229,7 +229,7 @@ class InsertStatement extends Statement
);
break;
}
- } elseif ($state == 2) {
+ } elseif ($state === 2) {
$lastCount = $miniState;
if ($miniState === 1 && $token->keyword === 'ON') {
diff --git a/src/Statements/ReplaceStatement.php b/src/Statements/ReplaceStatement.php
index 59d66ae..40b1194 100644
--- a/src/Statements/ReplaceStatement.php
+++ b/src/Statements/ReplaceStatement.php
@@ -89,11 +89,11 @@ class ReplaceStatement extends Statement
{
$ret = 'REPLACE ' . $this->options . ' INTO ' . $this->into;
- if ($this->values != null && count($this->values) > 0) {
+ if (!is_null($this->values) && count($this->values) > 0) {
$ret .= ' VALUES ' . Array2d::build($this->values);
- } elseif ($this->set != null && count($this->set) > 0) {
+ } elseif (!is_null($this->set) && count($this->set) > 0) {
$ret .= ' SET ' . SetOperation::build($this->set);
- } elseif ($this->select != null && strlen($this->select) > 0) {
+ } elseif (!is_null($this->select) && strlen($this->select) > 0) {
$ret .= ' ' . $this->select->build();
}
diff --git a/src/Utils/BufferedQuery.php b/src/Utils/BufferedQuery.php
index 9b0cda7..ee0dca4 100644
--- a/src/Utils/BufferedQuery.php
+++ b/src/Utils/BufferedQuery.php
@@ -191,7 +191,7 @@ class BufferedQuery
* treated differently, because of the preceding backslash, it will
* be ignored.
*/
- if ((($this->status & static::STATUS_COMMENT) == 0) && ($this->query[$i] === '\\')) {
+ if ((($this->status & static::STATUS_COMMENT) === 0) && ($this->query[$i] === '\\')) {
$this->current .= $this->query[$i] . $this->query[++$i];
continue;
}
@@ -319,7 +319,7 @@ class BufferedQuery
}
// Checking if the delimiter definition ended.
- if (($delimiter != '')
+ if (($delimiter !== '')
&& ((($i < $len) && Context::isWhitespace($this->query[$i]))
|| (($i === $len) && $end))
) {
diff --git a/src/Utils/CLI.php b/src/Utils/CLI.php
index d412789..3dc48a6 100644
--- a/src/Utils/CLI.php
+++ b/src/Utils/CLI.php
@@ -120,7 +120,7 @@ class CLI
$lexer = new Lexer($params['q'], false);
$parser = new Parser($lexer->list);
$errors = Error::get(array($lexer, $parser));
- if (count($errors) == 0) {
+ if (count($errors) === 0) {
return 0;
}
$output = Error::format($errors);
diff --git a/src/Utils/Formatter.php b/src/Utils/Formatter.php
index 4bfdc26..c41c69c 100644
--- a/src/Utils/Formatter.php
+++ b/src/Utils/Formatter.php
@@ -554,7 +554,7 @@ class Formatter
if ($this->options['type'] === 'html') {
return '<span ' . $format['html'] . '>' . htmlspecialchars($text, ENT_NOQUOTES) . '</span>';
} elseif ($this->options['type'] === 'cli') {
- if ($prev != $format['cli']) {
+ if ($prev !== $format['cli']) {
$prev = $format['cli'];
return $format['cli'] . $this->escapeConsole($text);
@@ -568,7 +568,7 @@ class Formatter
}
if ($this->options['type'] === 'cli') {
- if ($prev != "\x1b[39m") {
+ if ($prev !== "\x1b[39m") {
$prev = "\x1b[39m";
return "\x1b[39m" . $this->escapeConsole($text);
@@ -633,7 +633,7 @@ class Formatter
++$count;
} elseif ($list->tokens[$idx]->value === ')') {
--$count;
- if ($count == 0) {
+ if ($count === 0) {
break;
}
}
diff --git a/src/Utils/Query.php b/src/Utils/Query.php
index 7a8f462..f928ab3 100644
--- a/src/Utils/Query.php
+++ b/src/Utils/Query.php
@@ -633,7 +633,7 @@ class Query
&& ($clauses[$token->keyword] >= $currIdx)
) {
$currIdx = $clauses[$token->keyword];
- if ($skipFirst && ($currIdx == $clauseIdx)) {
+ if ($skipFirst && ($currIdx === $clauseIdx)) {
// This token is skipped (not added to the old
// clause) because it will be replaced.
continue;
@@ -843,7 +843,7 @@ class Query
}
}
- if ($brackets == 0) {
+ if ($brackets === 0) {
if (($token->type === Token::TYPE_KEYWORD)
&& isset($clauses[$token->keyword])
&& ($clause === $token->keyword)
diff --git a/tools/ContextGenerator.php b/tools/ContextGenerator.php
index dccc155..503c0e9 100644
--- a/tools/ContextGenerator.php
+++ b/tools/ContextGenerator.php
@@ -131,7 +131,7 @@ class ContextGenerator
$types = array();
- for ($i = 0, $count = count($words); $i != $count; ++$i) {
+ for ($i = 0, $count = count($words); $i !== $count; ++$i) {
$type = 1;
$value = trim($words[$i]);
@@ -198,17 +198,17 @@ class ContextGenerator
$i = 0;
foreach ($wordsByLen as $word) {
- if ($i == 0) {
+ if ($i === 0) {
$ret .= str_repeat(' ', $spaces);
}
$ret .= sprintf('\'%s\' => %s, ', $word, $type);
- if (++$i == $count) {
+ if (++$i === $count) {
$ret .= "\n";
$i = 0;
}
}
- if ($i != 0) {
+ if ($i !== 0) {
$ret .= "\n";
}
}
@@ -272,7 +272,7 @@ class ContextGenerator
/* Parse version to array */
$ver_str = $parts[2];
- if (strlen($ver_str) % 2 == 1) {
+ if (strlen($ver_str) % 2 === 1) {
$ver_str = '0' . $ver_str;
}
$version = array_map('intval', str_split($ver_str, 2));