mirror of
https://github.com/danog/psalm.git
synced 2025-01-21 21:31:13 +01:00
Fix namespaced functions in regular use statements
This commit is contained in:
parent
ac92de181f
commit
5315fd15ad
@ -688,7 +688,8 @@ class FunctionChecker extends FunctionLikeChecker
|
||||
return substr($function_name, 1);
|
||||
}
|
||||
|
||||
$imported_namespaces = $source->getAliasedFunctions();
|
||||
$imported_function_namespaces = $source->getAliasedFunctions();
|
||||
$imported_namespaces = $source->getAliasedClasses();
|
||||
|
||||
if (strpos($function_name, '\\') !== false) {
|
||||
$function_name_parts = explode('\\', $function_name);
|
||||
@ -697,8 +698,14 @@ class FunctionChecker extends FunctionLikeChecker
|
||||
if (isset($imported_namespaces[strtolower($first_namespace)])) {
|
||||
return $imported_namespaces[strtolower($first_namespace)] . '\\' . implode('\\', $function_name_parts);
|
||||
}
|
||||
|
||||
if (isset($imported_function_namespaces[strtolower($first_namespace)])) {
|
||||
return $imported_function_namespaces[strtolower($first_namespace)] . '\\' . implode('\\', $function_name_parts);
|
||||
}
|
||||
} elseif (isset($imported_namespaces[strtolower($function_name)])) {
|
||||
return $imported_namespaces[strtolower($function_name)];
|
||||
} elseif (isset($imported_function_namespaces[strtolower($function_name)])) {
|
||||
return $imported_function_namespaces[strtolower($function_name)];
|
||||
}
|
||||
|
||||
$namespace = $source->getNamespace();
|
||||
|
@ -482,9 +482,23 @@ class ExpressionChecker
|
||||
return null;
|
||||
}
|
||||
|
||||
if (in_array($stmt->name, [
|
||||
'_SERVER', '_GET', '_POST', '_COOKIE', '_REQUEST', '_FILES', '_ENV', 'GLOBALS', 'argv', 'argc'
|
||||
])) {
|
||||
if (in_array(
|
||||
$stmt->name,
|
||||
[
|
||||
'_SERVER',
|
||||
'_GET',
|
||||
'_POST',
|
||||
'_COOKIE',
|
||||
'_REQUEST',
|
||||
'_FILES',
|
||||
'_ENV',
|
||||
'_SESSION',
|
||||
'GLOBALS',
|
||||
'argv',
|
||||
'argc',
|
||||
]
|
||||
)
|
||||
) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -437,4 +437,25 @@ class ClassTest extends PHPUnit_Framework_TestCase
|
||||
$context = new Context('somefile.php');
|
||||
$file_checker->visitAndAnalyzeMethods($context);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function testNamespacedAliasedClassCall()
|
||||
{
|
||||
$stmts = self::$parser->parse('<?php
|
||||
namespace Aye {
|
||||
class Foo {}
|
||||
}
|
||||
namespace Bee {
|
||||
use Aye as A;
|
||||
|
||||
new A\Foo();
|
||||
}
|
||||
');
|
||||
|
||||
$file_checker = new FileChecker('somefile.php', $this->project_checker, $stmts);
|
||||
$context = new Context('somefile.php');
|
||||
$file_checker->visitAndAnalyzeMethods($context);
|
||||
}
|
||||
}
|
||||
|
@ -247,4 +247,26 @@ class FunctionCallTest extends PHPUnit_Framework_TestCase
|
||||
$context = new Context('somefile.php');
|
||||
$file_checker->visitAndAnalyzeMethods($context);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function testNamespacedAliasedFunctionCall()
|
||||
{
|
||||
$stmts = self::$parser->parse('<?php
|
||||
namespace Aye {
|
||||
/** @return void */
|
||||
function foo() { }
|
||||
}
|
||||
namespace Bee {
|
||||
use Aye as A;
|
||||
|
||||
A\foo();
|
||||
}
|
||||
');
|
||||
|
||||
$file_checker = new FileChecker('somefile.php', $this->project_checker, $stmts);
|
||||
$context = new Context('somefile.php');
|
||||
$file_checker->visitAndAnalyzeMethods($context);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user