Skip to content

Commit 4d9d237

Browse files
committed
Fix file_get_contents warning in ContextFactory
1 parent 60fe236 commit 4d9d237

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

src/Types/ContextFactory.php

+6
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,19 @@ final class ContextFactory
3737
* @see Context for more information on Contexts.
3838
*
3939
* @return Context
40+
*
41+
* @throws \InvalidArgumentException
4042
*/
4143
public function createFromReflector(\Reflector $reflector)
4244
{
4345
if (method_exists($reflector, 'getDeclaringClass')) {
4446
$reflector = $reflector->getDeclaringClass();
4547
}
48+
4649
$fileName = $reflector->getFileName();
50+
if (!$fileName) {
51+
throw new \InvalidArgumentException('There is no file name associated with this reflector.');
52+
}
4753

4854
return $this->createForNamespace($reflector->getNamespaceName(), file_get_contents($fileName));
4955
}

tests/unit/Types/ContextFactoryTest.php

+10
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,16 @@ public function bar()
149149

150150
$this->assertSame([], $context->getNamespaceAliases());
151151
}
152+
153+
/**
154+
* @expectedException \InvalidArgumentException
155+
* @covers ::createFromReflector
156+
*/
157+
public function testThrowExceptionWhenEmptyFileName()
158+
{
159+
$fixture = new ContextFactory();
160+
$fixture->createFromReflector(new \ReflectionClass('stdClass'));
161+
}
152162
}
153163
}
154164

0 commit comments

Comments
 (0)