Skip to content

Commit

Permalink
code improvements for readability
Browse files Browse the repository at this point in the history
Signed-off-by: Fawzi E. Abdulfattah <[email protected]>
  • Loading branch information
iifawzi committed Aug 15, 2021
1 parent bfa7222 commit 19f053d
Showing 1 changed file with 12 additions and 22 deletions.
34 changes: 12 additions & 22 deletions src/Components/AlterOperation.php
Original file line number Diff line number Diff line change
Expand Up @@ -279,9 +279,6 @@ public static function parse(Parser $parser, TokensList $list, array $options =
}
} elseif (! self::checkIfTokenQuotedSymbol($token)) {
if (! empty(Parser::$STATEMENT_PARSERS[$token->value])) {
// We have reached the end of ALTER operation and suddenly found
// a start to new statement, but have not find a delimiter between them

// We want to get the next non-comment and non-space token after $token
// therefore, the first getNext call will start with the current $idx which's $token,
// will return it and increase $idx by 1, which's not guaranteed to be non-comment
Expand All @@ -292,32 +289,25 @@ public static function parse(Parser $parser, TokensList $list, array $options =
$list->getNext();
$nextToken = $list->getNext();

if (
($token->value !== 'SET' ||
(
$list->tokens[$currentTokenID - 1]->value !== 'CHARACTER' &&
$nextToken->value !== '(' &&
$nextToken->value !== 'DEFAULT'
)
)
) {
if ($token->value === 'SET' && $list->tokens[$currentTokenID - 1]->value === 'CHARACTER'){
// Reverting the changes we made in the beginning
$list->idx = $currentTokenID;
} else if ($token->value === 'SET' && $nextToken->value === '('){
// To avoid adding the tokens between the SET() parentheses to the unknown tokens
$list->getNextOfTypeAndValue(Token::TYPE_OPERATOR, ')');
} else if ($token->value === 'SET' && $nextToken->value === 'DEFAULT'){
// to avoid adding the `DEFAULT` token to the unknown tokens.
++$list->idx;
} else {
// We have reached the end of ALTER operation and suddenly found
// a start to new statement, but have not find a delimiter between them
$parser->error(
'A new statement was found, but no delimiter between it and the previous one.',
$token
);
break;
}

if ($nextToken->value === '(') {
// To avoid adding the tokens between the SET() parentheses to the unknown tokens
$list->getNextOfTypeAndValue(Token::TYPE_OPERATOR, ')');
} elseif ($nextToken->value === 'DEFAULT') {
// to avoid adding the `DEFAULT` token to the unknown tokens.
++$list->idx;
} else {
// Reverting the changes we made in the beginning
$list->idx = $currentTokenID;
}
} elseif ((array_key_exists($array_key, self::$DB_OPTIONS)
|| array_key_exists($array_key, self::$TABLE_OPTIONS))
&& ! self::checkIfColumnDefinitionKeyword($array_key)
Expand Down

0 comments on commit 19f053d

Please sign in to comment.