Skip to content

Commit

Permalink
Add support for set = ? for parser
Browse files Browse the repository at this point in the history
Fixes: #492
  • Loading branch information
BackEndTea committed Aug 17, 2023
1 parent d70e65d commit 13938da
Show file tree
Hide file tree
Showing 5 changed files with 472 additions and 12 deletions.
30 changes: 19 additions & 11 deletions src/Components/SetOperation.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,19 +111,27 @@ public static function parse(Parser $parser, TokensList $list, array $options =
$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) {
$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');
$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

0 comments on commit 13938da

Please sign in to comment.