Skip to content

Commit 14bb2da

Browse files
committed
Merge pull request #7 from Ocramius/hotfix/incorrect-context-factory-resolved-root-namespace-import
Hotfix: incorrect context factory resolved root namespace import
2 parents 6df36de + a5712bf commit 14bb2da

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

src/Types/ContextFactory.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,13 @@ private function extractUseStatement(\ArrayIterator $tokens)
168168
}
169169

170170
if (count($result) == 1) {
171-
$result[] = substr($result[0], strrpos($result[0], '\\') + 1);
171+
$backslashPos = strrpos($result[0], '\\');
172+
173+
if (false !== $backslashPos) {
174+
$result[] = substr($result[0], $backslashPos + 1);
175+
} else {
176+
$result[] = $result[0];
177+
}
172178
}
173179

174180
return array_reverse($result);

tests/unit/Types/ContextFactoryTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use Mockery as m;
1717
use phpDocumentor\Reflection\DocBlock,
1818
phpDocumentor\Reflection\DocBlock\Tag;
19+
use phpDocumentor;
1920
use \ReflectionClass; // yes, the slash is part of the test
2021

2122
/**
@@ -49,6 +50,7 @@ public function testReadsAliasesFromClassReflection()
4950
'm' => 'Mockery',
5051
'DocBlock' => 'phpDocumentor\Reflection\DocBlock',
5152
'Tag' => 'phpDocumentor\Reflection\DocBlock\Tag',
53+
'phpDocumentor' => 'phpDocumentor',
5254
'ReflectionClass' => 'ReflectionClass'
5355
];
5456
$context = $fixture->createFromReflector(new ReflectionClass($this));
@@ -79,6 +81,7 @@ public function testReadsAliasesFromProvidedNamespaceAndContent()
7981
'm' => 'Mockery',
8082
'DocBlock' => 'phpDocumentor\Reflection\DocBlock',
8183
'Tag' => 'phpDocumentor\Reflection\DocBlock\Tag',
84+
'phpDocumentor' => 'phpDocumentor',
8285
'ReflectionClass' => 'ReflectionClass'
8386
];
8487
$context = $fixture->createForNamespace(__NAMESPACE__, file_get_contents(__FILE__));

0 commit comments

Comments
 (0)