Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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];
Expand Down
6 changes: 1 addition & 5 deletions tests/Issues/DowngradeNamedTrailing/Fixture/fixture.php.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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());

?>
43 changes: 43 additions & 0 deletions tests/Set/Fixture/named_argument_trailing_comma.php.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

namespace Rector\Tests\Set\Fixture;

final class NamedArgumentTrailingComma
{
public function run(string $foo, string $bar)
{}

public function execute()
{
$this->run(
foo: 'foo',
bar: 'bar',
);

$this->run(
bar: 'bar',
foo: 'foo',
);
}
}

?>
-----
<?php

namespace Rector\Tests\Set\Fixture;

final class NamedArgumentTrailingComma
{
public function run(string $foo, string $bar)
{}

public function execute()
{
$this->run('foo', 'bar');

$this->run('foo', 'bar');
}
}

?>