diff --git a/src/ReflectionStorage/ReflectionStorage.php b/src/ReflectionStorage/ReflectionStorage.php index 5ab1eeb..122584c 100644 --- a/src/ReflectionStorage/ReflectionStorage.php +++ b/src/ReflectionStorage/ReflectionStorage.php @@ -23,6 +23,11 @@ public function __construct( private readonly bool $detectChanges = true, ) {} + private static function throwingLoader(): never + { + throw new \LogicException('Reflection loader must not be called twice.'); + } + /** * @param class-string $class * @param non-empty-string $name @@ -87,7 +92,7 @@ public function get(string $class, string $name, \Closure $loader): object $loader(); - return $this->get($class, $name, static fn(): never => throw new ReflectionException(sprintf('%s with name %s not found.', $class, $name))); + return $this->get($class, $name, self::throwingLoader(...)); } /**