@@ -176,12 +176,64 @@ public static function generate(string $namespace, array $clients, SchemaRegistr
176176 }
177177
178178 $ class ->addStmt (
179- $ factory ->method ('callAsync ' )->makePublic ()->setReturnType (
180- new Node \Name ('\\' . PromiseInterface::class)
181- )->setDocComment (
179+ $ factory ->method ('call ' )->makePublic ()->setDocComment (
182180 new Doc (implode (PHP_EOL , [
183181 '/** ' ,
184- ' * @return \\' . PromiseInterface::class . '< ' . implode ('| ' , array_unique ($ callReturnTypes )) . '> ' ,
182+ ' * @return ' . (function (array $ operationCalls ): string {
183+ $ count = count ($ operationCalls );
184+ $ lastItem = $ count - 1 ;
185+ $ left = '' ;
186+ $ right = '' ;
187+ for ($ i = 0 ; $ i < $ count ; $ i ++) {
188+ if ($ i !== $ lastItem ) {
189+ $ left .= '($call is ' . $ operationCalls [$ i ]['className ' ] . '::OPERATION_MATCH ? ' . implode ('| ' , array_unique ($ operationCalls [$ i ]['returnType ' ])) . ' : ' ;
190+ } else {
191+ $ left .= implode ('| ' , array_unique ($ operationCalls [$ i ]['returnType ' ]));
192+ }
193+ $ right .= ') ' ;
194+ }
195+ return $ left . $ right ;
196+ })($ operationCalls ),
197+ ' */ ' ,
198+ ]))
199+ )->addParam ((new Param ('call ' ))->setType ('string ' ))->addParam ((new Param ('params ' ))->setType ('array ' )->setDefault ([]))->addStmt (new Node \Stmt \Return_ (
200+ new Node \Expr \FuncCall (
201+ new Node \Name ('\React\Async\await ' ),
202+ [
203+ new Node \Arg (
204+ new Node \Expr \MethodCall (
205+ new Node \Expr \Variable ('this ' ),
206+ new Node \Name ('callAsync ' ),
207+ [
208+ new Node \Arg (new Node \Expr \Variable ('call ' )),
209+ new Node \Arg (new Node \Expr \Variable ('params ' )),
210+ ]
211+ )
212+ ),
213+ ],
214+ )
215+ ))
216+ );
217+
218+ $ class ->addStmt (
219+ $ factory ->method ('callAsync ' )->makePublic ()->setDocComment (
220+ new Doc (implode (PHP_EOL , [
221+ '/** ' ,
222+ ' * @return ' . (function (array $ operationCalls ): string {
223+ $ count = count ($ operationCalls );
224+ $ lastItem = $ count - 1 ;
225+ $ left = '' ;
226+ $ right = '' ;
227+ for ($ i = 0 ; $ i < $ count ; $ i ++) {
228+ if ($ i !== $ lastItem ) {
229+ $ left .= '($call is ' . $ operationCalls [$ i ]['className ' ] . '::OPERATION_MATCH ? \\' . PromiseInterface::class . '< ' . implode ('| ' , array_unique ($ operationCalls [$ i ]['returnType ' ])) . '> : ' ;
230+ } else {
231+ $ left .= '\\' . PromiseInterface::class . '< ' . implode ('| ' , array_unique ($ operationCalls [$ i ]['returnType ' ])) . '> ' ;
232+ }
233+ $ right .= ') ' ;
234+ }
235+ return $ left . $ right ;
236+ })($ operationCalls ),
185237 ' */ ' ,
186238 ]))
187239 )->addParam ((new Param ('call ' ))->setType ('string ' ))->addParam ((new Param ('params ' ))->setType ('array ' )->setDefault ([]))->addStmt (new Node \Stmt \Switch_ (
@@ -341,46 +393,6 @@ public static function generate(string $namespace, array $clients, SchemaRegistr
341393 ))
342394 );
343395
344- $ class ->addStmt (
345- $ factory ->method ('call ' )->makePublic ()->setDocComment (
346- new Doc (implode (PHP_EOL , [
347- '/** ' ,
348- ' * @return ' . (function (array $ operationCalls ): string {
349- $ count = count ($ operationCalls );
350- $ lastItem = $ count - 1 ;
351- $ left = '' ;
352- $ right = '' ;
353- for ($ i = 0 ; $ i < $ count ; $ i ++) {
354- if ($ i !== $ lastItem ) {
355- $ left .= '($call is ' . $ operationCalls [$ i ]['className ' ] . '::OPERATION_MATCH ? ' . implode ('| ' , array_unique ($ operationCalls [$ i ]['returnType ' ])) . ' : ' ;
356- } else {
357- $ left .= implode ('| ' , array_unique ($ operationCalls [$ i ]['returnType ' ]));
358- }
359- $ right .= ') ' ;
360- }
361- return $ left . $ right ;
362- })($ operationCalls ),
363- ' */ ' ,
364- ]))
365- )->setReturnType (implode ('| ' , array_unique ($ rawCallReturnTypes )))->addParam ((new Param ('call ' ))->setType ('string ' ))->addParam ((new Param ('params ' ))->setType ('array ' )->setDefault ([]))->addStmt (new Node \Stmt \Return_ (
366- new Node \Expr \FuncCall (
367- new Node \Name ('\React\Async\await ' ),
368- [
369- new Node \Arg (
370- new Node \Expr \MethodCall (
371- new Node \Expr \Variable ('this ' ),
372- new Node \Name ('callAsync ' ),
373- [
374- new Node \Arg (new Node \Expr \Variable ('call ' )),
375- new Node \Arg (new Node \Expr \Variable ('params ' )),
376- ]
377- )
378- ),
379- ],
380- )
381- ))
382- );
383-
384396 yield new File ($ namespace . '\\' . 'Client ' , $ stmt ->addStmt ($ class )->getNode ());
385397 }
386398}
0 commit comments