From 21aa474269373c93fa8d74e72e7e8ee817a38cee Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Mon, 29 Jan 2024 22:07:54 +0100 Subject: [PATCH] Fix configured rule (#5517) --- src/Config/RectorConfig.php | 2 +- src/Configuration/RectorConfigBuilder.php | 15 +++++++++------ 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/Config/RectorConfig.php b/src/Config/RectorConfig.php index 70e1348bf21..fd4b915c62f 100644 --- a/src/Config/RectorConfig.php +++ b/src/Config/RectorConfig.php @@ -169,7 +169,7 @@ public function phpstanConfigs(array $filePaths): void } /** - * @param class-string $rectorClass + * @param class-string $rectorClass * @param mixed[] $configuration */ public function ruleWithConfiguration(string $rectorClass, array $configuration): void diff --git a/src/Configuration/RectorConfigBuilder.php b/src/Configuration/RectorConfigBuilder.php index 998422cb893..0ccbecca0a7 100644 --- a/src/Configuration/RectorConfigBuilder.php +++ b/src/Configuration/RectorConfigBuilder.php @@ -6,6 +6,7 @@ use Rector\Caching\Contract\ValueObject\Storage\CacheStorageInterface; use Rector\Config\RectorConfig; +use Rector\Contract\Rector\ConfigurableRectorInterface; use Rector\Contract\Rector\RectorInterface; use Rector\Doctrine\Set\DoctrineSetList; use Rector\PHPUnit\Set\PHPUnitSetList; @@ -43,9 +44,9 @@ final class RectorConfigBuilder private array $rules = []; /** - * @var array, mixed[]> + * @var array, mixed[]> */ - private array $rulesWithConfiguration = []; + private array $rulesWithConfigurations = []; /** * @var string[] @@ -115,8 +116,10 @@ public function __invoke(RectorConfig $rectorConfig): void $rectorConfig->skip($this->skip); $rectorConfig->rules($this->rules); - foreach ($this->rulesWithConfiguration as $ruleWithConfiguration) { - $rectorConfig->ruleWithConfiguration($ruleWithConfiguration[0], $ruleWithConfiguration[1]); + foreach ($this->rulesWithConfigurations as $rectorClass => $configurations) { + foreach ($configurations as $configuration) { + $rectorConfig->ruleWithConfiguration($rectorClass, $configuration); + } } if ($this->fileExtensions !== []) { @@ -365,12 +368,12 @@ public function withCache( } /** - * @param class-string<(RectorInterface)> $rectorClass + * @param class-string $rectorClass * @param mixed[] $configuration */ public function withConfiguredRule(string $rectorClass, array $configuration): self { - $this->rulesWithConfiguration[$rectorClass] = $configuration; + $this->rulesWithConfigurations[$rectorClass][] = $configuration; return $this; }