{"record":{"id":"0f6a717830af11f7","repo":"phar-io/version","slug":"version-constraint-s-is-not-supported","errorCode":null,"errorMessage":"Version constraint %s is not supported.","messagePattern":"Version constraint (.+?) is not supported\\.","errorType":"exception","errorClass":"UnsupportedVersionConstraintException","httpStatus":null,"severity":"error","filePath":"src/VersionConstraintParser.php","lineNumber":22,"sourceCode":" *\n * (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de>\n *\n * For the full copyright and license information, please view the LICENSE\n * file that was distributed with this source code.\n */\nnamespace PharIo\\Version;\n\nclass VersionConstraintParser {\n    /**\n     * @throws UnsupportedVersionConstraintException\n     */\n    public function parse(string $value): VersionConstraint {\n        if (\\strpos($value, '|') !== false) {\n            return $this->handleOrGroup($value);\n        }\n\n        if (!\\preg_match('/^[\\^~*]?v?[\\d.*]+(?:-.*)?$/i', $value)) {\n            throw new UnsupportedVersionConstraintException(\n                \\sprintf('Version constraint %s is not supported.', $value)\n            );\n        }\n\n        switch ($value[0]) {\n            case '~':\n                return $this->handleTildeOperator($value);\n            case '^':\n                return $this->handleCaretOperator($value);\n        }\n\n        $constraint = new VersionConstraintValue($value);\n\n        if ($constraint->getMajor()->isAny()) {\n            return new AnyVersionConstraint();\n        }\n\n        if ($constraint->getMinor()->isAny()) {","sourceCodeStart":4,"sourceCodeEnd":40,"githubUrl":"https://github.com/phar-io/version/blob/5eeb03f1ee82b3076d72daa5cb85d6b68abad783/src/VersionConstraintParser.php#L4-L40","documentation":"UnsupportedVersionConstraintException is thrown by VersionConstraintParser::parse when the constraint string does not match '/^[\\^~*]?v?[\\d.*]+(?:-.*)?$/i'. The parser supports only simple constraints: exact versions, wildcards (*, 1.*), caret (^) and tilde (~) ranges, and OR groups separated by '|'. Operators like '>=', '<', ranges with spaces ('1.0 - 2.0') or comma-separated AND lists are not supported.","triggerScenarios":"Calling (new VersionConstraintParser)->parse('>=1.0.0 <2.0.0'), parse('1.0.0 - 2.0.0'), parse('~1.2, ~1.3'), or any string containing characters outside the allowed set; handleOrGroup forwards each '|' separated part back through parse, so one bad part throws.","commonSituations":"Reusing Composer-style constraints ('^1.2 || >=2.0', 'dev-main') with this simpler parser; config files authored for Composer being fed to composer/semver's VersionConstraintParser; copy-pasted range syntax from npm ('1.x.x || >=2.3.0').","solutions":["Rewrite the constraint using supported syntax: plain versions, *, prefix wildcards, ^, ~, and single '|' OR groups (e.g. '>=1.0 <2.0' has no direct equivalent — enumerate alternatives like '1.0.*|1.1.*' if possible).","Pre-validate the constraint against the accepted regex and fall back to another parser (e.g. Composer's full Semver) for unsupported operators.","Split complex AND/OR logic in application code: parse individual supported constraints and combine matches() results manually."],"exampleFix":"// before\n$constraint = (new VersionConstraintParser())->parse('>=7.4 <8.0');\n\n// after\n$parser = new VersionConstraintParser();\n$lower = $parser->parse('7.4');\n$upper = $parser->parse('8.0.0');\n// compare with Version::isGreaterThan/isLessThan instead of an unsupported range string","handlingStrategy":"validation","validationCode":"// PHP\nif (!preg_match('/^[\\^~*]?v?[\\d.*]+(?:-.*)?$/i', $constraint)) {\n    throw new InvalidArgumentException(\"Constraint not supported by VersionConstraintParser: $constraint\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    $c = $parser->parse($value);\n} catch (UnsupportedVersionConstraintException $e) {\n    // fall back to Composer\\Semver\\Semver or reject the config value\n}","preventionTips":["Restrict config files to the supported grammar: exact versions, *, 1.*, ^x.y, ~x.y, and '|' OR groups.","Do not feed Composer/npm-style expressions ('>=1.0 <2.0', 'dev-main', comma lists) into this parser.","Implement range comparisons in application code using Version::isGreaterThan/isLessThan instead of range strings."],"tags":["semver","constraint-parsing","unsupported-syntax","php"],"backgroundTag":"unsupported-operation","analyzedSha":"5eeb03f1ee82b3076d72daa5cb85d6b68abad783","analyzedAt":"2026-09-14T11:12:29.257Z","contentChangedAt":"2026-09-14T11:12:29.257Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}