Skip to content

Write multi-catch type separators without spaces - #92

Merged
dereuromark merged 1 commit into
masterfrom
catch-type-separator-spacing
Oct 25, 2026
Merged

dereuromark merged 1 commit into
masterfrom
catch-type-separator-spacing

Conversation

@dereuromark

Copy link
Copy Markdown
Contributor

Closes #88

} catch (ValueError | TypeError $e) {   // now: CatchTypeSeparatorSpacing.SpacesAround, fixable
} catch (ValueError|TypeError $e) {     // now: passes
  • New PhpCollective.WhiteSpace.CatchTypeSeparatorSpacing: no whitespace around | in a catch type list, the same rule Universal.Operators.TypeSeparatorSpacing already applies to union types. A separator next to a newline is reported but not auto-fixed.
  • PSR12.Operators.OperatorSpacing is excluded and replaced by PhpCollective.Operators.OperatorSpacing, a subclass that skips catch separators and otherwise reports exactly what the PSR12 sniff did.

Breaking for projects that silence PSR12.Operators.OperatorSpacing or one of its codes in their own ruleset: those reports now come under PhpCollective.Operators.OperatorSpacing.*, so the exclusion has to be renamed. Projects that write catch (A | B $e) get a new, auto-fixable error.

On the 11 catch statements changed by cakephp/cakephp#19740 the fixer output matches the PR, and the PR head passes the full ruleset without silencing anything.

ruleset.xml and docs/sniffs.md are also touched by #91, so whichever PR merges second needs a rebase.

Union and intersection types are enforced without spaces around `|` and
`&`, but the `|` in a multi-catch is tokenized as a bitwise OR, so
PSR12.Operators.OperatorSpacing required `catch (A | B $e)`, the
opposite style.

New PhpCollective.WhiteSpace.CatchTypeSeparatorSpacing reports spaces
around a catch type separator and removes them; a separator next to a
newline is reported but not fixed. PSR12.Operators.OperatorSpacing is
replaced by PhpCollective.Operators.OperatorSpacing, a subclass that
skips catch separators and otherwise behaves the same, including the
skip over declare() statements.
@dereuromark dereuromark added the bug Something isn't working label Oct 25, 2026
Copilot AI balanced review requested due to automatic review settings October 25, 2026 14:02

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

@dereuromark
dereuromark merged commit f0a9f30 into master Oct 25, 2026
2 of 5 checks passed
@dereuromark
dereuromark deleted the catch-type-separator-spacing branch October 25, 2026 14:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Multi-catch pipe: PSR12 OperatorSpacing requires spaces, union types forbid them

2 participants