mirror of
https://github.com/danog/psalm.git
synced 2025-01-21 21:31:13 +01:00
Fix #44 - support empty namespaces
This commit is contained in:
parent
fbbef2c320
commit
fda96660fe
@ -213,8 +213,7 @@ class FileChecker extends SourceChecker implements StatementsSource
|
||||
if ($stmt instanceof PhpParser\Node\Stmt\Class_
|
||||
|| $stmt instanceof PhpParser\Node\Stmt\Interface_
|
||||
|| $stmt instanceof PhpParser\Node\Stmt\Trait_
|
||||
|| ($stmt instanceof PhpParser\Node\Stmt\Namespace_ &&
|
||||
$stmt->name instanceof PhpParser\Node\Name)
|
||||
|| $stmt instanceof PhpParser\Node\Stmt\Namespace_
|
||||
) {
|
||||
if ($stmt instanceof PhpParser\Node\Stmt\Class_ && $stmt->name) {
|
||||
$class_checker = new ClassChecker($stmt, $this, $stmt->name);
|
||||
@ -232,10 +231,8 @@ class FileChecker extends SourceChecker implements StatementsSource
|
||||
$interfaces_to_check[] = $class_checker;
|
||||
} elseif ($stmt instanceof PhpParser\Node\Stmt\Trait_ && $stmt->name) {
|
||||
$trait_checker = new TraitChecker($stmt, $this, $stmt->name);
|
||||
} elseif ($stmt instanceof PhpParser\Node\Stmt\Namespace_ &&
|
||||
$stmt->name instanceof PhpParser\Node\Name
|
||||
) {
|
||||
$namespace_name = implode('\\', $stmt->name->parts);
|
||||
} elseif ($stmt instanceof PhpParser\Node\Stmt\Namespace_) {
|
||||
$namespace_name = $stmt->name ? implode('\\', $stmt->name->parts) : '';
|
||||
|
||||
$namespace_checker = new NamespaceChecker($stmt, $this);
|
||||
|
||||
|
55
tests/NamespaceTest.php
Normal file
55
tests/NamespaceTest.php
Normal file
@ -0,0 +1,55 @@
|
||||
<?php
|
||||
namespace Psalm\Tests;
|
||||
|
||||
use PhpParser\ParserFactory;
|
||||
use PHPUnit_Framework_TestCase;
|
||||
use Psalm\Checker\FileChecker;
|
||||
use Psalm\Config;
|
||||
use Psalm\Context;
|
||||
|
||||
class NamespaceTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
/** @var \PhpParser\Parser */
|
||||
protected static $parser;
|
||||
|
||||
/** @var \Psalm\Checker\ProjectChecker */
|
||||
protected $project_checker;
|
||||
|
||||
public static function setUpBeforeClass()
|
||||
{
|
||||
self::$parser = (new ParserFactory)->create(ParserFactory::PREFER_PHP7);
|
||||
|
||||
$config = new TestConfig();
|
||||
}
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
FileChecker::clearCache();
|
||||
$this->project_checker = new \Psalm\Checker\ProjectChecker();
|
||||
}
|
||||
|
||||
public function testEmptyNamespace()
|
||||
{
|
||||
$stmts = self::$parser->parse('<?php
|
||||
namespace A {
|
||||
function foo() : void {
|
||||
|
||||
}
|
||||
|
||||
class Bar {
|
||||
|
||||
}
|
||||
}
|
||||
namespace {
|
||||
A\foo();
|
||||
\A\foo();
|
||||
|
||||
(new A\Bar);
|
||||
}
|
||||
');
|
||||
|
||||
$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