Skip to content
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

Operator spacing union types / multi-catch expressions #67

Open
jrfnl opened this issue Mar 2, 2023 · 3 comments
Open

Operator spacing union types / multi-catch expressions #67

jrfnl opened this issue Mar 2, 2023 · 3 comments

Comments

@jrfnl
Copy link
Contributor

jrfnl commented Mar 2, 2023

I believe some clarification is needed about the spacing requirements around the | operator when used in the following two situations:

  • Union types
  • Multi-catch statements

At this moment, most coding standards I'm aware of use "no spaces around the | operator" as a rule for union types.

However, multi-catch statements predate union types and the example in section 5.6 had spaces around the | operator.
PHPCS has taken the literal interpretation based on the example and expects one space on either side of the | operator in multi-catch statements.
CS-Fixer treats the | in multi-catch as if it were a union type, expecting no spaces.

End-users are confused ;-/

Ref: squizlabs/PHP_CodeSniffer#3663

@KorvinSzanto
Copy link
Contributor

See #45

We have some issues around consistency that won't be resolved before v2.0.0 in catch (Foo|Bar $e) and what syntax looks like in multiline function declarations.
In the meantime I'd just pick the paradigm that makes the most sense to you and stick to it, if the spec disagrees with your choice in the future this is a relatively safe bit of syntax to update with a static analysis tool.

@jrfnl
Copy link
Contributor Author

jrfnl commented Mar 2, 2023

Thanks for that link, I'll read up on the discussion.

In the meantime I'd just pick the paradigm that makes the most sense to you and stick to it, if the spec disagrees with your choice in the future this is a relatively safe bit of syntax to update with a static analysis tool.

For context: I'm not asking for me/my own code. I'm asking as a maintainer of/contributor to various PHPCS standards (i.e. as someone having to field support questions about this).

@ijesneo611
Copy link

I believe some clarification is needed about the spacing requirements around the | operator when used in the following two situations:

  • Union types
  • Multi-catch statements

At this moment, most coding standards I'm aware of use "no spaces around the | operator" as a rule for union types.

However, multi-catch statements predate union types and the example in section 5.6 had spaces around the | operator.
PHPCS has taken the literal interpretation based on the example and expects one space on either side of the | operator in multi-catch statements.
CS-Fixer treats the | in multi-catch as if it were a union type, expecting no spaces.

End-users are confused ;-/

Ref: squizlabs/PHP_CodeSniffer#3663

nonver2. 0_1.0

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

No branches or pull requests

3 participants