From b7b3d6a8b14f6f57b05fb8daf9f70015550c0052 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mr=20Alexandre=20ELIS=C3=89?= Date: Fri, 5 Aug 2022 04:40:54 -0400 Subject: [PATCH] Update rector-migrate.php to support latest Rector (#372) --- generator/src/FileCreator.php | 15 +++++++-------- generator/tests/rector/composer.json | 4 ++-- rector-migrate.php | 13 +++++-------- 3 files changed, 14 insertions(+), 18 deletions(-) diff --git a/generator/src/FileCreator.php b/generator/src/FileCreator.php index 3fedf965..8b2b32a4 100644 --- a/generator/src/FileCreator.php +++ b/generator/src/FileCreator.php @@ -2,6 +2,8 @@ namespace Safe; +use Rector\Config\RectorConfig; +use Rector\Renaming\Rector\FuncCall\RenameFunctionRector; use function array_merge; use function file_exists; @@ -101,16 +103,13 @@ public function generateRectorFile(array $functions, string $path): void declare(strict_types=1); +use Rector\Config\RectorConfig; use Rector\Renaming\Rector\FuncCall\RenameFunctionRector; -use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator; // This file configures rector/rector to replace all PHP functions with their equivalent "safe" functions. -return static function (ContainerConfigurator $containerConfigurator): void { - $services = $containerConfigurator->services(); - - $services->set(RenameFunctionRector::class) - ->call('configure', [[ RenameFunctionRector::OLD_FUNCTION_TO_NEW_FUNCTION => [ - +return static function (RectorConfig $rectorConfig): void { + $rectorConfig->ruleWithConfiguration( + RenameFunctionRector::class,[ TXT; fwrite($stream, $header); @@ -119,7 +118,7 @@ public function generateRectorFile(array $functions, string $path): void fwrite($stream, " '$functionName' => 'Safe\\$functionName',\n"); } - fwrite($stream, " ]]]);\n};\n"); + fwrite($stream, " ]);\n};\n"); fclose($stream); } diff --git a/generator/tests/rector/composer.json b/generator/tests/rector/composer.json index 8791ccce..8376ad3c 100644 --- a/generator/tests/rector/composer.json +++ b/generator/tests/rector/composer.json @@ -6,7 +6,7 @@ }, "require": { "php": "^8.0", - "rector/rector": "^0.11.36" + "rector/rector": "^0.13.10" }, "require-dev": { "phpunit/phpunit": "^9.5" @@ -15,4 +15,4 @@ "rector": "rector process src/ --config ../../../rector-migrate.php", "test": "phpunit" } -} \ No newline at end of file +} diff --git a/rector-migrate.php b/rector-migrate.php index db420d4c..fd38eb91 100644 --- a/rector-migrate.php +++ b/rector-migrate.php @@ -2,16 +2,13 @@ declare(strict_types=1); +use Rector\Config\RectorConfig; use Rector\Renaming\Rector\FuncCall\RenameFunctionRector; -use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator; // This file configures rector/rector to replace all PHP functions with their equivalent "safe" functions. -return static function (ContainerConfigurator $containerConfigurator): void { - $services = $containerConfigurator->services(); - - $services->set(RenameFunctionRector::class) - ->call('configure', [[ RenameFunctionRector::OLD_FUNCTION_TO_NEW_FUNCTION => [ - 'apache_getenv' => 'Safe\apache_getenv', +return static function (RectorConfig $rectorConfig): void { + $rectorConfig->ruleWithConfiguration( + RenameFunctionRector::class,[ 'apache_getenv' => 'Safe\apache_getenv', 'apache_get_version' => 'Safe\apache_get_version', 'apache_lookup_uri' => 'Safe\apache_lookup_uri', 'apache_request_headers' => 'Safe\apache_request_headers', @@ -1101,5 +1098,5 @@ 'zip_entry_open' => 'Safe\zip_entry_open', 'zip_entry_read' => 'Safe\zip_entry_read', 'zlib_decode' => 'Safe\zlib_decode', - ]]]); + ]); };