Skip to content

Commit 250bf02

Browse files
committed
Factory: $withBodies cannot be used for internal classes/functions
1 parent 7eb1b35 commit 250bf02

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
@@ -37,8 +37,8 @@ public function fromClassReflection(
3737
if ($materializeTraits !== null) {
3838
trigger_error(__METHOD__ . '() parameter $materializeTraits has been removed (is always false).', E_USER_DEPRECATED);
3939
}
40-
if ($withBodies && $from->isAnonymous()) {
41-
throw new Nette\NotSupportedException('The $withBodies parameter cannot be used for anonymous functions.');
40+
if ($withBodies && ($from->isAnonymous() || $from->isInternal())) {
41+
throw new Nette\NotSupportedException('The $withBodies parameter cannot be used for anonymous or internal classes.');
4242
}
4343

4444
$enumIface = null;
@@ -183,8 +183,8 @@ public function fromFunctionReflection(\ReflectionFunction $from, bool $withBody
183183
$function->setReturnType((string) $from->getReturnType());
184184

185185
if ($withBody) {
186-
if ($from->isClosure()) {
187-
throw new Nette\NotSupportedException('The $withBody parameter cannot be used for closures.');
186+
if ($from->isClosure() || $from->isInternal()) {
187+
throw new Nette\NotSupportedException('The $withBody parameter cannot be used for closures or internal functions.');
188188
}
189189

190190
$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)