@@ -88,6 +88,11 @@ final class RectorConfigBuilder
8888 */
8989 private array $ rulesWithConfigurations = [];
9090
91+ /**
92+ * @var array<array{class-string<ConfigurableRectorInterface>, mixed[], string, string}>
93+ */
94+ private array $ composerBasedRules = [];
95+
9196 /**
9297 * @var string[]
9398 */
@@ -262,6 +267,15 @@ public function __invoke(RectorConfig $rectorConfig): void
262267 }
263268 }
264269
270+ foreach ($ this ->composerBasedRules as [$ rectorClass , $ configuration , $ packageName , $ versionConstraint ]) {
271+ $ rectorConfig ->ruleWithConfigurationComposerVersionBound (
272+ $ rectorClass ,
273+ $ configuration ,
274+ $ packageName ,
275+ $ versionConstraint
276+ );
277+ }
278+
265279 if ($ this ->fileExtensions !== []) {
266280 $ rectorConfig ->fileExtensions ($ this ->fileExtensions );
267281 }
@@ -763,6 +777,24 @@ public function withConfiguredRule(string $rectorClass, array $configuration): s
763777 return $ this ;
764778 }
765779
780+ /**
781+ * Register the rule configuration only if the package version installed in the analysed project
782+ * satisfies the version constraint, e.g. a class renamed in a specific framework version.
783+ *
784+ * @param class-string<ConfigurableRectorInterface> $rectorClass
785+ * @param mixed[] $configuration
786+ */
787+ public function withComposerBasedRule (
788+ string $ rectorClass ,
789+ array $ configuration ,
790+ string $ packageName ,
791+ string $ versionConstraint
792+ ): self {
793+ $ this ->composerBasedRules [] = [$ rectorClass , $ configuration , $ packageName , $ versionConstraint ];
794+
795+ return $ this ;
796+ }
797+
766798 public function withParallel (
767799 ?int $ timeoutSeconds = null ,
768800 ?int $ maxNumberOfProcess = null ,
0 commit comments