Skip to content

[php] Fix PHPDoc so that UnaryCall defines the proper return type#37563

Closed
sayuprc wants to merge 5 commits intogrpc:masterfrom
sayuprc:typing-support-for-php
Closed

[php] Fix PHPDoc so that UnaryCall defines the proper return type#37563
sayuprc wants to merge 5 commits intogrpc:masterfrom
sayuprc:typing-support-for-php

Conversation

@sayuprc
Copy link
Copy Markdown
Contributor

@sayuprc sayuprc commented Aug 23, 2024

Type information is added to the result of UnaryCall::wait() execution.

resolve #33431

@linux-foundation-easycla
Copy link
Copy Markdown

linux-foundation-easycla bot commented Aug 23, 2024

CLA Signed

The committers listed above are authorized under a signed CLA.

@sayuprc sayuprc marked this pull request as ready for review August 23, 2024 17:20
@sayuprc sayuprc marked this pull request as draft August 24, 2024 08:13
@sayuprc sayuprc force-pushed the typing-support-for-php branch from e2a3756 to 06ec922 Compare August 24, 2024 13:26
@sayuprc sayuprc force-pushed the typing-support-for-php branch from 692e91e to 6e5aa44 Compare August 24, 2024 13:32
@sayuprc sayuprc marked this pull request as ready for review August 24, 2024 13:43
Copy link
Copy Markdown
Contributor

@bshaffer bshaffer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great, but we also need some tests for the generated output

" * @param array $$options call options\n"
" * @return $return_type_id$\n */\n"
"public function $name$(\\$input_type_id$ $$argument,\n"
" $$metadata = [], $$options = []) {\n");
Copy link
Copy Markdown
Contributor

@bshaffer bshaffer Sep 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like all the code duplication this presents - why not do something like this instead? Then you'd only have to change a single line of code

    if (method->server_streaming()) {
      vars["return_type_id"] = "\\Grpc\\ServerStreamingCall";
    } else {
      vars["return_type_id"] = "\\Grpc\\UnaryCall<" + $vars["input_type_id"] + ">";
    }
    out->Print(vars,
               " * @param \\$input_type_id$ $$argument input argument\n"
               " * @param array $$metadata metadata\n"
               " * @param array $$options call options\n"
               " * @return $return_type_id$\n */\n"
               "public function $name$(\\$input_type_id$ $$argument,\n"
               "  $$metadata = [], $$options = []) {\n");

@sayuprc
Copy link
Copy Markdown
Contributor Author

sayuprc commented Sep 18, 2024

@bshaffer

Thank you for your review.
I will make the corrections you pointed out and add the necessary tests.

I have one question, though—I wasn't sure where to place the test code.
For the changes I made this time, where would be the correct location to place the test code?

@bshaffer
Copy link
Copy Markdown
Contributor

@sayuprc you just need to follow the instructions in src/php/README.md to run the tests, and then run src/php/bin/generate_proto_php.sh to update the Grpc Client classes. You should get something like this:

bshaffer@d3cf6db

@sayuprc
Copy link
Copy Markdown
Contributor Author

sayuprc commented Sep 19, 2024

@bshaffer
Thank you for the thorough explanation.
I will give it a try.

@sayuprc sayuprc requested a review from bshaffer September 19, 2024 14:55
@bshaffer
Copy link
Copy Markdown
Contributor

This is looking great! I'm not sure what's up with that "NO CHECK IN GEN CODE", though. We will need to look into that.

@stanley-cheung what do you think?

@sayuprc
Copy link
Copy Markdown
Contributor Author

sayuprc commented Oct 29, 2024

I apologize for the delayed response.

Regarding # NO CHECKED-IN PROTOBUF GENCODE appearing in the diff, I thought it might be related to this commit: protocolbuffers/protobuf@c668e2e
However, I wasn’t able to understand much beyond that.

What should I do?

@veblush veblush requested review from stanley-cheung and removed request for bshaffer October 29, 2024 19:52
@Nyholm
Copy link
Copy Markdown
Contributor

Nyholm commented Mar 16, 2025

This is simply amazing. Is there anything I can do to help getting this merged?

@bshaffer
Copy link
Copy Markdown
Contributor

Messaging here for visibility is very helpful @Nyholm ! It's just waiting on me or @stanley-cheung to approve and merge.

@stanley-cheung stanley-cheung added release notes: yes Indicates if PR needs to be in release notes kokoro:run labels Jun 24, 2025
@stanley-cheung
Copy link
Copy Markdown
Contributor

stanley-cheung commented Jun 24, 2025

Sorry, there's some clang format diff here, do you mind fixing that? Thanks

--- /var/local/git/grpc/src/compiler/php_generator.cc	2025-06-24 18:31:09.427418725 +0000
+++ /tmp/tmp.UMLUXWZXww	2025-06-24 18:38:18.370327357 +0000
@@ -108,7 +108,8 @@
     if (method->server_streaming()) {
       vars["return_type_id"] = "\\Grpc\\ServerStreamingCall";
     } else {
-      vars["return_type_id"] = "\\Grpc\\UnaryCall<\\" + vars["output_type_id"] + ">";
+      vars["return_type_id"] =
+          "\\Grpc\\UnaryCall<\\" + vars["output_type_id"] + ">";
     }
     out->Print(vars,
                " * @param \\$input_type_id$ $$argument input argument\n"

You may be able to just run ./tools/distrib/clang_format_code.sh

@stanley-cheung stanley-cheung changed the title Fix PHPDoc so that UnaryCall defines the proper return type [php] Fix PHPDoc so that UnaryCall defines the proper return type Jun 24, 2025
@sayuprc
Copy link
Copy Markdown
Contributor Author

sayuprc commented Jun 24, 2025

@stanley-cheung
Thanks for the review!
I fixed the format.

@stanley-cheung
Copy link
Copy Markdown
Contributor

This has been merged. Thanks for the contributions. This will be part of the next 1.74.0 release which will happen in the next couple of weeks.

* Wait for the server to respond with data and a status.
*
* @return array [response data, status]
* @return array{0: T|null, 1: stdClass} [response data, status]
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sayuprc shouldn't stdClass be imported or used as \stdClass under a namespace?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your feedback. You are correct—I'll make the necessary changes and open a PR.

anniefrchz pushed a commit to anniefrchz/grpc that referenced this pull request Jun 25, 2025
…pc#37563)

Type information is added to the result of `UnaryCall::wait()` execution.

resolve grpc#33431

<!--

If you know who should review your pull request, please assign it to that
person, otherwise the pull request would get assigned randomly.

If your pull request is for a specific language, please add the appropriate
lang label.

-->

Closes grpc#37563

COPYBARA_INTEGRATE_REVIEW=grpc#37563 from sayuprc:typing-support-for-php 0f1e6b2
PiperOrigin-RevId: 775541985
copybara-service bot pushed a commit that referenced this pull request Jun 25, 2025
This PR addresses the following review comment: #37563 (comment)

Changed `stdClass` to `\stdClass` to explicitly reference the global namespace.

<!--

If you know who should review your pull request, please assign it to that
person, otherwise the pull request would get assigned randomly.

If your pull request is for a specific language, please add the appropriate
lang label.

-->

Closes #39996

COPYBARA_INTEGRATE_REVIEW=#39996 from sayuprc:use-global-namespace ea680d1
PiperOrigin-RevId: 775872442
paulosjca pushed a commit to paulosjca/grpc that referenced this pull request Aug 23, 2025
…pc#37563)

Type information is added to the result of `UnaryCall::wait()` execution.

resolve grpc#33431

<!--

If you know who should review your pull request, please assign it to that
person, otherwise the pull request would get assigned randomly.

If your pull request is for a specific language, please add the appropriate
lang label.

-->

Closes grpc#37563

COPYBARA_INTEGRATE_REVIEW=grpc#37563 from sayuprc:typing-support-for-php 0f1e6b2
PiperOrigin-RevId: 775541985
paulosjca pushed a commit to paulosjca/grpc that referenced this pull request Aug 23, 2025
This PR addresses the following review comment: grpc#37563 (comment)

Changed `stdClass` to `\stdClass` to explicitly reference the global namespace.

<!--

If you know who should review your pull request, please assign it to that
person, otherwise the pull request would get assigned randomly.

If your pull request is for a specific language, please add the appropriate
lang label.

-->

Closes grpc#39996

COPYBARA_INTEGRATE_REVIEW=grpc#39996 from sayuprc:use-global-namespace ea680d1
PiperOrigin-RevId: 775872442
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Typing support for grpc-php

7 participants