From 7c25248161e0710f917f44edde1a646d7877232f Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Thu, 2 Jul 2015 18:06:57 +0100 Subject: [PATCH 1/2] Failing test case: php documentor strips the first char of an imported root namespace --- tests/unit/Types/ContextFactoryTest.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/unit/Types/ContextFactoryTest.php b/tests/unit/Types/ContextFactoryTest.php index 72d7e21..3eae452 100644 --- a/tests/unit/Types/ContextFactoryTest.php +++ b/tests/unit/Types/ContextFactoryTest.php @@ -16,6 +16,7 @@ use Mockery as m; use phpDocumentor\Reflection\DocBlock, phpDocumentor\Reflection\DocBlock\Tag; + use phpDocumentor; use \ReflectionClass; // yes, the slash is part of the test /** @@ -49,6 +50,7 @@ public function testReadsAliasesFromClassReflection() 'm' => 'Mockery', 'DocBlock' => 'phpDocumentor\Reflection\DocBlock', 'Tag' => 'phpDocumentor\Reflection\DocBlock\Tag', + 'phpDocumentor' => 'phpDocumentor', 'ReflectionClass' => 'ReflectionClass' ]; $context = $fixture->createFromReflector(new ReflectionClass($this)); @@ -79,6 +81,7 @@ public function testReadsAliasesFromProvidedNamespaceAndContent() 'm' => 'Mockery', 'DocBlock' => 'phpDocumentor\Reflection\DocBlock', 'Tag' => 'phpDocumentor\Reflection\DocBlock\Tag', + 'phpDocumentor' => 'phpDocumentor', 'ReflectionClass' => 'ReflectionClass' ]; $context = $fixture->createForNamespace(__NAMESPACE__, file_get_contents(__FILE__)); From a5712bf5045da69da8fe7d661c5e234e39c35e95 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Thu, 2 Jul 2015 18:08:16 +0100 Subject: [PATCH 2/2] Hotfix: ensuring that root namespaces are imported correctly (not stripping first char) --- src/Types/ContextFactory.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/Types/ContextFactory.php b/src/Types/ContextFactory.php index 234ae43..ffdbb77 100644 --- a/src/Types/ContextFactory.php +++ b/src/Types/ContextFactory.php @@ -168,7 +168,13 @@ private function extractUseStatement(\ArrayIterator $tokens) } if (count($result) == 1) { - $result[] = substr($result[0], strrpos($result[0], '\\') + 1); + $backslashPos = strrpos($result[0], '\\'); + + if (false !== $backslashPos) { + $result[] = substr($result[0], $backslashPos + 1); + } else { + $result[] = $result[0]; + } } return array_reverse($result);