Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for set = ? for parser #499

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 19 additions & 11 deletions src/Components/SetOperation.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
*/
$commaLastSeenAt = null;

for (; $list->idx < $list->count; ++$list->idx) {

Check warning on line 80 in src/Components/SetOperation.php

View workflow job for this annotation

GitHub Actions / Mutation tests with PHP 8.1

Escaped Mutant for Mutator "LessThan": --- Original +++ New @@ @@ * @var Token */ $commaLastSeenAt = null; - for (; $list->idx < $list->count; ++$list->idx) { + for (; $list->idx <= $list->count; ++$list->idx) { /** * Token parsed at this moment. */
/**
* Token parsed at this moment.
*/
Expand Down Expand Up @@ -111,19 +111,27 @@
$commaLastSeenAt = $token;
}
} elseif ($state === 1) {
$tmp = Expression::parse(
$parser,
$list,
['breakOnAlias' => true]
);
if ($tmp === null) {
$parser->error('Missing expression.', $token);
break;
if ($token->flags & Token::FLAG_SYMBOL_PARAMETER) {
williamdes marked this conversation as resolved.
Show resolved Hide resolved
$expr->column = trim($expr->column);

Check warning on line 115 in src/Components/SetOperation.php

View workflow job for this annotation

GitHub Actions / Mutation tests with PHP 8.1

Escaped Mutant for Mutator "UnwrapTrim": --- Original +++ New @@ @@ } } elseif ($state === 1) { if ($token->flags & Token::FLAG_SYMBOL_PARAMETER) { - $expr->column = trim($expr->column); + $expr->column = $expr->column; $expr->value = $token->value; $ret[] = $expr; } else {
$expr->value = $token->value;

Check failure on line 116 in src/Components/SetOperation.php

View workflow job for this annotation

GitHub Actions / analyse-php (8.1)

Property PhpMyAdmin\SqlParser\Components\SetOperation::$value (string) does not accept mixed.

Check failure on line 116 in src/Components/SetOperation.php

View workflow job for this annotation

GitHub Actions / analyse-php (8.1)

MixedAssignment

src/Components/SetOperation.php:116:21: MixedAssignment: Unable to determine the type that $expr->value is being assigned to (see https://psalm.dev/032)
$ret[] = $expr;
} else {
$tmp = Expression::parse(
$parser,
$list,
['breakOnAlias' => true]

Check warning on line 122 in src/Components/SetOperation.php

View workflow job for this annotation

GitHub Actions / Mutation tests with PHP 8.1

Escaped Mutant for Mutator "TrueValue": --- Original +++ New @@ @@ $expr->value = $token->value; $ret[] = $expr; } else { - $tmp = Expression::parse($parser, $list, ['breakOnAlias' => true]); + $tmp = Expression::parse($parser, $list, ['breakOnAlias' => false]); if ($tmp === null) { $parser->error('Missing expression.', $token); break;

Check warning on line 122 in src/Components/SetOperation.php

View workflow job for this annotation

GitHub Actions / Mutation tests with PHP 8.1

Escaped Mutant for Mutator "ArrayItemRemoval": --- Original +++ New @@ @@ $expr->value = $token->value; $ret[] = $expr; } else { - $tmp = Expression::parse($parser, $list, ['breakOnAlias' => true]); + $tmp = Expression::parse($parser, $list, []); if ($tmp === null) { $parser->error('Missing expression.', $token); break;
);

if ($tmp === null) {
$parser->error('Missing expression.', $token);
break;
}

$expr->column = trim($expr->column);

Check warning on line 130 in src/Components/SetOperation.php

View workflow job for this annotation

GitHub Actions / Mutation tests with PHP 8.1

Escaped Mutant for Mutator "UnwrapTrim": --- Original +++ New @@ @@ $parser->error('Missing expression.', $token); break; } - $expr->column = trim($expr->column); + $expr->column = $expr->column; $expr->value = $tmp->expr; $ret[] = $expr; }
$expr->value = $tmp->expr;
$ret[] = $expr;
}

$expr->column = trim($expr->column);
$expr->value = $tmp->expr;
$ret[] = $expr;
$expr = new static();
$state = 0;
$commaLastSeenAt = null;
Expand Down
1 change: 1 addition & 0 deletions tests/Parser/UpdateStatementTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public static function updateProvider(): array
['parser/parseUpdate5'],
['parser/parseUpdate6'],
['parser/parseUpdate7'],
['parser/parseUpdate8'],
['parser/parseUpdateErr'],
];
}
Expand Down
2 changes: 1 addition & 1 deletion tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public function getErrorsAsArray($obj): array
*/
public function getData(string $name): array
{
$serializedData = file_get_contents('tests/data/' . $name . '.out');
$serializedData = file_get_contents(__DIR__ . '/data/' . $name . '.out');
williamdes marked this conversation as resolved.
Show resolved Hide resolved
$this->assertIsString($serializedData);

$serializer = new CustomJsonSerializer();
Expand Down
11 changes: 11 additions & 0 deletions tests/data/parser/parseUpdate8.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
UPDATE
users
SET
username = ?,
id=155;

UPDATE
users
SET
username = :user_name,
id=155;
Loading
Loading