Skip to content

Enforce proper return types for methods/functions get_order_from_event_body_intent_id #4293

Open

Description

Description

Based on this convo #4287 (review)

It's more than one time we see fatal errors due to mixed return types.

In this specific case #4287, get_order_from_event_body_intent_id returns a few types:

* @return boolean|WC_Order|WC_Order_Refund
*/
private function get_order_from_event_body_intent_id( $event_body ) {

But when a new code is added - ref, it misses checking the proper type before using it.

Acceptance criteria

  • Update/refactor get_order_from_event_body_intent_id to return less types. Ideally, it would be null | WC_Order, and ensure their consumers process_webhook_payment_intent_failed and process_webhook_payment_intent_succeeded properly check their types before using.
  • (Maybe) Check other functions to enforce the same. It's worth checking if PHPCS or Psalm can enforce or prevent this issue.

Dev notes

IIRC, Psalm is pretty smart in detecting types and it can prevent this type of issues. Quickly found out this post https://psalm.dev/articles/php-or-type-safety-pick-any-two

Additional context

This may fit into the RFC improving the plugin code quality paJDYF-3eh-p2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions