Skip to content

Commit bedaffe

Browse files
committed
Fix
1 parent d939a02 commit bedaffe

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

rules/DowngradePhp73/Rector/FuncCall/DowngradeTrailingCommasInFunctionCallsRector.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use PhpParser\Node\Expr\StaticCall;
1212
use Rector\DowngradePhp73\Tokenizer\FollowedByCommaAnalyzer;
1313
use Rector\DowngradePhp73\Tokenizer\TrailingCommaRemover;
14+
use Rector\NodeTypeResolver\Node\AttributeKey;
1415
use Rector\Rector\AbstractRector;
1516
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
1617
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
@@ -84,6 +85,16 @@ public function refactor(Node $node): ?Node
8485
return null;
8586
}
8687

88+
// reprint is needed as position changed that can't rely on token position
89+
// @see https://github.com/rectorphp/rector-downgrade-php/pull/281
90+
// @see https://github.com/rectorphp/rector-downgrade-php/pull/285
91+
foreach ($args as $arg) {
92+
if ($arg->getEndTokenPos() < 0) {
93+
$node->setAttribute(AttributeKey::ORIGINAL_NODE, null);
94+
return $node;
95+
}
96+
}
97+
8798
$lastArgKey = count($args) - 1;
8899

89100
$lastArg = $args[$lastArgKey];

tests/Set/Fixture/named_argument_trailing_comma.php.inc

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,9 @@ final class NamedArgumentTrailingComma
3434

3535
public function execute()
3636
{
37-
$this->run(
38-
'foo',
39-
'bar'
40-
);
37+
$this->run('foo', 'bar');
4138

42-
$this->run(
43-
'foo',
44-
'bar'
45-
);
39+
$this->run('foo', 'bar');
4640
}
4741
}
4842

0 commit comments

Comments
 (0)