From d751c202d8534436ab0452fe632e17fb1de6907d Mon Sep 17 00:00:00 2001 From: kkmuffme <11071985+kkmuffme@users.noreply.github.com> Date: Sat, 2 Mar 2024 11:30:28 +0100 Subject: [PATCH 1/2] fix unrelated Config bug not honoring PHP composer versions 8.2 + 8.3 --- src/Psalm/Config.php | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/Psalm/Config.php b/src/Psalm/Config.php index a8a08366e43..069fd2c7a1f 100644 --- a/src/Psalm/Config.php +++ b/src/Psalm/Config.php @@ -2781,8 +2781,22 @@ public function getPHPVersionFromComposerJson(): ?string $version_parser = new VersionParser(); $constraint = $version_parser->parseConstraints($php_version); - - foreach (['5.4', '5.5', '5.6', '7.0', '7.1', '7.2', '7.3', '7.4', '8.0', '8.1'] as $candidate) { + $php_versions = [ + '5.4', + '5.5', + '5.6', + '7.0', + '7.1', + '7.2', + '7.3', + '7.4', + '8.0', + '8.1', + '8.2', + '8.3', + ]; + + foreach ($php_versions as $candidate) { if ($constraint->matches(new Constraint('<=', "$candidate.0.0-dev")) || $constraint->matches(new Constraint('<=', "$candidate.999")) ) { From a1848a1a1419b602c0266d64513827b5f124842f Mon Sep 17 00:00:00 2001 From: kkmuffme <11071985+kkmuffme@users.noreply.github.com> Date: Sat, 2 Mar 2024 11:31:43 +0100 Subject: [PATCH 2/2] @since annotations should only infer PHP version in .phpstub files or for @since 8.0.0 PHP Fix https://github.com/vimeo/psalm/issues/10761 --- .../Reflector/FunctionLikeDocblockParser.php | 17 ++++++++++++----- tests/AnnotationTest.php | 10 ++++++++++ 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/src/Psalm/Internal/PhpVisitor/Reflector/FunctionLikeDocblockParser.php b/src/Psalm/Internal/PhpVisitor/Reflector/FunctionLikeDocblockParser.php index 52106d3895e..25fcb44bf21 100644 --- a/src/Psalm/Internal/PhpVisitor/Reflector/FunctionLikeDocblockParser.php +++ b/src/Psalm/Internal/PhpVisitor/Reflector/FunctionLikeDocblockParser.php @@ -23,6 +23,7 @@ use function explode; use function implode; use function in_array; +use function pathinfo; use function preg_last_error_msg; use function preg_match; use function preg_replace; @@ -37,6 +38,8 @@ use function substr_count; use function trim; +use const PATHINFO_EXTENSION; + /** * @internal */ @@ -417,11 +420,15 @@ public static function parse( if (isset($parsed_docblock->tags['since'])) { $since = trim(reset($parsed_docblock->tags['since'])); - if (preg_match('/^[4578]\.\d(\.\d+)?$/', $since)) { - $since_parts = explode('.', $since); - - $info->since_php_major_version = (int)$since_parts[0]; - $info->since_php_minor_version = (int)$since_parts[1]; + // only for phpstub files or @since 8.0.0 PHP + // since @since is commonly used with the project version, not the PHP version + // https://docs.phpdoc.org/3.0/guide/references/phpdoc/tags/since.html + // https://github.com/vimeo/psalm/issues/10761 + if (preg_match('/^([4578])\.(\d)(\.\d+)?(\s+PHP)?$/i', $since, $since_match) + && isset($since_match[1])&& isset($since_match[2]) + && (!empty($since_match[4]) || pathinfo($code_location->file_name, PATHINFO_EXTENSION) === 'phpstub')) { + $info->since_php_major_version = (int)$since_match[1]; + $info->since_php_minor_version = (int)$since_match[2]; } } diff --git a/tests/AnnotationTest.php b/tests/AnnotationTest.php index 1626c0bcc1a..7a7345bd538 100644 --- a/tests/AnnotationTest.php +++ b/tests/AnnotationTest.php @@ -1384,6 +1384,16 @@ class Bar {} class Foo {}', 'assertions' => [], ], + 'sinceTagNonPhpVersion' => [ + 'code' => '