diff --git a/.github/workflows/code_analysis.yaml b/.github/workflows/code_analysis.yaml index 28e08422582..1a4d31c2326 100644 --- a/.github/workflows/code_analysis.yaml +++ b/.github/workflows/code_analysis.yaml @@ -69,7 +69,9 @@ jobs: - name: 'Detect unused dependencies' # "default" format overrides default "github" in CI - run: vendor/bin/composer-unused --ansi --output-format=default + run: | + composer require icanhazstring/composer-unused --dev + vendor/bin/composer-unused --ansi --output-format=default name: ${{ matrix.actions.name }} runs-on: ubuntu-latest diff --git a/composer.json b/composer.json index 44ece7d98a8..b4b5f73564a 100644 --- a/composer.json +++ b/composer.json @@ -34,10 +34,7 @@ "rector/rector-phpunit": "dev-main", "rector/rector-symfony": "dev-main", "sebastian/diff": "^5.0", - "symfony/config": "^6.2", "symfony/console": "^6.3", - "symfony/contracts": "^3.2", - "symfony/dependency-injection": "6.1.*", "symfony/finder": "^6.3", "symfony/process": "^6.3", "symplify/easy-parallel": "^11.1", @@ -46,7 +43,6 @@ }, "require-dev": { "cweagans/composer-patches": "^1.7.2", - "icanhazstring/composer-unused": "^0.8.5", "nategood/httpful": "^0.3.2", "phpstan/extension-installer": "^1.3", "phpstan/phpstan-deprecation-rules": "^1.1", diff --git a/src/Configuration/ConfigInitializer.php b/src/Configuration/ConfigInitializer.php index d1c64c785fc..7c5b8104134 100644 --- a/src/Configuration/ConfigInitializer.php +++ b/src/Configuration/ConfigInitializer.php @@ -11,27 +11,18 @@ use Rector\Core\Php\PhpVersionProvider; use Rector\PostRector\Contract\Rector\PostRectorInterface; use Symfony\Component\Console\Style\SymfonyStyle; -use Symfony\Component\DependencyInjection\Argument\RewindableGenerator; final class ConfigInitializer { /** - * @var RectorInterface[] - */ - private array $rectors = []; - - /** - * @param RewindableGenerator|RectorInterface[] $rectors + * @param RectorInterface[] $rectors */ public function __construct( - iterable $rectors, + private readonly array $rectors, private readonly InitFilePathsResolver $initFilePathsResolver, private readonly SymfonyStyle $symfonyStyle, private readonly PhpVersionProvider $phpVersionProvider, ) { - $this->rectors = $rectors instanceof RewindableGenerator ? iterator_to_array( - $rectors->getIterator() - ) : $rectors; } public function createConfig(string $projectDirectory): void diff --git a/src/Configuration/Parameter/SimpleParameterProvider.php b/src/Configuration/Parameter/SimpleParameterProvider.php index 0b216b13134..43f5c708297 100644 --- a/src/Configuration/Parameter/SimpleParameterProvider.php +++ b/src/Configuration/Parameter/SimpleParameterProvider.php @@ -5,7 +5,7 @@ namespace Rector\Core\Configuration\Parameter; use Rector\Core\Configuration\Option; -use Symfony\Component\DependencyInjection\Exception\ParameterNotFoundException; +use Rector\Core\Exception\ShouldNotHappenException; use Webmozart\Assert\Assert; /** @@ -113,6 +113,6 @@ private static function ensureParameterIsSet(string $name): void return; } - throw new ParameterNotFoundException($name); + throw new ShouldNotHappenException(sprintf('Parameter "%s" was not found', $name)); } } diff --git a/src/Console/Command/ListRulesCommand.php b/src/Console/Command/ListRulesCommand.php index b90918e2f62..344a85eccd8 100644 --- a/src/Console/Command/ListRulesCommand.php +++ b/src/Console/Command/ListRulesCommand.php @@ -15,30 +15,18 @@ use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Style\SymfonyStyle; -use Symfony\Component\DependencyInjection\Argument\RewindableGenerator; final class ListRulesCommand extends Command { /** - * @var RectorInterface[] - */ - private array $rectors = []; - - /** - * @param RewindableGenerator|RectorInterface[] $rectors + * @param RectorInterface[] $rectors */ public function __construct( private readonly SymfonyStyle $symfonyStyle, private readonly SkippedClassResolver $skippedClassResolver, - iterable $rectors + private readonly array $rectors ) { parent::__construct(); - - if ($rectors instanceof RewindableGenerator) { - $rectors = iterator_to_array($rectors->getIterator()); - } - - $this->rectors = $rectors; } protected function configure(): void diff --git a/src/DependencyInjection/CompilerPass/RemoveSkippedRectorsCompilerPass.php b/src/DependencyInjection/CompilerPass/RemoveSkippedRectorsCompilerPass.php deleted file mode 100644 index 106109d8145..00000000000 --- a/src/DependencyInjection/CompilerPass/RemoveSkippedRectorsCompilerPass.php +++ /dev/null @@ -1,54 +0,0 @@ -resolveSkippedRectorClasses(); - - foreach ($containerBuilder->getDefinitions() as $id => $definition) { - if ($definition->getClass() === null) { - continue; - } - - if (! in_array($definition->getClass(), $skippedRectorClasses, true)) { - continue; - } - - $containerBuilder->removeDefinition($id); - } - } - - /** - * @return string[] - */ - private function resolveSkippedRectorClasses(): array - { - $skipParameters = SimpleParameterProvider::provideArrayParameter(Option::SKIP); - - return array_filter($skipParameters, fn ($element): bool => $this->isRectorClass($element)); - } - - private function isRectorClass(mixed $element): bool - { - if (! is_string($element)) { - return false; - } - - return is_a($element, RectorInterface::class, true); - } -} diff --git a/src/PhpParser/NodeTraverser/RectorNodeTraverser.php b/src/PhpParser/NodeTraverser/RectorNodeTraverser.php index 511c9d6b880..a069df0ee37 100644 --- a/src/PhpParser/NodeTraverser/RectorNodeTraverser.php +++ b/src/PhpParser/NodeTraverser/RectorNodeTraverser.php @@ -8,25 +8,18 @@ use PhpParser\NodeTraverser; use Rector\Core\Contract\Rector\PhpRectorInterface; use Rector\VersionBonding\PhpVersionedFilter; -use Symfony\Component\DependencyInjection\Argument\RewindableGenerator; final class RectorNodeTraverser extends NodeTraverser { private bool $areNodeVisitorsPrepared = false; /** - * @var PhpRectorInterface[] - */ - private array $phpRectors = []; - - /** - * @param RewindableGenerator|PhpRectorInterface[] $phpRectors + * @param PhpRectorInterface[] $phpRectors */ public function __construct( - iterable $phpRectors, + private array $phpRectors, private readonly PhpVersionedFilter $phpVersionedFilter ) { - $this->phpRectors = is_array($phpRectors) ? $phpRectors : iterator_to_array($phpRectors); parent::__construct(); }