diff --git a/rules/DowngradePhp73/Rector/FuncCall/DowngradeTrailingCommasInFunctionCallsRector.php b/rules/DowngradePhp73/Rector/FuncCall/DowngradeTrailingCommasInFunctionCallsRector.php index 6ddf5253..6bd30df4 100644 --- a/rules/DowngradePhp73/Rector/FuncCall/DowngradeTrailingCommasInFunctionCallsRector.php +++ b/rules/DowngradePhp73/Rector/FuncCall/DowngradeTrailingCommasInFunctionCallsRector.php @@ -11,6 +11,7 @@ use PhpParser\Node\Expr\StaticCall; use Rector\DowngradePhp73\Tokenizer\FollowedByCommaAnalyzer; use Rector\DowngradePhp73\Tokenizer\TrailingCommaRemover; +use Rector\NodeTypeResolver\Node\AttributeKey; use Rector\Rector\AbstractRector; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; @@ -84,6 +85,16 @@ public function refactor(Node $node): ?Node return null; } + // reprint is needed as position changed that can't rely on token position + // @see https://github.com/rectorphp/rector-downgrade-php/pull/281 + // @see https://github.com/rectorphp/rector-downgrade-php/pull/285 + foreach ($args as $arg) { + if ($arg->getEndTokenPos() < 0) { + $node->setAttribute(AttributeKey::ORIGINAL_NODE, null); + return $node; + } + } + $lastArgKey = count($args) - 1; $lastArg = $args[$lastArgKey]; diff --git a/tests/Issues/DowngradeNamedTrailing/Fixture/fixture.php.inc b/tests/Issues/DowngradeNamedTrailing/Fixture/fixture.php.inc index 7783f706..d8d38c04 100644 --- a/tests/Issues/DowngradeNamedTrailing/Fixture/fixture.php.inc +++ b/tests/Issues/DowngradeNamedTrailing/Fixture/fixture.php.inc @@ -44,10 +44,6 @@ class Fixture } } -$contents = new Fixture( - $content->getType(), - ['error' => $e->getMessage()], - $content->getId() -); +$contents = new Fixture($content->getType(), ['error' => $e->getMessage()], $content->getId()); ?> diff --git a/tests/Set/Fixture/named_argument_trailing_comma.php.inc b/tests/Set/Fixture/named_argument_trailing_comma.php.inc new file mode 100644 index 00000000..8efb66cc --- /dev/null +++ b/tests/Set/Fixture/named_argument_trailing_comma.php.inc @@ -0,0 +1,43 @@ +run( + foo: 'foo', + bar: 'bar', + ); + + $this->run( + bar: 'bar', + foo: 'foo', + ); + } +} + +?> +----- +run('foo', 'bar'); + + $this->run('foo', 'bar'); + } +} + +?>