Updated Rector to commit aa706a152c2cb0ece154edab3bc89bad8c2f7208

aa706a152c [Php82] Add VariableInStringInterpolationFixerRector (#5781)
This commit is contained in:
Tomas Votruba 2024-03-29 21:39:12 +00:00
parent 42078c4127
commit f2feb272ed
7 changed files with 101 additions and 5 deletions

View File

@ -7,6 +7,7 @@ use Rector\Config\RectorConfig;
use Rector\Php82\Rector\Class_\ReadOnlyClassRector;
use Rector\Php82\Rector\FuncCall\Utf8DecodeEncodeToMbConvertEncodingRector;
use Rector\Php82\Rector\New_\FilesystemIteratorSkipDotsRector;
use Rector\Php82\Rector\Encapsed\VariableInStringInterpolationFixerRector;
return static function (RectorConfig $rectorConfig) : void {
$rectorConfig->rules([ReadOnlyClassRector::class, Utf8DecodeEncodeToMbConvertEncodingRector::class, FilesystemIteratorSkipDotsRector::class]);
$rectorConfig->rules([ReadOnlyClassRector::class, Utf8DecodeEncodeToMbConvertEncodingRector::class, FilesystemIteratorSkipDotsRector::class, VariableInStringInterpolationFixerRector::class]);
};

View File

@ -1,4 +1,4 @@
# 368 Rules Overview
# 369 Rules Overview
<br>
@ -42,7 +42,7 @@
- [Php81](#php81) (9)
- [Php82](#php82) (4)
- [Php82](#php82) (5)
- [Php83](#php83) (3)
@ -5323,6 +5323,20 @@ Change deprecated utf8_decode and utf8_encode to mb_convert_encoding
<br>
### VariableInStringInterpolationFixerRector
Replace deprecated "${var}" to "{$var}"
- class: [`Rector\Php82\Rector\Encapsed\VariableInStringInterpolationFixerRector`](../rules/Php82/Rector/Encapsed/VariableInStringInterpolationFixerRector.php)
```diff
$c = "football";
-echo "I like playing ${c}";
+echo "I like playing {$c}";
```
<br>
## Php83
### AddOverrideAttributeToOverriddenMethodsRector

View File

@ -0,0 +1,74 @@
<?php
declare (strict_types=1);
namespace Rector\Php82\Rector\Encapsed;
use PhpParser\Node;
use PhpParser\Node\Expr\Variable;
use PhpParser\Node\Scalar\Encapsed;
use Rector\NodeTypeResolver\Node\AttributeKey;
use Rector\Rector\AbstractRector;
use Rector\ValueObject\PhpVersionFeature;
use Rector\VersionBonding\Contract\MinPhpVersionInterface;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
/**
* @changelog https://wiki.php.net/rfc/deprecate_dollar_brace_string_interpolation
*
* @see \Rector\Tests\Php82\Rector\Encapsed\VariableInStringInterpolationFixerRector\VariableInStringInterpolationFixerRectorTest
*/
final class VariableInStringInterpolationFixerRector extends AbstractRector implements MinPhpVersionInterface
{
public function getRuleDefinition() : RuleDefinition
{
return new RuleDefinition('Replace deprecated "${var}" to "{$var}"', [new CodeSample(<<<'CODE_SAMPLE'
$c = "football";
echo "I like playing ${c}";
CODE_SAMPLE
, <<<'CODE_SAMPLE'
$c = "football";
echo "I like playing {$c}";
CODE_SAMPLE
)]);
}
/**
* @return array<class-string<Node>>
*/
public function getNodeTypes() : array
{
return [Encapsed::class];
}
/**
* @param Encapsed $node
*/
public function refactor(Node $node) : ?Node
{
$oldTokens = $this->file->getOldTokens();
$hasChanged = \false;
foreach ($node->parts as $part) {
if (!$part instanceof Variable) {
continue;
}
$startTokenPos = $part->getStartTokenPos();
if (!isset($oldTokens[$startTokenPos])) {
continue;
}
if (!\is_array($oldTokens[$startTokenPos])) {
continue;
}
if ($oldTokens[$startTokenPos][1] !== '${') {
continue;
}
$part->setAttribute(AttributeKey::ORIGINAL_NODE, null);
$hasChanged = \true;
}
if (!$hasChanged) {
return null;
}
return $node;
}
public function provideMinPhpVersion() : int
{
return PhpVersionFeature::DEPRECATE_VARIABLE_IN_STRING_INTERPOLATION;
}
}

View File

@ -19,12 +19,12 @@ final class VersionResolver
* @api
* @var string
*/
public const PACKAGE_VERSION = '08d73a1af5ebc77bf37e9854fc1aca76cd5fcbcb';
public const PACKAGE_VERSION = 'aa706a152c2cb0ece154edab3bc89bad8c2f7208';
/**
* @api
* @var string
*/
public const RELEASE_DATE = '2024-03-28 17:03:10';
public const RELEASE_DATE = '2024-03-29 22:36:43';
/**
* @var int
*/

View File

@ -522,6 +522,11 @@ final class PhpVersionFeature
* @var int
*/
public const SENSITIVE_PARAMETER_ATTRIBUTE = \Rector\ValueObject\PhpVersion::PHP_82;
/**
* @see https://wiki.php.net/rfc/deprecate_dollar_brace_string_interpolation
* @var int
*/
public const DEPRECATE_VARIABLE_IN_STRING_INTERPOLATION = \Rector\ValueObject\PhpVersion::PHP_82;
/**
* @see https://wiki.php.net/rfc/marking_overriden_methods
* @var int

View File

@ -1927,6 +1927,7 @@ return array(
'Rector\\Php81\\Rector\\MethodCall\\SpatieEnumMethodCallToEnumConstRector' => $baseDir . '/rules/Php81/Rector/MethodCall/SpatieEnumMethodCallToEnumConstRector.php',
'Rector\\Php81\\Rector\\Property\\ReadOnlyPropertyRector' => $baseDir . '/rules/Php81/Rector/Property/ReadOnlyPropertyRector.php',
'Rector\\Php82\\Rector\\Class_\\ReadOnlyClassRector' => $baseDir . '/rules/Php82/Rector/Class_/ReadOnlyClassRector.php',
'Rector\\Php82\\Rector\\Encapsed\\VariableInStringInterpolationFixerRector' => $baseDir . '/rules/Php82/Rector/Encapsed/VariableInStringInterpolationFixerRector.php',
'Rector\\Php82\\Rector\\FuncCall\\Utf8DecodeEncodeToMbConvertEncodingRector' => $baseDir . '/rules/Php82/Rector/FuncCall/Utf8DecodeEncodeToMbConvertEncodingRector.php',
'Rector\\Php82\\Rector\\New_\\FilesystemIteratorSkipDotsRector' => $baseDir . '/rules/Php82/Rector/New_/FilesystemIteratorSkipDotsRector.php',
'Rector\\Php82\\Rector\\Param\\AddSensitiveParameterAttributeRector' => $baseDir . '/rules/Php82/Rector/Param/AddSensitiveParameterAttributeRector.php',

View File

@ -2146,6 +2146,7 @@ class ComposerStaticInit67be42e0079886f0083b7116ae1de531
'Rector\\Php81\\Rector\\MethodCall\\SpatieEnumMethodCallToEnumConstRector' => __DIR__ . '/../..' . '/rules/Php81/Rector/MethodCall/SpatieEnumMethodCallToEnumConstRector.php',
'Rector\\Php81\\Rector\\Property\\ReadOnlyPropertyRector' => __DIR__ . '/../..' . '/rules/Php81/Rector/Property/ReadOnlyPropertyRector.php',
'Rector\\Php82\\Rector\\Class_\\ReadOnlyClassRector' => __DIR__ . '/../..' . '/rules/Php82/Rector/Class_/ReadOnlyClassRector.php',
'Rector\\Php82\\Rector\\Encapsed\\VariableInStringInterpolationFixerRector' => __DIR__ . '/../..' . '/rules/Php82/Rector/Encapsed/VariableInStringInterpolationFixerRector.php',
'Rector\\Php82\\Rector\\FuncCall\\Utf8DecodeEncodeToMbConvertEncodingRector' => __DIR__ . '/../..' . '/rules/Php82/Rector/FuncCall/Utf8DecodeEncodeToMbConvertEncodingRector.php',
'Rector\\Php82\\Rector\\New_\\FilesystemIteratorSkipDotsRector' => __DIR__ . '/../..' . '/rules/Php82/Rector/New_/FilesystemIteratorSkipDotsRector.php',
'Rector\\Php82\\Rector\\Param\\AddSensitiveParameterAttributeRector' => __DIR__ . '/../..' . '/rules/Php82/Rector/Param/AddSensitiveParameterAttributeRector.php',