Skip to content

Commit 3e1f6ba

Browse files
committed
Factory: $withBodies cannot be used for internal classes/functions
1 parent 047e8a6 commit 3e1f6ba

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

src/PhpGenerator/Factory.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ public function fromClassReflection(
3131
bool $withBodies = false,
3232
): ClassLike
3333
{
34-
if ($withBodies && $from->isAnonymous()) {
35-
throw new Nette\NotSupportedException('The $withBodies parameter cannot be used for anonymous functions.');
34+
if ($withBodies && ($from->isAnonymous() || $from->isInternal())) {
35+
throw new Nette\NotSupportedException('The $withBodies parameter cannot be used for anonymous or internal classes.');
3636
}
3737

3838
$enumIface = null;
@@ -177,8 +177,8 @@ public function fromFunctionReflection(\ReflectionFunction $from, bool $withBody
177177
$function->setReturnType((string) $from->getReturnType());
178178

179179
if ($withBody) {
180-
if ($from->isClosure()) {
181-
throw new Nette\NotSupportedException('The $withBody parameter cannot be used for closures.');
180+
if ($from->isClosure() || $from->isInternal()) {
181+
throw new Nette\NotSupportedException('The $withBody parameter cannot be used for closures or internal functions.');
182182
}
183183

184184
$function->setBody($this->getExtractor($from)->extractFunctionBody($from->name));

tests/PhpGenerator/ClassType.from.bodies.phpt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ require __DIR__ . '/fixtures/bodies.php';
1111

1212
Assert::exception(
1313
fn() => ClassType::from(PDO::class, withBodies: true),
14-
Nette\InvalidStateException::class,
15-
'Source code of PDO not found.',
14+
Nette\NotSupportedException::class,
15+
'The $withBodies parameter cannot be used for anonymous or internal classes.',
1616
);
1717

1818

@@ -23,7 +23,7 @@ Assert::exception(
2323
}
2424
}, withBodies: true),
2525
Nette\NotSupportedException::class,
26-
'The $withBodies parameter cannot be used for anonymous functions.',
26+
'The $withBodies parameter cannot be used for anonymous or internal classes.',
2727
);
2828

2929

0 commit comments

Comments
 (0)