Skip to content

Add handling for compound types. #45

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jan 20, 2025
Merged

Conversation

Crell
Copy link
Collaborator

@Crell Crell commented Sep 12, 2022

There's likely to be discussion on this, but this PR gets us started. Discuss.

@Crell Crell mentioned this pull request Sep 12, 2022
25 tasks
function veryComplex(
array
|(ArrayAccess&Traversable)
|(Traversable&Countable) $input): ArrayAccess&Traversable
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
|(Traversable&Countable) $input): ArrayAccess&Traversable
|(Traversable&Countable) $input
): ArrayAccess&Traversable

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Hm. Not sure here. Does this context also force multilining the return part? If so, that should be said explicitly somewhere.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah doing this would split the argument list over multiple lines and would make "argument list is split across multiple lines" rules apply here. I get that this is different than actually splitting each argument onto their own lines but I don't think that distinction matters at all when it comes to readability and consistency.

Copy link
Contributor

@KorvinSzanto KorvinSzanto left a comment

Choose a reason for hiding this comment

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

Needs:

  • Consistency with catch() or an argument for not being consistent
  • Consistency with mutliline declaration requirements

@KorvinSzanto
Copy link
Contributor

I think the catch consistency question is a big one so I've opened a vote in discord for the WG to decide the way to move forward.

@Crell
Copy link
Collaborator Author

Crell commented Sep 3, 2024

A while back, I put out a Mastodon poll on this. Not exactly scientific, but probably the best we've got.

https://phpc.social/@Crell/112496711448592596

That poll at least comes out 60/40 in favor of no-space. (Some interesting comments either way in the replies.)

Symfony, doesn't make an explicit stance, but their examples also show no-space (link courtesy Ben Ramsey):

https://symfony.com/doc/current/contributing/code/standards.html

And the default configuration for php-cs-fixer also defaults to no-space:

https://cs.symfony.com/doc/rules/whitespace/types_spaces.html#rule-sets

Laravel doesn't say explicitly either, but its examples have no-space in compound types in the docblock:

https://laravel.com/docs/11.x/contributions#coding-style

Based on that, I am strongly leaning toward requiring no-space for compound types, as the PR currently does. And then probably changing union-catch to match.

WG members (only): Yay 👍 or nay 👎, based on the above?

@Jean85
Copy link
Member

Jean85 commented Sep 4, 2024

Symfony, doesn't make an explicit stance, but their examples also show no-space (link courtesy Ben Ramsey):

https://symfony.com/doc/current/contributing/code/standards.html

And the default configuration for php-cs-fixer also defaults to no-space:

https://cs.symfony.com/doc/rules/whitespace/types_spaces.html#rule-sets

I should note that the latter is surely causing the former, since Symfony uses PHP-CS-Fixer for its code (it even has a dedicated preset).

@samdark
Copy link
Member

samdark commented Sep 4, 2024

No-space is used in Yii as well.

@Crell
Copy link
Collaborator Author

Crell commented Jan 4, 2025

Based on the above research and lack of objection to it, we will proceed with this PR (which I just rebased) unless I hear an articulated objection in the next week or so.

@KorvinSzanto Please unblock the PR. 😄

@kenguest
Copy link
Contributor

kenguest commented Jan 8, 2025

Overall consistency is important, so I would expect the later revision of PER-CS to disallow spaces around "|" for catch statements.

Copy link
Contributor

@KorvinSzanto KorvinSzanto left a comment

Choose a reason for hiding this comment

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

I have to approve to remove my request for changes, but I believe this needs to be a 3.0 change given that we're modifying catch

@Crell Crell merged commit 7ce5844 into php-fig:master Jan 20, 2025
@Crell Crell deleted the compound-types branch January 20, 2025 23:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants