mirror of
https://github.com/danog/psalm.git
synced 2025-01-21 21:31:13 +01:00
Fix #56 - functions in root namespaces should not need slash
This commit is contained in:
parent
ff2e7b1b28
commit
8836f05027
@ -1407,7 +1407,7 @@ class CallChecker
|
||||
*/
|
||||
protected static function checkFunctionExists(
|
||||
StatementsChecker $statements_checker,
|
||||
$function_id,
|
||||
&$function_id,
|
||||
Context $context,
|
||||
CodeLocation $code_location
|
||||
) {
|
||||
@ -1415,16 +1415,25 @@ class CallChecker
|
||||
$function_id = strtolower($function_id);
|
||||
|
||||
if (!FunctionChecker::functionExists($function_id, $statements_checker->getFilePath())) {
|
||||
if (IssueBuffer::accepts(
|
||||
new UndefinedFunction(
|
||||
'Function ' . $cased_function_id . ' does not exist',
|
||||
$code_location
|
||||
),
|
||||
$statements_checker->getSuppressedIssues()
|
||||
)) {
|
||||
// fall through
|
||||
$root_function_id = preg_replace('/.*\\\/', '', $function_id);
|
||||
|
||||
if ($function_id !== $root_function_id &&
|
||||
FunctionChecker::functionExists($root_function_id, $statements_checker->getFilePath())
|
||||
) {
|
||||
$function_id = $root_function_id;
|
||||
} else {
|
||||
if (IssueBuffer::accepts(
|
||||
new UndefinedFunction(
|
||||
'Function ' . $cased_function_id . ' does not exist',
|
||||
$code_location
|
||||
),
|
||||
$statements_checker->getSuppressedIssues()
|
||||
)) {
|
||||
// fall through
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
|
@ -218,7 +218,8 @@ class FunctionCallTest extends PHPUnit_Framework_TestCase
|
||||
$stmts = self::$parser->parse('<?php
|
||||
namespace A;
|
||||
|
||||
function f(int $p) : void {}
|
||||
/** @return void */
|
||||
function f(int $p) {}
|
||||
f(5);
|
||||
');
|
||||
|
||||
@ -226,4 +227,24 @@ class FunctionCallTest extends PHPUnit_Framework_TestCase
|
||||
$context = new Context('somefile.php');
|
||||
$file_checker->visitAndAnalyzeMethods($context);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function testNamespacedRootFunctionCall()
|
||||
{
|
||||
$stmts = self::$parser->parse('<?php
|
||||
namespace {
|
||||
/** @return void */
|
||||
function foo() { }
|
||||
}
|
||||
namespace A\B\C {
|
||||
foo();
|
||||
}
|
||||
');
|
||||
|
||||
$file_checker = new FileChecker('somefile.php', $this->project_checker, $stmts);
|
||||
$context = new Context('somefile.php');
|
||||
$file_checker->visitAndAnalyzeMethods($context);
|
||||
}
|
||||
}
|
||||
|
@ -41,7 +41,8 @@ class NamespaceTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
$stmts = self::$parser->parse('<?php
|
||||
namespace A {
|
||||
function foo() : void {
|
||||
/** @return void */
|
||||
function foo() {
|
||||
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user