mirror of
https://github.com/danog/psalm.git
synced 2024-11-26 20:34:47 +01:00
Fix #817 - allow methods named "global" in @method annotations
This commit is contained in:
parent
7fb4c4acad
commit
47a40b2ffc
@ -426,7 +426,7 @@ class CommentChecker
|
||||
|
||||
$method_entry = preg_replace('/[a-zA-Z\\\\0-9_]+(\|[a-zA-Z\\\\0-9_]+)+ \$/', '$', $method_entry);
|
||||
|
||||
$php_string = '<?php ' . $return_docblock . ' function ' . $method_entry . '{}';
|
||||
$php_string = '<?php class A { ' . $return_docblock . ' public function ' . $method_entry . '{} }';
|
||||
|
||||
try {
|
||||
$statements = \Psalm\Provider\StatementsProvider::parseStatements($php_string);
|
||||
@ -434,11 +434,16 @@ class CommentChecker
|
||||
throw new DocblockParseException('Badly-formatted @method string ' . $method_entry);
|
||||
}
|
||||
|
||||
if (!$statements[0] instanceof \PhpParser\Node\Stmt\Function_) {
|
||||
if (!$statements[0] instanceof \PhpParser\Node\Stmt\Class_
|
||||
|| !isset($statements[0]->stmts[0])
|
||||
|| !$statements[0]->stmts[0] instanceof \PhpParser\Node\Stmt\ClassMethod
|
||||
) {
|
||||
throw new DocblockParseException('Badly-formatted @method string ' . $method_entry);
|
||||
}
|
||||
|
||||
$info->methods[] = $statements[0];
|
||||
|
||||
|
||||
$info->methods[] = $statements[0]->stmts[0];
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -26,7 +26,7 @@ class ClassLikeDocblockComment
|
||||
public $properties = [];
|
||||
|
||||
/**
|
||||
* @var array<int, \PhpParser\Node\Stmt\Function_>
|
||||
* @var array<int, \PhpParser\Node\Stmt\ClassMethod>
|
||||
*/
|
||||
public $methods = [];
|
||||
|
||||
|
@ -666,7 +666,7 @@ class DependencyFinderVisitor extends PhpParser\NodeVisitorAbstract implements P
|
||||
{
|
||||
$class_storage = null;
|
||||
|
||||
if ($fake_method && $stmt instanceof PhpParser\Node\Stmt\Function_) {
|
||||
if ($fake_method && $stmt instanceof PhpParser\Node\Stmt\ClassMethod) {
|
||||
$cased_function_id = '@method ' . $stmt->name->name;
|
||||
|
||||
$storage = new FunctionLikeStorage();
|
||||
|
@ -890,6 +890,13 @@ class AnnotationTest extends TestCase
|
||||
/** @param string[] $s */
|
||||
function foo(string ...$s) : void {}',
|
||||
],
|
||||
'globalMethod' => [
|
||||
'<?php
|
||||
/** @method void global() */
|
||||
class A {
|
||||
public function __call(string $s) {}
|
||||
}',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user