Skip to content

Commit

Permalink
config method must be static, to avoid creating rule before loading r…
Browse files Browse the repository at this point in the history
…elated ctor services (#5606)
  • Loading branch information
TomasVotruba committed Feb 12, 2024
1 parent 62ba916 commit 6c7dbaa
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 15 deletions.
28 changes: 15 additions & 13 deletions src/Config/RectorConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,21 @@ public function rule(string $rectorClass): void

// for cache invalidation in case of change
SimpleParameterProvider::addParameter(Option::REGISTERED_RECTOR_RULES, $rectorClass);

// for cache invalidation in case of change
SimpleParameterProvider::addParameter(Option::REGISTERED_RECTOR_RULES, $rectorClass);

if (is_a($rectorClass, RelatedConfigInterface::class, true)) {
$configFile = $rectorClass::getConfigFile();

Assert::file($configFile, sprintf(
'The config path "%s" in "%s::getConfigFile()" could not be found',
$configFile,
$rectorClass
));

$this->import($configFile);
}
}

/**
Expand Down Expand Up @@ -252,19 +267,6 @@ public function rules(array $rectorClasses): void

foreach ($rectorClasses as $rectorClass) {
$this->rule($rectorClass);

if (is_a($rectorClass, RelatedConfigInterface::class, true)) {
/** @var RelatedConfigInterface $rector */
$rector = $this->make($rectorClass);

Assert::file($rector->getConfigFile(), sprintf(
'The config path "%s" in "%s::getConfigFile()" could not be found',
$rector->getConfigFile(),
$rector::class
));

$this->import($rector->getConfigFile());
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@
*/
interface RelatedConfigInterface
{
public function getConfigFile(): string;
public static function getConfigFile(): string;
}
2 changes: 1 addition & 1 deletion src/PostRector/Rector/UnusedImportRemovingPostRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ private function findNamesInDocBlocks(Namespace_|FileWithoutNamespace $namespace
return null;
}

$docs = array_filter($comments, static fn(Comment $comment): bool => $comment instanceof Doc);
$docs = array_filter($comments, static fn (Comment $comment): bool => $comment instanceof Doc);
if ($docs === []) {
return null;
}
Expand Down

0 comments on commit 6c7dbaa

Please sign in to comment.