Skip to content
Merged
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
43 changes: 40 additions & 3 deletions src/DependencyInjection/LazyContainerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,21 @@ public function create(): RectorConfig

$rectorConfig->import(__DIR__ . '/../../config/config.php');

$this->registerConsole($rectorConfig);
$this->registerFileProcessing($rectorConfig);
$this->registerCachingAndResettables($rectorConfig);
$this->registerTypeMappers($rectorConfig);
$this->registerNodeNameResolvers($rectorConfig);
$this->registerRectorAutowiring($rectorConfig);
$this->registerTaggedServices($rectorConfig);
$this->registerAnnotationToAttributeSetters($rectorConfig);
$this->registerNodeVisitorsAndPhpDoc($rectorConfig);

return $rectorConfig;
}

private function registerConsole(RectorConfig $rectorConfig): void
{
$rectorConfig->singleton(Application::class, static function (Container $container): Application {
$consoleApplication = $container->make(ConsoleApplication::class);

Expand Down Expand Up @@ -432,11 +447,14 @@ public function create(): RectorConfig
$rectorConfig->when(DeprecatedRulesReporter::class)
->needs('$rectors')
->giveTagged(RectorInterface::class);
}

private function registerFileProcessing(RectorConfig $rectorConfig): void
{
$rectorConfig->singleton(FileProcessor::class);
$rectorConfig->singleton(PostFileProcessor::class);

// shared state: collects used skips across skipper voters and the file processor
// shared state: collects used skips across the skipper, the path skipper and the file processor
$rectorConfig->singleton(UsedSkipCollector::class);

$rectorConfig->when(RectorNodeTraverser::class)
Expand All @@ -458,7 +476,10 @@ static function (Container $container): DynamicSourceLocatorProvider {
return $phpStanServicesFactory->createDynamicSourceLocatorProvider();
}
);
}

private function registerCachingAndResettables(RectorConfig $rectorConfig): void
{
// resettable
// DynamicSourceLocatorProvider is autotagged on its singleton() call above,
// as RectorConfig autotags ResettableInterface
Expand All @@ -474,7 +495,10 @@ static function (Container $container): DynamicSourceLocatorProvider {
$rectorConfig->when(FileHashComputer::class)
->needs('$cacheMetaExtensions')
->giveTagged(CacheMetaExtensionInterface::class);
}

private function registerTypeMappers(RectorConfig $rectorConfig): void
{
// tagged services
$rectorConfig->when(BetterPhpDocParser::class)
->needs('$phpDocNodeDecorators')
Expand Down Expand Up @@ -529,7 +553,10 @@ static function (UnionTypeMapper $unionTypeMapper, Container $container): void {
$rectorConfig->when(NodeTypeResolver::class)
->needs('$nodeTypeResolvers')
->giveTagged(NodeTypeResolverInterface::class);
}

private function registerNodeNameResolvers(RectorConfig $rectorConfig): void
{
// node name resolvers
$rectorConfig->when(NodeNameResolver::class)
->needs('$nodeNameResolvers')
Expand All @@ -544,7 +571,10 @@ static function (UnionTypeMapper $unionTypeMapper, Container $container): void {
self::CONVERTER_ATTRIBUTE_DECORATOR_CLASSES,
ConverterAttributeDecoratorInterface::class
);
}

private function registerRectorAutowiring(RectorConfig $rectorConfig): void
{
$rectorConfig->afterResolving(
AbstractRector::class,
static function (AbstractRector $rector, Container $container): void {
Expand Down Expand Up @@ -580,7 +610,10 @@ static function (AbstractRector $rector, Container $container): void {
self::BASE_PHP_DOC_NODE_VISITORS,
BasePhpDocNodeVisitorInterface::class
);
}

private function registerTaggedServices(RectorConfig $rectorConfig): void
{
// PHP 8.0 attributes
$this->registerTagged(
$rectorConfig,
Expand Down Expand Up @@ -616,7 +649,10 @@ static function (Container $container): SymfonyStyle {
$rectorConfig->when(OutputFormatterCollector::class)
->needs('$outputFormatters')
->giveTagged(OutputFormatterInterface::class);
}

private function registerAnnotationToAttributeSetters(RectorConfig $rectorConfig): void
{
// required-like setter
$rectorConfig->afterResolving(
ArrayAnnotationToAttributeMapper::class,
Expand Down Expand Up @@ -671,7 +707,10 @@ static function (
$doctrineAnnotationAnnotationToAttributeMapper->autowire($annotationToAttributeMapper);
}
);
}

private function registerNodeVisitorsAndPhpDoc(RectorConfig $rectorConfig): void
{
$rectorConfig->when(PHPStanNodeScopeResolver::class)
->needs('$decoratingNodeVisitors')
->giveTagged(DecoratingNodeVisitorInterface::class);
Expand All @@ -697,8 +736,6 @@ static function (
'comments' => true,
])
);

return $rectorConfig;
}

/**
Expand Down
Loading