mirror of
https://github.com/danog/psalm.git
synced 2024-11-30 04:39:00 +01:00
Fix PHP version checking
Separate condition to check both cases if the specified string is a valid version and if it is supported Remove unsupported versions up to 7.4 from regex
This commit is contained in:
parent
bf8e150f8f
commit
5f40d26539
@ -200,6 +200,10 @@ class ProjectAnalyzer
|
||||
UnnecessaryVarAnnotation::class,
|
||||
];
|
||||
|
||||
private const PHP_VERSION_REGEX = '^(0|[1-9]\d*)\.(0|[1-9]\d*)(?:\..*)?$';
|
||||
|
||||
private const PHP_SUPPORTED_VERSIONS_REGEX = '^(7\.4|8\.[012])(\..*)?$';
|
||||
|
||||
/**
|
||||
* @param array<ReportOptions> $generated_report_options
|
||||
*/
|
||||
@ -1179,10 +1183,27 @@ class ProjectAnalyzer
|
||||
*/
|
||||
public function setPhpVersion(string $version, string $source): void
|
||||
{
|
||||
if (!preg_match('/^(5\.[456]|7\.[01234]|8\.[012])(\..*)?$/', $version)) {
|
||||
throw new UnexpectedValueException('Expecting a version number in the format x.y');
|
||||
if (!preg_match('/' . self::PHP_VERSION_REGEX . '/', $version)) {
|
||||
fwrite(
|
||||
STDERR,
|
||||
'Expecting a version number in the format x.y or x.y.z'
|
||||
. PHP_EOL,
|
||||
);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (!preg_match('/' . self::PHP_SUPPORTED_VERSIONS_REGEX . '/', $version)) {
|
||||
fwrite(
|
||||
STDERR,
|
||||
'Psalm requires PHP version ">7.4". The specified version '
|
||||
. $version
|
||||
. " is either not supported or doesn't exist."
|
||||
. PHP_EOL,
|
||||
);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
|
||||
[$php_major_version, $php_minor_version] = explode('.', $version);
|
||||
|
||||
$php_major_version = (int) $php_major_version;
|
||||
|
Loading…
Reference in New Issue
Block a user