Skip to content

Commit fa7290b

Browse files
committed
Return an empty context when no file related to the reflector
1 parent 4d9d237 commit fa7290b

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

src/Types/ContextFactory.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,6 @@ final class ContextFactory
3737
* @see Context for more information on Contexts.
3838
*
3939
* @return Context
40-
*
41-
* @throws \InvalidArgumentException
4240
*/
4341
public function createFromReflector(\Reflector $reflector)
4442
{
@@ -47,8 +45,10 @@ public function createFromReflector(\Reflector $reflector)
4745
}
4846

4947
$fileName = $reflector->getFileName();
48+
$namespace = $reflector->getNamespaceName();
49+
5050
if (!$fileName) {
51-
throw new \InvalidArgumentException('There is no file name associated with this reflector.');
51+
return new Context($namespace, []);
5252
}
5353

5454
return $this->createForNamespace($reflector->getNamespaceName(), file_get_contents($fileName));

tests/unit/Types/ContextFactoryTest.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,13 +151,14 @@ public function bar()
151151
}
152152

153153
/**
154-
* @expectedException \InvalidArgumentException
155154
* @covers ::createFromReflector
156155
*/
157-
public function testThrowExceptionWhenEmptyFileName()
156+
public function testEmptyFileName()
158157
{
159158
$fixture = new ContextFactory();
160-
$fixture->createFromReflector(new \ReflectionClass('stdClass'));
159+
$context = $fixture->createFromReflector(new \ReflectionClass('stdClass'));
160+
161+
$this->assertSame([], $context->getNamespaceAliases());
161162
}
162163
}
163164
}

0 commit comments

Comments
 (0)