From 7bbe9ba2af41fbb64a2817cd44d19665aa79f186 Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Fri, 27 Dec 2024 16:37:19 +0100 Subject: [PATCH] [DX] Warn about ->withPhpSets() called multiple times, to avoid invalid set mix (#6632) * [DX] Warn about ->withPhpSets() called multiple times, to avoid invalid set mix * [ci-review] Rector Rectify --------- Co-authored-by: GitHub Action --- src/Configuration/RectorConfigBuilder.php | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/Configuration/RectorConfigBuilder.php b/src/Configuration/RectorConfigBuilder.php index 5d96678a1f..8dff9de935 100644 --- a/src/Configuration/RectorConfigBuilder.php +++ b/src/Configuration/RectorConfigBuilder.php @@ -158,9 +158,6 @@ final class RectorConfigBuilder private ?string $editorUrl = null; - /** - * @api soon to be used - */ private ?bool $isWithPhpSetsUsed = null; private ?bool $isWithPhpLevelUsed = null; @@ -533,6 +530,14 @@ public function withPhpSets( bool $php53 = false, bool $php84 = false, // place on later as BC break when used in php 7.x without named arg ): self { + if ($this->isWithPhpSetsUsed === true) { + throw new InvalidConfigurationException(sprintf( + 'Method "%s()" can be called only once. It always includes all previous sets UP TO the defined version.%sThe best practise is to call it once with no argument. That way it will pick up PHP version from composer.json and your project will always stay up to date.', + __METHOD__, + PHP_EOL + )); + } + $this->isWithPhpSetsUsed = true; $pickedArguments = array_filter(func_get_args());