1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-30 04:39:00 +01:00

@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
This commit is contained in:
kkmuffme 2024-03-02 11:31:43 +01:00
parent d751c202d8
commit a1848a1a14
2 changed files with 22 additions and 5 deletions

View File

@ -23,6 +23,7 @@ use function count;
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;
use function substr_count;
use function trim;
use const PATHINFO_EXTENSION;
/**
* @internal
*/
@ -417,11 +420,15 @@ final class FunctionLikeDocblockParser
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];
}
}

View File

@ -1384,6 +1384,16 @@ class AnnotationTest extends TestCase
class Foo {}',
'assertions' => [],
],
'sinceTagNonPhpVersion' => [
'code' => '<?php
class Foo {
/**
* @since 8.9.9
*/
public function bar() : void {
}
};',
],
];
}