diff --git a/src/Console/Command/InitCommand.php b/src/Console/Command/InitCommand.php index 1ee8173715d..3d0df517b1a 100644 --- a/src/Console/Command/InitCommand.php +++ b/src/Console/Command/InitCommand.php @@ -4,9 +4,11 @@ declare(strict_types=1); namespace Rector\Core\Console\Command; +use Nette\Utils\Strings; use Rector\Core\Configuration\Option; use Rector\Core\Contract\Template\TemplateResolverInterface; use Rector\Core\Exception\Template\TemplateTypeNotFoundException; +use Rector\Core\Php\PhpVersionProvider; use Rector\Core\Template\DefaultResolver; use Stringable; use Symfony\Component\Console\Command\Command; @@ -26,7 +28,8 @@ final class InitCommand extends Command private FileSystemGuard $fileSystemGuard, private SmartFileSystem $smartFileSystem, private SymfonyStyle $symfonyStyle, - private array $templateResolvers + private array $templateResolvers, + private PhpVersionProvider $phpVersionProvider ) { parent::__construct(); } @@ -59,6 +62,18 @@ final class InitCommand extends Command $this->symfonyStyle->warning('Config file "rector.php" already exists'); } else { $this->smartFileSystem->copy($rectorTemplateFilePath, $rectorRootFilePath); + + $fullPHPVersion = (string) $this->phpVersionProvider->provide(); + $phpVersion = Strings::substring($fullPHPVersion, 0, 1) . Strings::substring($fullPHPVersion, 2, 1); + + $fileContent = $this->smartFileSystem->readFile($rectorRootFilePath); + $fileContent = str_replace( + 'LevelSetList::UP_TO_PHP_XY', + sprintf('LevelSetList::UP_TO_PHP_%d', $phpVersion), + $fileContent + ); + $this->smartFileSystem->dumpFile($rectorRootFilePath, $fileContent); + $this->symfonyStyle->success('"rector.php" config file was added'); } diff --git a/templates/rector.php.dist b/templates/rector.php.dist index 75d4d52a8cf..08a29eebb3d 100644 --- a/templates/rector.php.dist +++ b/templates/rector.php.dist @@ -4,7 +4,7 @@ declare(strict_types=1); use Rector\Core\Configuration\Option; use Rector\Php74\Rector\Property\TypedPropertyRector; -use Rector\Set\ValueObject\SetList; +use Rector\Set\ValueObject\LevelSetList; use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator; return static function (ContainerConfigurator $containerConfigurator): void { @@ -15,7 +15,7 @@ return static function (ContainerConfigurator $containerConfigurator): void { ]); // Define what rule sets will be applied - $containerConfigurator->import(SetList::DEAD_CODE); + $containerConfigurator->import(LevelSetList::UP_TO_PHP_XY); // get services (needed for register a single rule) // $services = $containerConfigurator->services();