Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions src/Configuration/Option.php
Original file line number Diff line number Diff line change
Expand Up @@ -276,12 +276,6 @@ final class Option
*/
public const string TREAT_CLASSES_AS_FINAL = 'treat_classes_as_final';

/**
* @internal To report composer based loaded sets
* @see \Rector\Configuration\RectorConfigBuilder::withComposerBased()
*/
public const string COMPOSER_BASED_SETS = 'composer_based_sets';

/**
* @internal To report rule configuration bound to an installed package version
* @see \Rector\Config\RectorConfig::ruleWithConfigurationComposerVersionBound()
Expand Down
64 changes: 6 additions & 58 deletions src/Configuration/RectorConfigBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,8 @@

use Deprecated;
use PhpParser\NodeVisitor;
use Rector\Bridge\SetProviderCollector;
use Rector\Bridge\SetRectorsResolver;
use Rector\Caching\Contract\ValueObject\Storage\CacheStorageInterface;
use Rector\Composer\InstalledPackageResolver;
use Rector\Config\Level\CodeQualityLevel;
use Rector\Config\Level\CodingStyleLevel;
use Rector\Config\Level\DeadCodeLevel;
Expand All @@ -26,9 +24,7 @@
use Rector\Exception\Configuration\InvalidConfigurationException;
use Rector\Php\PhpVersionResolver\ComposerJsonPhpVersionResolver;
use Rector\PHPUnit\Set\PHPUnitSetList;
use Rector\Set\Contract\SetProviderInterface;
use Rector\Set\Enum\SetGroup;
use Rector\Set\SetManager;
use Rector\Set\ValueObject\DowngradeLevelSetList;
use Rector\Set\ValueObject\SetList;
use Rector\Symfony\Set\SymfonyInternalSetList;
Expand Down Expand Up @@ -175,20 +171,10 @@ final class RectorConfigBuilder
*/
private array $registerServices = [];

/**
* @var array<SetGroup::*>
*/
private array $setGroups = [];

private ?bool $reportingRealPath = null;

private ?bool $reportUnusedSkips = null;

/**
* @var string[]
*/
private array $groupLoadedSets = [];

private ?string $editorUrl = null;

private ?bool $isWithPhpSetsUsed = null;
Expand All @@ -197,31 +183,13 @@ final class RectorConfigBuilder

private ?int $pickedPhpSetsVersion = null;

/**
* @var array<class-string<SetProviderInterface>,bool>
*/
private array $setProviders = [];

/**
* @var LevelOverflow[]
*/
private array $levelOverflows = [];

public function __invoke(RectorConfig $rectorConfig): void
{
if ($this->setGroups !== [] || $this->setProviders !== []) {
$setProviderCollector = new SetProviderCollector(array_map(
$rectorConfig->make(...),
\array_keys($this->setProviders)
));

$setManager = new SetManager($setProviderCollector, new InstalledPackageResolver(getcwd()));

$this->groupLoadedSets = $setManager->matchBySetGroups($this->setGroups);

SimpleParameterProvider::addParameter(Option::COMPOSER_BASED_SETS, $this->groupLoadedSets);
}

// not to miss it by accident
if ($this->isWithPhpSetsUsed === true) {
$this->sets[] = SetList::PHP_POLYFILLS;
Expand All @@ -234,9 +202,6 @@ public function __invoke(RectorConfig $rectorConfig): void
);
}

// merge sets together
$this->sets = array_merge($this->sets, $this->groupLoadedSets);

$uniqueSets = array_unique($this->sets);

if ($this->isWithPhpLevelUsed && $this->isWithPhpSetsUsed) {
Expand Down Expand Up @@ -745,12 +710,7 @@ public function withComposerBased(

// single set, as every rule inside is bound to the installed package version on its own
$this->sets[] = $setFilePath;
continue;
}

// @deprecated fallback for extensions that still describe their sets as objects,
// instead of bonding the rules themselves
$this->setGroups[] = $setGroup;
}

if ($phpunit) {
Expand Down Expand Up @@ -1188,26 +1148,14 @@ public function withEditorUrl(string $editorUrl): self
}

/**
* @param class-string<SetProviderInterface> ...$setProviders
* @deprecated Set providers are now loaded internally. Use withComposerBased() instead.
*/
public function withSetProviders(string ...$setProviders): self
public function withSetProviders(): self
{
foreach ($setProviders as $setProvider) {
if (\array_key_exists($setProvider, $this->setProviders)) {
continue;
}

if (! is_a($setProvider, SetProviderInterface::class, true)) {
throw new InvalidConfigurationException(sprintf(
'Set provider "%s" must implement "%s"',
$setProvider,
SetProviderInterface::class
));
}

$this->setProviders[$setProvider] = true;
}

trigger_error(
'The withSetProviders() method is deprecated and no longer applied. Set providers are now loaded internally - use "withComposerBased()" instead.',
E_USER_DEPRECATED
);
return $this;
}

Expand Down
21 changes: 0 additions & 21 deletions src/Console/Command/ProcessCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
use Rector\Configuration\ConfigurationFactory;
use Rector\Configuration\ConfigurationRuleFilter;
use Rector\Configuration\Option;
use Rector\Configuration\Parameter\SimpleParameterProvider;
use Rector\Console\ExitCode;
use Rector\Console\Output\OutputFormatterCollector;
use Rector\Console\ProcessConfigureDecorator;
Expand Down Expand Up @@ -163,11 +162,6 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$this->additionalAutoloader->autoloadPaths();
}

// show debug info
if ($configuration->isDebug()) {
$this->reportLoadedComposerBasedSets();
}

// MAIN PHASE
// 2. run Rector
$processResult = $this->applicationFileProcessor->run($configuration, $input);
Expand Down Expand Up @@ -247,21 +241,6 @@ private function resolveReturnCode(ProcessResult $processResult, Configuration $
return ExitCode::SUCCESS;
}

private function reportLoadedComposerBasedSets(): void
{
if (! SimpleParameterProvider::hasParameter(Option::COMPOSER_BASED_SETS)) {
return;
}

$composerBasedSets = SimpleParameterProvider::provideArrayParameter(Option::COMPOSER_BASED_SETS);
if ($composerBasedSets === []) {
return;
}

$this->symfonyStyle->writeln('[info] Sets loaded based on installed packages:');
$this->symfonyStyle->listing($composerBasedSets);
}

private function reportLevelOverflow(LevelOverflow $levelOverflow): void
{
$suggestedSetMethod = PHP_VERSION_ID >= 80000 ? sprintf(
Expand Down
66 changes: 0 additions & 66 deletions src/Set/SetManager.php

This file was deleted.

7 changes: 3 additions & 4 deletions tests/Configuration/ExtensionComposerBasedSetTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ public function testEverySetGroupToggleHasASetListMapped(): void
}

/**
* The extension packages are not required by rector-src, so their constant is undefined here and the
* deprecated set group has to keep working.
* The extension packages are not required by rector-src, so their constant is undefined here and
* nothing is loaded for the toggle.
*/
public function testFallsBackToTheSetGroupWhenTheExtensionIsNotInstalled(): void
public function testLoadsNothingWhenTheExtensionIsNotInstalled(): void
{
foreach ($this->provideExtensionComposerBasedSetLists() as $setListConstant) {
$this->assertFalse(defined($setListConstant), $setListConstant);
Expand All @@ -40,7 +40,6 @@ public function testFallsBackToTheSetGroupWhenTheExtensionIsNotInstalled(): void
$rectorConfigBuilder = new RectorConfigBuilder()
->withComposerBased(laravel: true, drupal: true);

$this->assertSame([SetGroup::LARAVEL, SetGroup::DRUPAL], $this->readPrivateArray($rectorConfigBuilder, 'setGroups'));
$this->assertSame([], $this->readPrivateArray($rectorConfigBuilder, 'sets'));
}

Expand Down
Loading