mirror of https://github.com/rectorphp/rector.git
[Core] Refactor init command to use LevelSetList::UP_TO_PHP_XY set list (#1328)
Co-authored-by: GitHub Action <action@github.com>
This commit is contained in:
parent
39a530c1f5
commit
00dd0eb4ca
|
@ -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');
|
||||
}
|
||||
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Reference in New Issue