Skip to content

Commit 5e14d8b

Browse files
authored
[CodingStyle] Deprecate WrapEncapsedVariableInCurlyBracesRector (#8272)
1 parent b17019f commit 5e14d8b

10 files changed

Lines changed: 8 additions & 170 deletions

File tree

‎rules-tests/CodingStyle/Rector/Encapsed/WrapEncapsedVariableInCurlyBracesRector/Fixture/fixture.php.inc‎

Lines changed: 0 additions & 11 deletions
This file was deleted.

‎rules-tests/CodingStyle/Rector/Encapsed/WrapEncapsedVariableInCurlyBracesRector/Fixture/multiple_variables.php.inc‎

Lines changed: 0 additions & 21 deletions
This file was deleted.

‎rules-tests/CodingStyle/Rector/Encapsed/WrapEncapsedVariableInCurlyBracesRector/Fixture/skip_braces_already_present.php.inc‎

Lines changed: 0 additions & 8 deletions
This file was deleted.

‎rules-tests/CodingStyle/Rector/Encapsed/WrapEncapsedVariableInCurlyBracesRector/Fixture/skip_single_quotes.php.inc‎

Lines changed: 0 additions & 8 deletions
This file was deleted.

‎rules-tests/CodingStyle/Rector/Encapsed/WrapEncapsedVariableInCurlyBracesRector/Fixture/some_variables_with_braces.php.inc‎

Lines changed: 0 additions & 21 deletions
This file was deleted.

‎rules-tests/CodingStyle/Rector/Encapsed/WrapEncapsedVariableInCurlyBracesRector/Fixture/with_middle_variable.php.inc‎

Lines changed: 0 additions & 35 deletions
This file was deleted.

‎rules-tests/CodingStyle/Rector/Encapsed/WrapEncapsedVariableInCurlyBracesRector/WrapEncapsedVariableInCurlyBracesRectorTest.php‎

Lines changed: 0 additions & 28 deletions
This file was deleted.

‎rules-tests/CodingStyle/Rector/Encapsed/WrapEncapsedVariableInCurlyBracesRector/config/configured_rule.php‎

Lines changed: 0 additions & 9 deletions
This file was deleted.

‎rules/CodingStyle/Rector/Encapsed/WrapEncapsedVariableInCurlyBracesRector.php‎

Lines changed: 8 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,17 @@
55
namespace Rector\CodingStyle\Rector\Encapsed;
66

77
use PhpParser\Node;
8-
use PhpParser\Node\Expr\Variable;
98
use PhpParser\Node\Scalar\InterpolatedString;
10-
use PhpParser\Token;
9+
use Rector\Configuration\Deprecation\Contract\DeprecatedInterface;
10+
use Rector\Exception\ShouldNotHappenException;
1111
use Rector\Rector\AbstractRector;
1212
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
1313
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
1414

1515
/**
16-
* @see \Rector\Tests\CodingStyle\Rector\Encapsed\WrapEncapsedVariableInCurlyBracesRector\WrapEncapsedVariableInCurlyBracesRectorTest
16+
* @deprecated This rule is deprecated, as it is a coding standard preference with no real value. Use a coding standard tool instead.
1717
*/
18-
final class WrapEncapsedVariableInCurlyBracesRector extends AbstractRector
18+
final class WrapEncapsedVariableInCurlyBracesRector extends AbstractRector implements DeprecatedInterface
1919
{
2020
public function getRuleDefinition(): RuleDefinition
2121
{
@@ -51,28 +51,9 @@ public function getNodeTypes(): array
5151
*/
5252
public function refactor(Node $node): ?Node
5353
{
54-
$hasVariableBeenWrapped = false;
55-
$oldTokens = $this->getFile()
56-
->getOldTokens();
57-
58-
foreach ($node->parts as $index => $nodePart) {
59-
if ($nodePart instanceof Variable && $nodePart->getStartTokenPos() >= 0) {
60-
$start = $oldTokens[$nodePart->getStartTokenPos() - 1] ?? null;
61-
$end = $oldTokens[$nodePart->getEndTokenPos() + 1] ?? null;
62-
63-
if ($start instanceof Token && $end instanceof Token && $start->text === '{' && $end->text === '}') {
64-
continue;
65-
}
66-
67-
$hasVariableBeenWrapped = true;
68-
$node->parts[$index] = new Variable($nodePart->name);
69-
}
70-
}
71-
72-
if (! $hasVariableBeenWrapped) {
73-
return null;
74-
}
75-
76-
return $node;
54+
throw new ShouldNotHappenException(sprintf(
55+
'"%s" rule is deprecated, as it is a coding standard preference with no real value',
56+
self::class
57+
));
7758
}
7859
}

‎src/Config/Level/CodingStyleLevel.php‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
use Rector\CodingStyle\Rector\ClassMethod\FuncGetArgsToVariadicParamRector;
1212
use Rector\CodingStyle\Rector\ClassMethod\MakeInheritedMethodVisibilitySameAsParentRector;
1313
use Rector\CodingStyle\Rector\ClassMethod\NewlineBeforeNewAssignSetRector;
14-
use Rector\CodingStyle\Rector\Encapsed\WrapEncapsedVariableInCurlyBracesRector;
1514
use Rector\CodingStyle\Rector\FuncCall\CallUserFuncArrayToVariadicRector;
1615
use Rector\CodingStyle\Rector\FuncCall\CallUserFuncToMethodCallRector;
1716
use Rector\CodingStyle\Rector\FuncCall\ConsistentImplodeRector;
@@ -57,7 +56,6 @@ final class CodingStyleLevel
5756
StringClassNameToClassConstantRector::class,
5857
CatchExceptionNameMatchingTypeRector::class,
5958
SplitDoubleAssignRector::class,
60-
WrapEncapsedVariableInCurlyBracesRector::class,
6159
NewlineBeforeNewAssignSetRector::class,
6260
MakeInheritedMethodVisibilitySameAsParentRector::class,
6361
CallUserFuncArrayToVariadicRector::class,

0 commit comments

Comments
 (0)