From 1dbfd30aa3fb7908b4cd7194565d0c6e625278d1 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Thu, 12 Dec 2024 21:38:48 +0700 Subject: [PATCH] fix --- .../Fixture/fixture.php.inc | 9 ++++---- .../Fixture/new.php.inc | 5 ++++- ...adeTrailingCommasInFunctionCallsRector.php | 6 +++-- .../DowngradeHeredoc/Fixture/fixture.php.inc | 22 ++++++++++++++----- 4 files changed, 29 insertions(+), 13 deletions(-) diff --git a/rules-tests/DowngradePhp73/Rector/FuncCall/DowngradeTrailingCommasInFunctionCallsRector/Fixture/fixture.php.inc b/rules-tests/DowngradePhp73/Rector/FuncCall/DowngradeTrailingCommasInFunctionCallsRector/Fixture/fixture.php.inc index 801aaf49..85cef5f4 100644 --- a/rules-tests/DowngradePhp73/Rector/FuncCall/DowngradeTrailingCommasInFunctionCallsRector/Fixture/fixture.php.inc +++ b/rules-tests/DowngradePhp73/Rector/FuncCall/DowngradeTrailingCommasInFunctionCallsRector/Fixture/fixture.php.inc @@ -26,12 +26,13 @@ class Fixture { public function run() { - compact('posts', 'units'); - $this->setData('posts', 'units'); + compact('posts','units'); + $this->setData('posts','units'); - self::run('posts', 'units'); + self::run('posts','units'); - self::run('posts', 'units'); + self::run('posts', + 'units'); } } diff --git a/rules-tests/DowngradePhp73/Rector/FuncCall/DowngradeTrailingCommasInFunctionCallsRector/Fixture/new.php.inc b/rules-tests/DowngradePhp73/Rector/FuncCall/DowngradeTrailingCommasInFunctionCallsRector/Fixture/new.php.inc index 9209e6b0..30fd356d 100644 --- a/rules-tests/DowngradePhp73/Rector/FuncCall/DowngradeTrailingCommasInFunctionCallsRector/Fixture/new.php.inc +++ b/rules-tests/DowngradePhp73/Rector/FuncCall/DowngradeTrailingCommasInFunctionCallsRector/Fixture/new.php.inc @@ -22,7 +22,10 @@ class Foo { public function doFoo() { - new self('foo', 'bar'); + new self( + 'foo', + 'bar' + ); } } ?> diff --git a/rules/DowngradePhp73/Rector/FuncCall/DowngradeTrailingCommasInFunctionCallsRector.php b/rules/DowngradePhp73/Rector/FuncCall/DowngradeTrailingCommasInFunctionCallsRector.php index 0b09978e..ea05f9fa 100644 --- a/rules/DowngradePhp73/Rector/FuncCall/DowngradeTrailingCommasInFunctionCallsRector.php +++ b/rules/DowngradePhp73/Rector/FuncCall/DowngradeTrailingCommasInFunctionCallsRector.php @@ -90,8 +90,10 @@ public function refactor(Node $node): ?Node return null; } - // remove comma - $node->setAttribute(AttributeKey::ORIGINAL_NODE, null); + $tokens = $this->file->getOldTokens(); + if (isset($tokens[$args[$lastArgKey]->getEndTokenPos() + 1]) && $tokens[$args[$lastArgKey]->getEndTokenPos() + 1]->text === ',') { + $tokens[$args[$lastArgKey]->getEndTokenPos() + 1]->text = ''; + } return $node; } diff --git a/tests/Issues/DowngradeHeredoc/Fixture/fixture.php.inc b/tests/Issues/DowngradeHeredoc/Fixture/fixture.php.inc index 4ee39bda..0c1fdb69 100644 --- a/tests/Issues/DowngradeHeredoc/Fixture/fixture.php.inc +++ b/tests/Issues/DowngradeHeredoc/Fixture/fixture.php.inc @@ -63,8 +63,11 @@ class Fixture { public function getDefinition(): FixerDefinitionInterface { - return new FixerDefinition('Sorts attributes using the configured sort algorithm.', [ - new VersionSpecificCodeSample(<<<'EOL' + return new FixerDefinition( + 'Sorts attributes using the configured sort algorithm.', + [ + new VersionSpecificCodeSample( + <<<'EOL' self::ORDER_CUSTOM, 'order' => ['A\B\Qux', 'A\B\Bar', 'A\B\Corge']]), - ]); +, + new VersionSpecification(80000), + ['sort_algorithm' => self::ORDER_CUSTOM, 'order' => ['A\B\Qux', 'A\B\Bar', 'A\B\Corge']] + ), + ] + ); } }