diff --git a/src/Generator/Client.php b/src/Generator/Client.php index 0bc966d..e71351e 100644 --- a/src/Generator/Client.php +++ b/src/Generator/Client.php @@ -34,7 +34,13 @@ public static function generate(string $namespace, array $clients, SchemaRegistr $factory = new BuilderFactory(); $stmt = $factory->namespace(rtrim($namespace, '\\')); - $class = $factory->class('Client')->implement(new Node\Name('ClientInterface'))->makeFinal()->addStmt( + $class = $factory->class('Client')->implement(new Node\Name('ClientInterface'))->makeFinal()->setDocComment( + new Doc(implode(PHP_EOL, [ + '/**', + ' * @template H', + ' */', + ])) + )->addStmt( $factory->property('authentication')->setType('\\' . AuthenticationInterface::class)->makeReadonly()->makePrivate() )->addStmt( $factory->property('browser')->setType('\\' . Browser::class)->makeReadonly()->makePrivate() @@ -322,7 +328,14 @@ public static function generate(string $namespace, array $clients, SchemaRegistr ); $class->addStmt( - $factory->method('hydrateObject')->makePublic()->setReturnType('object')->addParam( + $factory->method('hydrateObject')->makePublic()->setDocComment( + new Doc(implode(PHP_EOL, [ + '/**', + ' * @param class-string $className', + ' * @return H', + ' */', + ])) + )->setReturnType('object')->addParam( (new Param('className'))->setType('string') )->addParam( (new Param('data'))->setType('array') diff --git a/src/Generator/ClientInterface.php b/src/Generator/ClientInterface.php index 93a2ea5..e229b88 100644 --- a/src/Generator/ClientInterface.php +++ b/src/Generator/ClientInterface.php @@ -34,7 +34,13 @@ public static function generate(string $namespace, array $clients, SchemaRegistr $factory = new BuilderFactory(); $stmt = $factory->namespace(rtrim($namespace, '\\')); - $class = $factory->interface('ClientInterface'); + $class = $factory->interface('ClientInterface')->setDocComment( + new Doc(implode(PHP_EOL, [ + '/**', + ' * @template H', + ' */', + ])) + ); $rawCallReturnTypes = []; $operationCalls = []; $callReturnTypes = []; @@ -112,7 +118,14 @@ public static function generate(string $namespace, array $clients, SchemaRegistr ); $class->addStmt( - $factory->method('hydrateObject')->makePublic()->setReturnType('object')->addParam( + $factory->method('hydrateObject')->makePublic()->setDocComment( + new Doc(implode(PHP_EOL, [ + '/**', + ' * @param class-string $className', + ' * @return H', + ' */', + ])) + )->setReturnType('object')->addParam( (new Param('className'))->setType('string') )->addParam( (new Param('data'))->setType('array') diff --git a/src/Generator/WebHooks.php b/src/Generator/WebHooks.php index 2e3b303..291d0b6 100644 --- a/src/Generator/WebHooks.php +++ b/src/Generator/WebHooks.php @@ -52,8 +52,6 @@ public static function generate(string $namespace, string $baseNamespace, array ], Class_::MODIFIER_PUBLIC ) - )->addStmt( - $factory->property('hydrator')->setType('\\' . $baseNamespace . 'OptimizedHydratorMapper')->makeReadonly()->makePrivate() )->addStmt( $factory->method('__construct')->makePublic()->addStmt( new Node\Expr\Assign( @@ -117,37 +115,8 @@ public static function generate(string $namespace, string $baseNamespace, array ) ) )) - )->addStmt( - $factory->method('hydrate')->makePublic()->setReturnType('object')->addParam( - (new Param('event'))->setType('string') - )->addParam( - (new Param('data'))->setType('array') - )->addStmt(new Node\Stmt\Return_( - new Node\Expr\MethodCall( - new Node\Expr\PropertyFetch( - new Node\Expr\Variable('this'), - 'hydrator' - ), - new Node\Name('hydrateObject'), - [ - new Node\Arg(new Node\Expr\MethodCall( - new Node\Expr\StaticCall( - new Node\Name('self'), - new Node\Name('resolve'), - [ - new Node\Arg(new Node\Expr\Variable('event')), - ] - ), - new Node\Name('resolve'), - [ - new Node\Arg(new Node\Expr\Variable('data')), - ] - )), - new Node\Arg(new Node\Expr\Variable('data')), - ] - ) - )) ); + yield new File($namespace . '\\' . 'WebHooks', $stmt->addStmt($class)->getNode()); } }