Updated Rector to commit 0afec7e54615912ced1ffe83e9dccadc4f153c17

0afec7e546 [Config] Add RectorConfigBuilder (#5503)
This commit is contained in:
Tomas Votruba 2024-01-26 19:37:08 +00:00
parent 00449e1e5c
commit f076295e84
5 changed files with 351 additions and 2 deletions

View File

@ -19,12 +19,12 @@ final class VersionResolver
* @api
* @var string
*/
public const PACKAGE_VERSION = '35ddfb28bac90271f2317ae394471062c699d419';
public const PACKAGE_VERSION = '0afec7e54615912ced1ffe83e9dccadc4f153c17';
/**
* @api
* @var string
*/
public const RELEASE_DATE = '2024-01-26 15:23:36';
public const RELEASE_DATE = '2024-01-26 20:34:48';
/**
* @var int
*/

View File

@ -7,6 +7,7 @@ use RectorPrefix202401\Illuminate\Container\Container;
use Rector\Caching\Contract\ValueObject\Storage\CacheStorageInterface;
use Rector\Configuration\Option;
use Rector\Configuration\Parameter\SimpleParameterProvider;
use Rector\Configuration\RectorConfigBuilder;
use Rector\Contract\Rector\ConfigurableRectorInterface;
use Rector\Contract\Rector\RectorInterface;
use Rector\DependencyInjection\Laravel\ContainerMemento;
@ -33,6 +34,10 @@ final class RectorConfig extends Container
* @var string[]
*/
private $autotagInterfaces = [Command::class];
public static function configure() : RectorConfigBuilder
{
return new RectorConfigBuilder();
}
/**
* @param string[] $paths
*/

View File

@ -0,0 +1,342 @@
<?php
declare (strict_types=1);
namespace Rector\Configuration;
use Rector\Caching\Contract\ValueObject\Storage\CacheStorageInterface;
use Rector\Config\RectorConfig;
use Rector\Contract\Rector\RectorInterface;
use Rector\ValueObject\PhpVersion;
use RectorPrefix202401\Symfony\Component\Finder\Finder;
/**
* @api
*/
final class RectorConfigBuilder
{
/**
* @var string[]
*/
private $paths = [];
/**
* @var string[]
*/
private $sets = [];
/**
* @var array<mixed>
*/
private $skip = [];
/**
* @var array<class-string<RectorInterface>>
*/
private $rules = [];
/**
* @var array<class-string<RectorInterface>, mixed[]>
*/
private $rulesWithConfiguration = [];
/**
* @var string[]
*/
private $fileExtensions = [];
/**
* @var null|class-string<CacheStorageInterface>
*/
private $cacheClass;
/**
* @var string|null
*/
private $cacheDirectory;
/**
* @var string|null
*/
private $containerCacheDirectory;
/**
* Enabled by default
* @var bool
*/
private $parallel = \true;
/**
* @var int
*/
private $parallelTimeoutSeconds = 120;
/**
* @var int
*/
private $parallelMaxNumberOfProcess = 16;
/**
* @var int
*/
private $parallelJobSize = 16;
/**
* @var bool
*/
private $importNames = \false;
/**
* @var bool
*/
private $importDocBlockNames = \false;
/**
* @var bool
*/
private $importShortClasses = \true;
/**
* @var bool
*/
private $removeUnusedImports = \false;
/**
* @var bool
*/
private $noDiffs = \false;
/**
* @var string|null
*/
private $memoryLimit;
/**
* @var string[]
*/
private $autoloadPaths = [];
/**
* @var string[]
*/
private $bootstrapFiles = [];
/**
* @var string
*/
private $indentChar = ' ';
/**
* @var int
*/
private $indentSize = 4;
/**
* @var string|null
*/
private $phpstanConfig;
/**
* @var string[]
*/
private $phpstanConfigs = [];
/**
* @var null|PhpVersion::*
*/
private $phpVersion;
public function __invoke(RectorConfig $rectorConfig) : void
{
$rectorConfig->sets($this->sets);
$rectorConfig->paths($this->paths);
$rectorConfig->skip($this->skip);
$rectorConfig->rules($this->rules);
foreach ($this->rulesWithConfiguration as $ruleWithConfiguration) {
$rectorConfig->ruleWithConfiguration($ruleWithConfiguration[0], $ruleWithConfiguration[1]);
}
if ($this->fileExtensions !== []) {
$rectorConfig->fileExtensions($this->fileExtensions);
}
if ($this->cacheClass !== null) {
$rectorConfig->cacheClass($this->cacheClass);
}
if ($this->cacheDirectory !== null) {
$rectorConfig->cacheDirectory($this->cacheDirectory);
}
if ($this->containerCacheDirectory !== null) {
$rectorConfig->containerCacheDirectory($this->containerCacheDirectory);
}
if ($this->importNames || $this->importDocBlockNames) {
$rectorConfig->importNames($this->importNames, $this->importDocBlockNames);
$rectorConfig->importShortClasses($this->importShortClasses);
}
if ($this->removeUnusedImports) {
$rectorConfig->removeUnusedImports($this->removeUnusedImports);
}
if ($this->noDiffs) {
$rectorConfig->noDiffs();
}
if ($this->memoryLimit !== null) {
$rectorConfig->memoryLimit($this->memoryLimit);
}
if ($this->autoloadPaths !== []) {
$rectorConfig->autoloadPaths($this->autoloadPaths);
}
if ($this->bootstrapFiles !== []) {
$rectorConfig->bootstrapFiles($this->bootstrapFiles);
}
if ($this->indentChar !== ' ' || $this->indentSize !== 4) {
$rectorConfig->indent($this->indentChar, $this->indentSize);
}
if ($this->phpstanConfig !== null) {
$rectorConfig->phpstanConfig($this->phpstanConfig);
}
if ($this->phpstanConfigs !== []) {
$rectorConfig->phpstanConfigs($this->phpstanConfigs);
}
if ($this->phpVersion !== null) {
$rectorConfig->phpVersion($this->phpVersion);
}
if ($this->parallel) {
$rectorConfig->parallel($this->parallelTimeoutSeconds, $this->parallelMaxNumberOfProcess, $this->parallelJobSize);
} else {
$rectorConfig->disableParallel();
}
}
/**
* @param string[] $paths
*/
public function withPaths(array $paths) : self
{
$this->paths = $paths;
return $this;
}
/**
* @param array<mixed> $skip
*/
public function withSkip(array $skip) : self
{
$this->skip = $skip;
return $this;
}
/**
* Include PHP files from the root directory,
* typically ecs.php, rector.php etc.
*/
public function withRootFiles() : self
{
$rootPhpFilesFinder = (new Finder())->files()->in(\getcwd())->depth(0)->name('*.php');
foreach ($rootPhpFilesFinder as $rootPhpFileFinder) {
$this->paths[] = $rootPhpFileFinder->getRealPath();
}
return $this;
}
/**
* @param string[] $sets
*/
public function withSets(array $sets) : self
{
$this->sets = $sets;
return $this;
}
/**
* @param array<class-string<RectorInterface>> $rules
*/
public function withRules(array $rules) : self
{
$this->rules = $rules;
return $this;
}
/**
* @param string[] $fileExtensions
*/
public function withFileExtensions(array $fileExtensions) : self
{
$this->fileExtensions = $fileExtensions;
return $this;
}
public function withCacheDirectory(string $cacheDirectory, ?string $containerCacheDirectory = null) : self
{
$this->cacheDirectory = $cacheDirectory;
$this->containerCacheDirectory = $containerCacheDirectory;
return $this;
}
/**
* @param class-string<CacheStorageInterface> $cacheClass
*/
public function withClassCache(string $cacheClass) : self
{
$this->cacheClass = $cacheClass;
return $this;
}
/**
* @param class-string<(RectorInterface)> $rectorClass
* @param mixed[] $configuration
*/
public function withConfiguredRule(string $rectorClass, array $configuration) : self
{
$this->rulesWithConfiguration[$rectorClass] = $configuration;
return $this;
}
public function withParallel(?int $timeoutSeconds = null, ?int $maxNumberOfProcess = null, ?int $jobSize = null) : self
{
$this->parallel = \true;
if (\is_int($timeoutSeconds)) {
$this->parallelTimeoutSeconds = $timeoutSeconds;
}
if (\is_int($maxNumberOfProcess)) {
$this->parallelMaxNumberOfProcess = $maxNumberOfProcess;
}
if (\is_int($jobSize)) {
$this->parallelJobSize = $jobSize;
}
return $this;
}
public function withoutParallel() : self
{
$this->parallel = \false;
return $this;
}
public function withImportNames(bool $importNames = \true, bool $importDocBlockNames = \true) : self
{
$this->importNames = $importNames;
$this->importDocBlockNames = $importDocBlockNames;
return $this;
}
public function withImporShortClasses(bool $importShortClasses = \true) : self
{
$this->importShortClasses = $importShortClasses;
return $this;
}
public function withRemoveUnusedImports(bool $removeUnusedImports = \false) : self
{
$this->removeUnusedImports = $removeUnusedImports;
return $this;
}
public function withNoDiffs() : self
{
$this->noDiffs = \true;
return $this;
}
public function withMemoryLimit(string $memoryLimit) : self
{
$this->memoryLimit = $memoryLimit;
return $this;
}
public function withIndent(string $indentChar = ' ', int $indentSize = 4) : self
{
$this->indentChar = $indentChar;
$this->indentSize = $indentSize;
return $this;
}
/**
* @param string[] $autoloadPaths
*/
public function withAutoloadPaths(array $autoloadPaths) : self
{
$this->autoloadPaths = $autoloadPaths;
return $this;
}
/**
* @param string[] $bootstrapFiles
*/
public function withBootstrapFiles(array $bootstrapFiles) : self
{
$this->bootstrapFiles = $bootstrapFiles;
return $this;
}
public function withPHPStanConfig(string $phpstanConfig) : self
{
$this->phpstanConfig = $phpstanConfig;
return $this;
}
/**
* @param string[] $phpstanConfigs
*/
public function withPHPStanConfigs(array $phpstanConfigs) : self
{
$this->phpstanConfigs = $phpstanConfigs;
return $this;
}
/**
* @param PhpVersion::* $phpVersion
*/
public function withPhpVersion(int $phpVersion) : self
{
$this->phpVersion = $phpVersion;
return $this;
}
}

View File

@ -1175,6 +1175,7 @@ return array(
'Rector\\Configuration\\ConfigurationFactory' => $baseDir . '/src/Configuration/ConfigurationFactory.php',
'Rector\\Configuration\\Option' => $baseDir . '/src/Configuration/Option.php',
'Rector\\Configuration\\Parameter\\SimpleParameterProvider' => $baseDir . '/src/Configuration/Parameter/SimpleParameterProvider.php',
'Rector\\Configuration\\RectorConfigBuilder' => $baseDir . '/src/Configuration/RectorConfigBuilder.php',
'Rector\\Configuration\\RenamedClassesDataCollector' => $baseDir . '/src/Configuration/RenamedClassesDataCollector.php',
'Rector\\Console\\Command\\CustomRuleCommand' => $baseDir . '/src/Console/Command/CustomRuleCommand.php',
'Rector\\Console\\Command\\ListRulesCommand' => $baseDir . '/src/Console/Command/ListRulesCommand.php',

View File

@ -1389,6 +1389,7 @@ class ComposerStaticInitf637847380e2ddf55dcae18dded1d2b3
'Rector\\Configuration\\ConfigurationFactory' => __DIR__ . '/../..' . '/src/Configuration/ConfigurationFactory.php',
'Rector\\Configuration\\Option' => __DIR__ . '/../..' . '/src/Configuration/Option.php',
'Rector\\Configuration\\Parameter\\SimpleParameterProvider' => __DIR__ . '/../..' . '/src/Configuration/Parameter/SimpleParameterProvider.php',
'Rector\\Configuration\\RectorConfigBuilder' => __DIR__ . '/../..' . '/src/Configuration/RectorConfigBuilder.php',
'Rector\\Configuration\\RenamedClassesDataCollector' => __DIR__ . '/../..' . '/src/Configuration/RenamedClassesDataCollector.php',
'Rector\\Console\\Command\\CustomRuleCommand' => __DIR__ . '/../..' . '/src/Console/Command/CustomRuleCommand.php',
'Rector\\Console\\Command\\ListRulesCommand' => __DIR__ . '/../..' . '/src/Console/Command/ListRulesCommand.php',