{"record":{"id":"8a568d2dc5b45ba9","repo":"rectorphp/rector","slug":"pick-only-one-version-target-in-withphpsets-a","errorCode":null,"errorMessage":"Pick only one version target in \"withPhpSets()\". All rules up to this version will be used.%sTo use your composer.json PHP version, keep arguments empty.","messagePattern":"Pick only one version target in \"withPhpSets\\(\\)\"\\. All rules up to this version will be used\\.(.+?)To use your composer\\.json PHP version, keep arguments empty\\.","errorType":"exception","errorClass":"InvalidConfigurationException","httpStatus":null,"severity":"error","filePath":"src/Configuration/RectorConfigBuilder.php","lineNumber":417,"sourceCode":"        bool $php55 = \\false,\n        bool $php54 = \\false,\n        bool $php53 = \\false,\n        // place on later as BC break when used in php 7.x without named arg\n        bool $php84 = \\false,\n        bool $php85 = \\false,\n        bool $php86 = \\false\n    ): self\n    {\n        if ($this->isWithPhpSetsUsed === \\true) {\n            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));\n        }\n        $this->isWithPhpSetsUsed = \\true;\n        $pickedPhpVersions = array_keys(array_filter([PhpVersion::PHP_53 => $php53, PhpVersion::PHP_54 => $php54, PhpVersion::PHP_55 => $php55, PhpVersion::PHP_56 => $php56, PhpVersion::PHP_70 => $php70, PhpVersion::PHP_71 => $php71, PhpVersion::PHP_72 => $php72, PhpVersion::PHP_73 => $php73, PhpVersion::PHP_74 => $php74, PhpVersion::PHP_80 => $php80, PhpVersion::PHP_81 => $php81, PhpVersion::PHP_82 => $php82, PhpVersion::PHP_83 => $php83, PhpVersion::PHP_84 => $php84, PhpVersion::PHP_85 => $php85, PhpVersion::PHP_86 => $php86]));\n        if ($pickedPhpVersions !== []) {\n            Notifier::errorWithPhpSetsNotSuitableForPHP74AndLower();\n        }\n        if (count($pickedPhpVersions) > 1) {\n            throw new InvalidConfigurationException(sprintf('Pick only one version target in \"withPhpSets()\". All rules up to this version will be used.%sTo use your composer.json PHP version, keep arguments empty.', \\PHP_EOL));\n        }\n        // no version picked, resolve it from the project composer.json\n        if ($pickedPhpVersions === []) {\n            return $this->addPhpLevelSets(ComposerJsonPhpVersionResolver::resolveFromCwdOrFail());\n        }\n        // explicitly picked version is a ceiling, even for polyfilled rules\n        $this->pickedPhpSetsVersion = $pickedPhpVersions[0];\n        return $this->addPhpLevelSets($pickedPhpVersions[0]);\n    }\n    public function withPhp53Sets(): self\n    {\n        return $this->reportDeprecatedPhpSetsMethod(__FUNCTION__);\n    }\n    public function withPhp54Sets(): self\n    {\n        return $this->reportDeprecatedPhpSetsMethod(__FUNCTION__);\n    }\n    public function withPhp55Sets(): self","sourceCodeStart":399,"sourceCodeEnd":435,"githubUrl":"https://github.com/rectorphp/rector/blob/408fcb0ff1833e3d26cbc9b04c23a77565814a16/src/Configuration/RectorConfigBuilder.php#L399-L435","documentation":"withPhpSets() accepts one boolean per PHP version (php53..php86); passing more than one true flag is contradictory because the method means 'everything up to this version'. RectorConfigBuilder collects the true flags via array_filter and throws InvalidConfigurationException when count > 1. To target the composer.json version, pass no flags at all.","triggerScenarios":"Calling ->withPhpSets(php82: true, php83: true), or adding a new version flag while forgetting to remove the old one; also older snippets using positional booleans (php74: true) combined with newer flags.","commonSituations":"Incremental upgrades where a developer adds the next version instead of replacing the previous flag; copy-pasted examples with different targets merged.","solutions":["Keep only the highest target flag: ->withPhpSets(php83: true)","Better: call ->withPhpSets() with no arguments and let composer.json's php requirement define the ceiling","Note the flags are cumulative by design -- you never need two to chain versions"],"exampleFix":"// before\nreturn RectorConfig::configure()\n    ->withPhpSets(php82: true, php83: true);\n\n// after\nreturn RectorConfig::configure()\n    ->withPhpSets(php83: true);  // includes everything up to 8.3","handlingStrategy":"validation","validationCode":"// lint: exactly zero or one version flag in withPhpSets\nif (preg_match('/withPhpSets\\(([^)]*)\\)/', $configSrc, $m)\n    && preg_match_all('/php\\d+:\\s*true|(?<!:)\\btrue\\b/', $m[1], $flags) > 1\n) {\n    fwrite(STDERR, \"withPhpSets() got multiple version flags; keep only the highest\\n\");\n}","typeGuard":null,"tryCatchPattern":"catch \\Rector\\Exception\\Configuration\\InvalidConfigurationException; on the 'Pick only one version target' message, keep the single highest flag and re-run.","preventionTips":["Flags are cumulative: one call with the target version includes all lower sets","Default to the argument-less form so composer.json drives the ceiling","When bumping PHP versions, replace the old flag rather than appending"],"tags":["php","rector","config","php-version","conflicting-arguments"],"backgroundTag":"conflicting-config-options","analyzedSha":"408fcb0ff1833e3d26cbc9b04c23a77565814a16","analyzedAt":"2026-08-21T05:11:02.643Z","schemaVersion":2},"datasetVersion":"2026-08-21T11:28:35.574Z"}