diff --git a/config/set/php82.php b/config/set/php82.php index 3e98729fad9..17aadb33746 100644 --- a/config/set/php82.php +++ b/config/set/php82.php @@ -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]); }; diff --git a/docs/rector_rules_overview.md b/docs/rector_rules_overview.md index 8a8e689ad53..a39279ad1d8 100644 --- a/docs/rector_rules_overview.md +++ b/docs/rector_rules_overview.md @@ -1,4 +1,4 @@ -# 368 Rules Overview +# 369 Rules Overview
@@ -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
+### 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}"; +``` + +
+ ## Php83 ### AddOverrideAttributeToOverriddenMethodsRector diff --git a/rules/Php82/Rector/Encapsed/VariableInStringInterpolationFixerRector.php b/rules/Php82/Rector/Encapsed/VariableInStringInterpolationFixerRector.php new file mode 100644 index 00000000000..f8b66aacebe --- /dev/null +++ b/rules/Php82/Rector/Encapsed/VariableInStringInterpolationFixerRector.php @@ -0,0 +1,74 @@ +> + */ + 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; + } +} diff --git a/src/Application/VersionResolver.php b/src/Application/VersionResolver.php index 5ce8a0b84ee..853d446ab55 100644 --- a/src/Application/VersionResolver.php +++ b/src/Application/VersionResolver.php @@ -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 */ diff --git a/src/ValueObject/PhpVersionFeature.php b/src/ValueObject/PhpVersionFeature.php index 3dd931e19a4..b36db8ae381 100644 --- a/src/ValueObject/PhpVersionFeature.php +++ b/src/ValueObject/PhpVersionFeature.php @@ -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 diff --git a/vendor/composer/autoload_classmap.php b/vendor/composer/autoload_classmap.php index 34fea42f977..d43a2cd1593 100644 --- a/vendor/composer/autoload_classmap.php +++ b/vendor/composer/autoload_classmap.php @@ -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', diff --git a/vendor/composer/autoload_static.php b/vendor/composer/autoload_static.php index 12272f3d79c..debae55e353 100644 --- a/vendor/composer/autoload_static.php +++ b/vendor/composer/autoload_static.php @@ -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',