Skip to content

Commit

Permalink
Update rector-migrate.php to support latest Rector (#372)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mr Alexandre ELISÉ authored Aug 5, 2022
1 parent f531c6a commit b7b3d6a
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 18 deletions.
15 changes: 7 additions & 8 deletions generator/src/FileCreator.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace Safe;

use Rector\Config\RectorConfig;
use Rector\Renaming\Rector\FuncCall\RenameFunctionRector;
use function array_merge;
use function file_exists;

Expand Down Expand Up @@ -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);
Expand All @@ -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);
}

Expand Down
4 changes: 2 additions & 2 deletions generator/tests/rector/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
},
"require": {
"php": "^8.0",
"rector/rector": "^0.11.36"
"rector/rector": "^0.13.10"
},
"require-dev": {
"phpunit/phpunit": "^9.5"
Expand All @@ -15,4 +15,4 @@
"rector": "rector process src/ --config ../../../rector-migrate.php",
"test": "phpunit"
}
}
}
13 changes: 5 additions & 8 deletions rector-migrate.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -1101,5 +1098,5 @@
'zip_entry_open' => 'Safe\zip_entry_open',
'zip_entry_read' => 'Safe\zip_entry_read',
'zlib_decode' => 'Safe\zlib_decode',
]]]);
]);
};

0 comments on commit b7b3d6a

Please # to comment.