Open
Description
openedon May 26, 2022
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:
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 benull | WC_Order
, and ensure their consumersprocess_webhook_payment_intent_failed
andprocess_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