From 9b3d2786e76ffeedad88e8413e60f499308d5835 Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Mon, 3 Aug 2026 14:23:16 +0200 Subject: [PATCH] [CodingStyle] Deprecate WrapEncapsedVariableInCurlyBracesRector --- .../Fixture/fixture.php.inc | 11 ------ .../Fixture/multiple_variables.php.inc | 21 ----------- .../skip_braces_already_present.php.inc | 8 ----- .../Fixture/skip_single_quotes.php.inc | 8 ----- .../some_variables_with_braces.php.inc | 21 ----------- .../Fixture/with_middle_variable.php.inc | 35 ------------------- ...ncapsedVariableInCurlyBracesRectorTest.php | 28 --------------- .../config/configured_rule.php | 9 ----- ...rapEncapsedVariableInCurlyBracesRector.php | 35 +++++-------------- src/Config/Level/CodingStyleLevel.php | 2 -- 10 files changed, 8 insertions(+), 170 deletions(-) delete mode 100644 rules-tests/CodingStyle/Rector/Encapsed/WrapEncapsedVariableInCurlyBracesRector/Fixture/fixture.php.inc delete mode 100644 rules-tests/CodingStyle/Rector/Encapsed/WrapEncapsedVariableInCurlyBracesRector/Fixture/multiple_variables.php.inc delete mode 100644 rules-tests/CodingStyle/Rector/Encapsed/WrapEncapsedVariableInCurlyBracesRector/Fixture/skip_braces_already_present.php.inc delete mode 100644 rules-tests/CodingStyle/Rector/Encapsed/WrapEncapsedVariableInCurlyBracesRector/Fixture/skip_single_quotes.php.inc delete mode 100644 rules-tests/CodingStyle/Rector/Encapsed/WrapEncapsedVariableInCurlyBracesRector/Fixture/some_variables_with_braces.php.inc delete mode 100644 rules-tests/CodingStyle/Rector/Encapsed/WrapEncapsedVariableInCurlyBracesRector/Fixture/with_middle_variable.php.inc delete mode 100644 rules-tests/CodingStyle/Rector/Encapsed/WrapEncapsedVariableInCurlyBracesRector/WrapEncapsedVariableInCurlyBracesRectorTest.php delete mode 100644 rules-tests/CodingStyle/Rector/Encapsed/WrapEncapsedVariableInCurlyBracesRector/config/configured_rule.php diff --git a/rules-tests/CodingStyle/Rector/Encapsed/WrapEncapsedVariableInCurlyBracesRector/Fixture/fixture.php.inc b/rules-tests/CodingStyle/Rector/Encapsed/WrapEncapsedVariableInCurlyBracesRector/Fixture/fixture.php.inc deleted file mode 100644 index 47bbd995bd1..00000000000 --- a/rules-tests/CodingStyle/Rector/Encapsed/WrapEncapsedVariableInCurlyBracesRector/Fixture/fixture.php.inc +++ /dev/null @@ -1,11 +0,0 @@ - ------ - diff --git a/rules-tests/CodingStyle/Rector/Encapsed/WrapEncapsedVariableInCurlyBracesRector/Fixture/multiple_variables.php.inc b/rules-tests/CodingStyle/Rector/Encapsed/WrapEncapsedVariableInCurlyBracesRector/Fixture/multiple_variables.php.inc deleted file mode 100644 index e9e99d91ef1..00000000000 --- a/rules-tests/CodingStyle/Rector/Encapsed/WrapEncapsedVariableInCurlyBracesRector/Fixture/multiple_variables.php.inc +++ /dev/null @@ -1,21 +0,0 @@ - ------ - diff --git a/rules-tests/CodingStyle/Rector/Encapsed/WrapEncapsedVariableInCurlyBracesRector/Fixture/skip_braces_already_present.php.inc b/rules-tests/CodingStyle/Rector/Encapsed/WrapEncapsedVariableInCurlyBracesRector/Fixture/skip_braces_already_present.php.inc deleted file mode 100644 index 1ae35b77974..00000000000 --- a/rules-tests/CodingStyle/Rector/Encapsed/WrapEncapsedVariableInCurlyBracesRector/Fixture/skip_braces_already_present.php.inc +++ /dev/null @@ -1,8 +0,0 @@ - ------ - diff --git a/rules-tests/CodingStyle/Rector/Encapsed/WrapEncapsedVariableInCurlyBracesRector/Fixture/with_middle_variable.php.inc b/rules-tests/CodingStyle/Rector/Encapsed/WrapEncapsedVariableInCurlyBracesRector/Fixture/with_middle_variable.php.inc deleted file mode 100644 index 8dba78d37a4..00000000000 --- a/rules-tests/CodingStyle/Rector/Encapsed/WrapEncapsedVariableInCurlyBracesRector/Fixture/with_middle_variable.php.inc +++ /dev/null @@ -1,35 +0,0 @@ - ------ - diff --git a/rules-tests/CodingStyle/Rector/Encapsed/WrapEncapsedVariableInCurlyBracesRector/WrapEncapsedVariableInCurlyBracesRectorTest.php b/rules-tests/CodingStyle/Rector/Encapsed/WrapEncapsedVariableInCurlyBracesRector/WrapEncapsedVariableInCurlyBracesRectorTest.php deleted file mode 100644 index b37724d02f9..00000000000 --- a/rules-tests/CodingStyle/Rector/Encapsed/WrapEncapsedVariableInCurlyBracesRector/WrapEncapsedVariableInCurlyBracesRectorTest.php +++ /dev/null @@ -1,28 +0,0 @@ -doTestFile($filePath); - } - - public static function provideData(): Iterator - { - return self::yieldFilesFromDirectory(__DIR__ . '/Fixture'); - } - - public function provideConfigFilePath(): string - { - return __DIR__ . '/config/configured_rule.php'; - } -} diff --git a/rules-tests/CodingStyle/Rector/Encapsed/WrapEncapsedVariableInCurlyBracesRector/config/configured_rule.php b/rules-tests/CodingStyle/Rector/Encapsed/WrapEncapsedVariableInCurlyBracesRector/config/configured_rule.php deleted file mode 100644 index bb80081d3f4..00000000000 --- a/rules-tests/CodingStyle/Rector/Encapsed/WrapEncapsedVariableInCurlyBracesRector/config/configured_rule.php +++ /dev/null @@ -1,9 +0,0 @@ -withRules([WrapEncapsedVariableInCurlyBracesRector::class]); diff --git a/rules/CodingStyle/Rector/Encapsed/WrapEncapsedVariableInCurlyBracesRector.php b/rules/CodingStyle/Rector/Encapsed/WrapEncapsedVariableInCurlyBracesRector.php index 3d039823d08..38776ab2832 100644 --- a/rules/CodingStyle/Rector/Encapsed/WrapEncapsedVariableInCurlyBracesRector.php +++ b/rules/CodingStyle/Rector/Encapsed/WrapEncapsedVariableInCurlyBracesRector.php @@ -5,17 +5,17 @@ namespace Rector\CodingStyle\Rector\Encapsed; use PhpParser\Node; -use PhpParser\Node\Expr\Variable; use PhpParser\Node\Scalar\InterpolatedString; -use PhpParser\Token; +use Rector\Configuration\Deprecation\Contract\DeprecatedInterface; +use Rector\Exception\ShouldNotHappenException; use Rector\Rector\AbstractRector; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; /** - * @see \Rector\Tests\CodingStyle\Rector\Encapsed\WrapEncapsedVariableInCurlyBracesRector\WrapEncapsedVariableInCurlyBracesRectorTest + * @deprecated This rule is deprecated, as it is a coding standard preference with no real value. Use a coding standard tool instead. */ -final class WrapEncapsedVariableInCurlyBracesRector extends AbstractRector +final class WrapEncapsedVariableInCurlyBracesRector extends AbstractRector implements DeprecatedInterface { public function getRuleDefinition(): RuleDefinition { @@ -51,28 +51,9 @@ public function getNodeTypes(): array */ public function refactor(Node $node): ?Node { - $hasVariableBeenWrapped = false; - $oldTokens = $this->getFile() - ->getOldTokens(); - - foreach ($node->parts as $index => $nodePart) { - if ($nodePart instanceof Variable && $nodePart->getStartTokenPos() >= 0) { - $start = $oldTokens[$nodePart->getStartTokenPos() - 1] ?? null; - $end = $oldTokens[$nodePart->getEndTokenPos() + 1] ?? null; - - if ($start instanceof Token && $end instanceof Token && $start->text === '{' && $end->text === '}') { - continue; - } - - $hasVariableBeenWrapped = true; - $node->parts[$index] = new Variable($nodePart->name); - } - } - - if (! $hasVariableBeenWrapped) { - return null; - } - - return $node; + throw new ShouldNotHappenException(sprintf( + '"%s" rule is deprecated, as it is a coding standard preference with no real value', + self::class + )); } } diff --git a/src/Config/Level/CodingStyleLevel.php b/src/Config/Level/CodingStyleLevel.php index 0957a81f946..787a29c837a 100644 --- a/src/Config/Level/CodingStyleLevel.php +++ b/src/Config/Level/CodingStyleLevel.php @@ -11,7 +11,6 @@ use Rector\CodingStyle\Rector\ClassMethod\FuncGetArgsToVariadicParamRector; use Rector\CodingStyle\Rector\ClassMethod\MakeInheritedMethodVisibilitySameAsParentRector; use Rector\CodingStyle\Rector\ClassMethod\NewlineBeforeNewAssignSetRector; -use Rector\CodingStyle\Rector\Encapsed\WrapEncapsedVariableInCurlyBracesRector; use Rector\CodingStyle\Rector\FuncCall\CallUserFuncArrayToVariadicRector; use Rector\CodingStyle\Rector\FuncCall\CallUserFuncToMethodCallRector; use Rector\CodingStyle\Rector\FuncCall\ConsistentImplodeRector; @@ -57,7 +56,6 @@ final class CodingStyleLevel StringClassNameToClassConstantRector::class, CatchExceptionNameMatchingTypeRector::class, SplitDoubleAssignRector::class, - WrapEncapsedVariableInCurlyBracesRector::class, NewlineBeforeNewAssignSetRector::class, MakeInheritedMethodVisibilitySameAsParentRector::class, CallUserFuncArrayToVariadicRector::class,