Skip to content

Commit

Permalink
[DX] Make command default autotag (#5441)
Browse files Browse the repository at this point in the history
  • Loading branch information
TomasVotruba authored Jan 7, 2024
1 parent c9608a0 commit 2f5a252
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 16 deletions.
19 changes: 6 additions & 13 deletions src/Config/RectorConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use Rector\Validation\RectorConfigValidator;
use Rector\ValueObject\PhpVersion;
use Rector\ValueObject\PolyfillPackage;
use Symfony\Component\Console\Command\Command;
use Webmozart\Assert\Assert;

/**
Expand All @@ -26,14 +27,14 @@
final class RectorConfig extends Container
{
/**
* @var array<class-string<RectorInterface>, mixed[]>>
* @var string[]
*/
private array $ruleConfigurations = [];
private const AUTOTAG_INTERFACES = [Command::class];

/**
* @var string[]
* @var array<class-string<RectorInterface>, mixed[]>>
*/
private array $autotagInterfaces = [];
private array $ruleConfigurations = [];

/**
* @param string[] $paths
Expand Down Expand Up @@ -379,22 +380,14 @@ public function disableCollectors(): void
SimpleParameterProvider::setParameter(Option::COLLECTORS, false);
}

/**
* @internal Use to add tag on service registrations
*/
public function autotagInterface(string $interface): void
{
$this->autotagInterfaces[] = $interface;
}

/**
* @param string $abstract
*/
public function singleton($abstract, mixed $concrete = null): void
{
parent::singleton($abstract, $concrete);

foreach ($this->autotagInterfaces as $autotagInterface) {
foreach (self::AUTOTAG_INTERFACES as $autotagInterface) {
if (! is_a($abstract, $autotagInterface, true)) {
continue;
}
Expand Down
2 changes: 0 additions & 2 deletions src/DependencyInjection/LazyContainerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -406,8 +406,6 @@ public function create(): RectorConfig
return $inflectorFactory->build();
});

$rectorConfig->autotagInterface(Command::class);

$rectorConfig->singleton(ProcessCommand::class);
$rectorConfig->singleton(WorkerCommand::class);
$rectorConfig->singleton(SetupCICommand::class);
Expand Down
2 changes: 1 addition & 1 deletion src/Testing/PHPUnit/AbstractRectorTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ private function includePreloadFilesAndScoperAutoload(): void
if (file_exists(__DIR__ . '/../../../preload.php')) {
if (file_exists(__DIR__ . '/../../../vendor')) {
require_once __DIR__ . '/../../../preload.php';
// test case in rector split package
// test case in rector split package
} elseif (file_exists(__DIR__ . '/../../../../../../vendor')) {
require_once __DIR__ . '/../../../preload-split-package.php';
}
Expand Down

0 comments on commit 2f5a252

Please sign in to comment.