$clazz * @return R * @noinspection PhpDocMissingThrowsInspection */ public function ofType(string $clazz): object { /** @noinspection PhpUnhandledExceptionInspection */ $refClass = new ReflectionClass($clazz); /** * @var R of object * @phpstan-ignore varTag.nativeType */ return new class($refClass) { /** * @param ReflectionClass $refClass */ public function __construct( private readonly ReflectionClass $refClass ) {} /** * @param string $name * @param list $arguments * @return mixed */ public function __call(string $name, array $arguments): mixed { $method = $this->refClass->getMethod($name); $queryAttr = $method->getAttributes(Query::class); if (count($queryAttr) !== 1) { throw new InvalidRepository( "Called method $name has an invalid number of Query attributes. Expected: 1" ); } return ''; } }; } }