diff --git a/composer-unused.php b/composer-unused.php index 5e8cfa98fdd..4cdf584598a 100644 --- a/composer-unused.php +++ b/composer-unused.php @@ -9,7 +9,6 @@ return static function (Configuration $configuration): Configuration { // rector dependencies - $configuration->addPatternFilter(PatternFilter::fromString('#rector/.#')); $configuration->addPatternFilter(PatternFilter::fromString('#phpstan/phpstan#')); return $configuration; diff --git a/rector.php b/rector.php index 9d6a8ac12fc..7be44fabe8c 100644 --- a/rector.php +++ b/rector.php @@ -36,8 +36,7 @@ __DIR__ . '/config', ]) ->withRootFiles() - ->withImportNames() - ->withRemoveUnusedImports() + ->withImportNames(removeUnusedImports: true) ->withSkip([ StringClassNameToClassConstantRector::class, __DIR__ . '/bin/validate-phpstan-version.php', diff --git a/src/Configuration/RectorConfigBuilder.php b/src/Configuration/RectorConfigBuilder.php index cc1f22b0ac3..998422cb893 100644 --- a/src/Configuration/RectorConfigBuilder.php +++ b/src/Configuration/RectorConfigBuilder.php @@ -7,7 +7,13 @@ use Rector\Caching\Contract\ValueObject\Storage\CacheStorageInterface; use Rector\Config\RectorConfig; use Rector\Contract\Rector\RectorInterface; +use Rector\Doctrine\Set\DoctrineSetList; +use Rector\PHPUnit\Set\PHPUnitSetList; use Rector\Set\ValueObject\SetList; +use Rector\Symfony\Set\FOSRestSetList; +use Rector\Symfony\Set\JMSSetList; +use Rector\Symfony\Set\SensiolabsSetList; +use Rector\Symfony\Set\SymfonySetList; use Rector\ValueObject\PhpVersion; use Symfony\Component\Finder\Finder; @@ -92,8 +98,6 @@ final class RectorConfigBuilder private int $indentSize = 4; - private ?string $phpstanConfig = null; - /** * @var string[] */ @@ -160,10 +164,6 @@ public function __invoke(RectorConfig $rectorConfig): void $rectorConfig->indent($this->indentChar, $this->indentSize); } - if ($this->phpstanConfig !== null) { - $rectorConfig->phpstanConfig($this->phpstanConfig); - } - if ($this->phpstanConfigs !== []) { $rectorConfig->phpstanConfigs($this->phpstanConfigs); } @@ -231,6 +231,54 @@ public function withSets(array $sets): self return $this; } + /** + * Upgrade your annotations to attributes + */ + public function withAttributesSets( + bool $symfony = false, + bool $doctrine = false, + bool $mongoDb = false, + bool $gedmo = false, + bool $phpunit = false, + bool $fosRest = false, + bool $jms = false, + bool $sensiolabs = false, + ): self { + if ($symfony) { + $this->sets[] = SymfonySetList::ANNOTATIONS_TO_ATTRIBUTES; + } + + if ($doctrine) { + $this->sets[] = DoctrineSetList::ANNOTATIONS_TO_ATTRIBUTES; + } + + if ($mongoDb) { + $this->sets[] = DoctrineSetList::MONGODB__ANNOTATIONS_TO_ATTRIBUTES; + } + + if ($gedmo) { + $this->sets[] = DoctrineSetList::GEDMO_ANNOTATIONS_TO_ATTRIBUTES; + } + + if ($phpunit) { + $this->sets[] = PHPUnitSetList::ANNOTATIONS_TO_ATTRIBUTES; + } + + if ($fosRest) { + $this->sets[] = FOSRestSetList::ANNOTATIONS_TO_ATTRIBUTES; + } + + if ($jms) { + $this->sets[] = JMSSetList::ANNOTATIONS_TO_ATTRIBUTES; + } + + if ($sensiolabs) { + $this->sets[] = SensiolabsSetList::ANNOTATIONS_TO_ATTRIBUTES; + } + + return $this; + } + public function withPreparedSets( bool $deadCode = false, bool $codeQuality = false, @@ -301,20 +349,17 @@ public function withFileExtensions(array $fileExtensions): self return $this; } - public function withCacheDirectory(string $cacheDirectory, ?string $containerCacheDirectory = null): self - { - $this->cacheDirectory = $cacheDirectory; - $this->containerCacheDirectory = $containerCacheDirectory; - - return $this; - } - /** - * @param class-string $cacheClass + * @param class-string|null $cacheClass */ - public function withClassCache(string $cacheClass): self - { + public function withCache( + ?string $cacheDirectory = null, + ?string $cacheClass = null, + ?string $containerCacheDirectory = null + ): self { + $this->cacheDirectory = $cacheDirectory; $this->cacheClass = $cacheClass; + $this->containerCacheDirectory = $containerCacheDirectory; return $this; } @@ -359,25 +404,16 @@ public function withoutParallel(): self return $this; } - public function withImportNames(bool $importNames = true, bool $importDocBlockNames = true): self - { + public function withImportNames( + bool $importNames = true, + bool $importDocBlockNames = true, + bool $importShortClasses = true, + bool $removeUnusedImports = false + ): 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; } @@ -419,12 +455,6 @@ public function withBootstrapFiles(array $bootstrapFiles): self return $this; } - public function withPHPStanConfig(string $phpstanConfig): self - { - $this->phpstanConfig = $phpstanConfig; - return $this; - } - /** * @param string[] $phpstanConfigs */ diff --git a/templates/custom-rule/utils/rector/src/Rector/__Name__.php b/templates/custom-rule/utils/rector/src/Rector/__Name__.php index fd7c21e7c81..f3b9e64e45e 100644 --- a/templates/custom-rule/utils/rector/src/Rector/__Name__.php +++ b/templates/custom-rule/utils/rector/src/Rector/__Name__.php @@ -10,7 +10,7 @@ use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; /** - * @see \rector\tests\Rector\__Name__\__Name__Test + * @see \Utils\Rector\Tests\Rector\__Name__\__Name__Test */ final class __Name__ extends AbstractRector {