Skip to content

Commit

Permalink
Use triple (in)equalities when type compatibility is ensured
Browse files Browse the repository at this point in the history
  • Loading branch information
bperel committed Nov 26, 2018
1 parent 513ed81 commit ef7968e
Show file tree
Hide file tree
Showing 18 changed files with 56 additions and 58 deletions.
2 changes: 1 addition & 1 deletion src/Components/AlterOperation.php
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ public static function parse(Parser $parser, TokensList $list, array $options =
// 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
Expand Down
2 changes: 1 addition & 1 deletion src/Components/Array2d.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public static function parse(Parser $parser, TokensList $list, array $options =
$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.'),
Expand Down
2 changes: 1 addition & 1 deletion src/Components/Condition.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ public static function parse(Parser $parser, TokensList $list, array $options =
if ($token->value === '(') {
++$brackets;
} elseif ($token->value === ')') {
if ($brackets == 0) {
if ($brackets === 0) {
break;
}
--$brackets;
Expand Down
2 changes: 1 addition & 1 deletion src/Components/Expression.php
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ public static function parse(Parser $parser, TokensList $list, array $options =
$ret->function = $prev[1]->value;
}
} elseif ($token->value === ')') {
if ($brackets == 0) {
if ($brackets === 0) {
// Not our bracket
break;
} else {
Expand Down
4 changes: 2 additions & 2 deletions src/Components/IntoKeyword.php
Original file line number Diff line number Diff line change
Expand Up @@ -207,10 +207,10 @@ public static function parse(Parser $parser, TokensList $list, array $options =
$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;
}
Expand Down
8 changes: 4 additions & 4 deletions src/Components/OptionsArray.php
Original file line number Diff line number Diff line change
Expand Up @@ -247,10 +247,10 @@ public static function parse(Parser $parser, TokensList $list, array $options =
*/
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(
Expand Down
4 changes: 2 additions & 2 deletions src/Components/SetOperation.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public static function parse(Parser $parser, TokensList $list, array $options =
// No keyword is expected.
if (($token->type === Token::TYPE_KEYWORD)
&& ($token->flags & Token::FLAG_KEYWORD_RESERVED)
&& ($state == 0)
&& ($state === 0)
) {
break;
}
Expand All @@ -113,7 +113,7 @@ public static function parse(Parser $parser, TokensList $list, array $options =
'breakOnAlias' => true,
)
);
if ($tmp == null) {
if (is_null($tmp)) {
$parser->error('Missing expression.', $token);
break;
}
Expand Down
6 changes: 3 additions & 3 deletions src/Context.php
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ public static function isWhitespace($str)
public static function isComment($str, $end = false)
{
$len = strlen($str);
if ($len == 0) {
if ($len === 0) {
return null;
}
if ($str[0] === '#') {
Expand Down Expand Up @@ -382,7 +382,7 @@ public static function isNumber($str)
*/
public static function isSymbol($str)
{
if (strlen($str) == 0) {
if (strlen($str) === 0) {
return null;
}
if ($str[0] === '@') {
Expand All @@ -408,7 +408,7 @@ public static function isSymbol($str)
*/
public static function isString($str)
{
if (strlen($str) == 0) {
if (strlen($str) === 0) {
return null;
}
if ($str[0] === '\'') {
Expand Down
10 changes: 4 additions & 6 deletions src/Statement.php
Original file line number Diff line number Diff line change
Expand Up @@ -451,9 +451,7 @@ public function validateClauseOrder($parser, $list)
{
$clauses = array_flip(array_keys($this->getClauses()));

if (empty($clauses)
|| count($clauses) == 0
) {
if (empty($clauses) || count($clauses) === 0) {
return true;
}

Expand Down Expand Up @@ -489,7 +487,7 @@ public function validateClauseOrder($parser, $list)
);

// 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;
Expand All @@ -501,7 +499,7 @@ public function validateClauseOrder($parser, $list)
}
}

if ($clauseStartIdx != -1 && $clauseStartIdx < $minIdx) {
if ($clauseStartIdx !== -1 && $clauseStartIdx < $minIdx) {
if ($minJoin === 0 || $error === 1) {
$token = $list->tokens[$clauseStartIdx];
$parser->error(
Expand All @@ -512,7 +510,7 @@ public function validateClauseOrder($parser, $list)
return false;
}
$minIdx = $clauseStartIdx;
} elseif ($clauseStartIdx != -1) {
} elseif ($clauseStartIdx !== -1) {
$minIdx = $clauseStartIdx;
}

Expand Down
18 changes: 9 additions & 9 deletions src/Statements/CreateStatement.php
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ public function parse(Parser $parser, TokensList $list)
*/
$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;
}

Expand All @@ -399,18 +399,18 @@ public function parse(Parser $parser, TokensList $list)
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(
Expand All @@ -422,7 +422,7 @@ public function parse(Parser $parser, TokensList $list)
)
);
// 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]
Expand Down
14 changes: 7 additions & 7 deletions src/Statements/DeleteStatement.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,25 +142,25 @@ public function build()
{
$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);
}

Expand Down
10 changes: 5 additions & 5 deletions src/Statements/InsertStatement.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,15 +113,15 @@ public function build()
$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);
}

Expand Down Expand Up @@ -229,7 +229,7 @@ public function parse(Parser $parser, TokensList $list)
);
break;
}
} elseif ($state == 2) {
} elseif ($state === 2) {
$lastCount = $miniState;

if ($miniState === 1 && $token->keyword === 'ON') {
Expand Down
6 changes: 3 additions & 3 deletions src/Statements/ReplaceStatement.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,11 @@ public function build()
{
$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();
}

Expand Down
4 changes: 2 additions & 2 deletions src/Utils/BufferedQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ public function extract($end = false)
* 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;
}
Expand Down Expand Up @@ -319,7 +319,7 @@ public function extract($end = false)
}

// Checking if the delimiter definition ended.
if (($delimiter != '')
if (($delimiter !== '')
&& ((($i < $len) && Context::isWhitespace($this->query[$i]))
|| (($i === $len) && $end))
) {
Expand Down
2 changes: 1 addition & 1 deletion src/Utils/CLI.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public function runLint()
$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);
Expand Down
6 changes: 3 additions & 3 deletions src/Utils/Formatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,7 @@ public function toString($token)
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);
Expand All @@ -568,7 +568,7 @@ public function toString($token)
}

if ($this->options['type'] === 'cli') {
if ($prev != "\x1b[39m") {
if ($prev !== "\x1b[39m") {
$prev = "\x1b[39m";

return "\x1b[39m" . $this->escapeConsole($text);
Expand Down Expand Up @@ -633,7 +633,7 @@ public static function getGroupLength($list)
++$count;
} elseif ($list->tokens[$idx]->value === ')') {
--$count;
if ($count == 0) {
if ($count === 0) {
break;
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/Utils/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -633,7 +633,7 @@ public static function getClause($statement, $list, $clause, $type = 0, $skipFir
&& ($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;
Expand Down Expand Up @@ -843,7 +843,7 @@ public static function getClauseStartOffset($statement, $list, $clause)
}
}

if ($brackets == 0) {
if ($brackets === 0) {
if (($token->type === Token::TYPE_KEYWORD)
&& isset($clauses[$token->keyword])
&& ($clause === $token->keyword)
Expand Down
10 changes: 5 additions & 5 deletions tools/ContextGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ public static function readWords(array $files)

$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]);

Expand Down Expand Up @@ -198,17 +198,17 @@ public static function printWords($words, $spaces = 8, $line = 80)
$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";
}
}
Expand Down Expand Up @@ -272,7 +272,7 @@ public static function formatName($name)

/* 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));
Expand Down

0 comments on commit ef7968e

Please sign in to comment.