diff --git a/src/Types/ContextFactory.php b/src/Types/ContextFactory.php index 892ee0f..4909ab7 100644 --- a/src/Types/ContextFactory.php +++ b/src/Types/ContextFactory.php @@ -181,6 +181,7 @@ public function createForNamespace(string $namespace, string $fileContents): Con $currentNamespace = $this->parseNamespace($tokens); break; case T_CLASS: + case T_TRAIT: // Fast-forward the iterator through the class so that any // T_USE tokens found within are skipped - these are not // valid namespace use statements so should be ignored. diff --git a/tests/unit/Types/ContextFactoryTest.php b/tests/unit/Types/ContextFactoryTest.php index 28a3d5d..9aa97ae 100644 --- a/tests/unit/Types/ContextFactoryTest.php +++ b/tests/unit/Types/ContextFactoryTest.php @@ -139,6 +139,35 @@ public function bar() $this->assertSame([], $context->getNamespaceAliases()); } + /** + * @covers ::createForNamespace + * @uses phpDocumentor\Reflection\Types\Context + */ + public function testTraitContainsClosureWithUseStatement() : void + { + $php = 'createForNamespace('Foo', $php); + + $this->assertSame([], $context->getNamespaceAliases()); + } + /** * @covers ::createFromReflector */