php-fig / per-coding-style

PER coding style
259 stars 26 forks source link

Operator spacing union types / multi-catch expressions #67

Open jrfnl opened 1 year ago

jrfnl commented 1 year ago

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

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: https://github.com/squizlabs/PHP_CodeSniffer/issues/3663

KorvinSzanto commented 1 year ago

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 commented 1 year ago

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 commented 8 months ago

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: https://github.com/squizlabs/PHP_CodeSniffer/issues/3663

nonver2. 0_1.0