Skip to content

Commit

Permalink
Factory: $withBodies cannot be used for internal classes/functions
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Oct 15, 2023
1 parent c7e7b82 commit 894a440
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
8 changes: 4 additions & 4 deletions src/PhpGenerator/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ public function fromClassReflection(
if ($materializeTraits !== null) {
trigger_error(__METHOD__ . '() parameter $materializeTraits has been removed (is always false).', E_USER_DEPRECATED);
}
if ($withBodies && $from->isAnonymous()) {
throw new Nette\NotSupportedException('The $withBodies parameter cannot be used for anonymous functions.');
if ($withBodies && ($from->isAnonymous() || $from->isInternal())) {
throw new Nette\NotSupportedException('The $withBodies parameter cannot be used for anonymous or internal classes.');
}

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

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

$function->setBody($this->getExtractor($from)->extractFunctionBody($from->name));
Expand Down
6 changes: 3 additions & 3 deletions tests/PhpGenerator/ClassType.from.bodies.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ require __DIR__ . '/fixtures/bodies.php';

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


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


Expand Down

0 comments on commit 894a440

Please sign in to comment.