Skip to content

Conversation

@dereuromark
Copy link
Member

We cannot declare the returns that strict.
Otherwise, extending classes are impossible to satisfy this when using different array<string, mixed> return keys, e.g.
"code" and others specific to API pushing mailers.

PHPDoc tag @var with type array<string, mixed> is not subtype of type array{headers: string, message: string}.  
         🪪  varTag.type   

so we should not declare concrete keys as only valid ones.

@dereuromark dereuromark added this to the 5.2.7 milestone Aug 21, 2025
@markstory
Copy link
Member

The existing format is for the message that was sent, what other keys and data are you putting in those messages?

@dereuromark
Copy link
Member Author

Yes.
See my description above. Can be other mailer or transport specific key like code (http Status) and alike.

@markstory
Copy link
Member

See my description above. Can be other mailer or transport specific key like code (http Status) and alike.

Ok, I feel like this change is roughly equivalent to replacing a class type with mixed or object. Is there a way we could express the array shape as headers, messages, and more?

@dereuromark
Copy link
Member Author

dereuromark commented Aug 22, 2025

I am not aware if any syntax.
Right now we are limiting the contract artifically to sth like private method scope of exactly only those value keys allowed. Not ideal either.

@dereuromark dereuromark requested a review from Copilot August 22, 2025 10:01
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR relaxes the strict type annotations in the mailer system to improve extensibility for custom transport implementations. The changes address PHPStan compatibility issues when extending mailer classes that need to return additional array keys beyond just 'headers' and 'message'.

  • Updates return type annotations from strict array shapes to generic arrays with mixed values
  • Removes PHPStan-specific type annotations that were too restrictive for inheritance
  • Modifies parameter type hints to match the more flexible return types

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
src/TestSuite/TestEmailTransport.php Updates send() method return type from strict array shape to generic array
src/Mailer/Mailer.php Relaxes return types for send(), deliver(), and logDelivery() methods
src/Mailer/AbstractTransport.php Updates abstract send() method return type to allow extensible implementations

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@dereuromark dereuromark force-pushed the fix-return-documentation branch from 992de60 to 297d115 Compare August 22, 2025 12:43
@dereuromark
Copy link
Member Author

OK, turns out there is a way to keep it "open" for exendability.

@dereuromark dereuromark changed the title Fix mailer to be extendable. 5.x Fix methods to be extendable. Aug 22, 2025
@dereuromark dereuromark added the needs squashing The pull request should be squashed before merging label Aug 22, 2025
@markstory markstory merged commit cf7ef2f into 5.x Aug 22, 2025
13 checks passed
@markstory markstory deleted the fix-return-documentation branch August 22, 2025 19:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation needs squashing The pull request should be squashed before merging

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants