Skip to content
Permalink
Browse files

Reflection::getUseStatements() throw exceptions on anonymous class

  • Loading branch information...
dg committed Mar 15, 2019
1 parent d339ba9 commit 5c076fde09fed2da8a95d9b2e9c0bd328b9a1040
Showing with 14 additions and 0 deletions.
  1. +3 −0 src/Utils/Reflection.php
  2. +11 −0 tests/Utils/Reflection.expandClassName.phpt
@@ -188,6 +188,9 @@ public static function expandClassName(string $name, \ReflectionClass $rc): stri
*/
public static function getUseStatements(\ReflectionClass $class): array
{
if ($class->isAnonymous()) {
throw new Nette\NotImplementedException('Anonymous classes are not supported.');
}
static $cache = [];
if (!isset($cache[$name = $class->getName()])) {
if ($class->isInternal()) {
@@ -27,6 +27,12 @@ Assert::exception(function () use ($rcTest) {
}, Nette\InvalidArgumentException::class, 'Class name must not be empty.');
Assert::exception(function () use ($rcTest) {
Reflection::expandClassName('A', new ReflectionClass(new class {
}));
}, Nette\NotImplementedException::class, 'Anonymous classes are not supported.');
Assert::same('A', Reflection::expandClassName('A', $rcTest));
Assert::same('A\B', Reflection::expandClassName('C', $rcTest));
@@ -139,3 +145,8 @@ Assert::same(
[],
Reflection::getUseStatements(new ReflectionClass('stdClass'))
);
Assert::exception(function () use ($rcTest) {
Reflection::getUseStatements(new ReflectionClass(new class {
}));
}, Nette\NotImplementedException::class, 'Anonymous classes are not supported.');

0 comments on commit 5c076fd

Please sign in to comment.
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.