Skip to content

UnexpectedValueException: Expecting a version number in the format x.y #10084

@AndreyMZ

Description

@AndreyMZ

Steps to reproduce

  1. Set phpVersion to "5.1" in the configuration file.
  2. Run Psalm.

Actual result

Uncaught UnexpectedValueException: Expecting a version number in the format x.y in /opt/psalm/vendor/vimeo/psalm/src/Psalm/Internal/Analyzer/ProjectAnalyzer.php:1174
Stack trace:
#0 /opt/psalm/vendor/vimeo/psalm/src/Psalm/Internal/CliUtils.php(500): Psalm\Internal\Analyzer\ProjectAnalyzer->setPhpVersion('5.1', 'config')
#1 /opt/psalm/vendor/vimeo/psalm/src/Psalm/Internal/Cli/Psalm.php(349): Psalm\Internal\CliUtils::initPhpVersion(Array, Object(Psalm\Config), Object(Psalm\Internal\Analyzer\ProjectAnalyzer))
#2 /opt/psalm/vendor/vimeo/psalm/psalm(9): Psalm\Internal\Cli\Psalm::run(Array)
#3 /opt/psalm/vendor/bin/psalm(119): include('/opt/psalm/vend...')
#4 {main}
(Psalm 5.11.0@c9b192ab8400fdaf04b2b13d110575adc879aa90 crashed due to an uncaught Throwable)

Expected result

  1. No uncaught exception, no stack trace.
  2. Correct error message telling that PHP 5.1 specified in the configuration file ".xml" is not supported by Psalm, and only PHP 5.4-5.6, 7.0-7.4, 8.0-8.2 are supported.

Root cause

if (!preg_match('/^(5\.[456]|7\.[01234]|8\.[012])(\..*)?$/', $version)) {
throw new UnexpectedValueException('Expecting a version number in the format x.y');
}

Additional information

The error message is also wrong because actually version numbers in the formats x.y.z (e.g. "8.2.8") are also expected.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions