Skip to content

Commit

Permalink
Throw exception instead of relying on PHP type error
Browse files Browse the repository at this point in the history
  • Loading branch information
GromNaN committed Feb 26, 2024
1 parent 5dca140 commit cca65d8
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/PhpGenerator/ClassLike.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,27 @@ abstract class ClassLike

public static function from(string|object $class, bool $withBodies = false): static
{
return (new Factory)
$class = (new Factory)
->fromClassReflection(new \ReflectionClass($class), $withBodies);

if (!$class instanceof static) {
throw new Nette\InvalidArgumentException("Object '$class' is not an instance of " . static::class);
}

return $class;
}


public static function fromCode(string $code): static
{
return (new Factory)
$class = (new Factory)
->fromClassCode($code);

if (!$class instanceof static) {
throw new Nette\InvalidArgumentException("Object '$class' is not an instance of " . static::class);
}

return $class;
}


Expand Down

0 comments on commit cca65d8

Please sign in to comment.