Skip to content

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

Closed

Description

@dereuromark

Union and intersection types are written without spaces (Universal.Operators.TypeSeparatorSpacing), but a multi-catch has to keep them:

} catch (ValueError | TypeError $e) {   // passes
} catch (ValueError|TypeError $e) {     // PSR12.Operators.OperatorSpacing.NoSpaceBefore + NoSpaceAfter

TypeSeparatorSpacing doesn't look at catch, and the PSR12.Operators.OperatorSpacing the ruleset inherits treats the | as a bitwise operator. php-cs-fixer's @PER-CS3x0 set writes it like a union type, with no spaces. cakephp/cakephp#19740 had to silence both PSR12 codes in its phpcs.xml for exactly this, and that also silenced them for real bitwise operators.

Proposal: treat the | in a catch type list like a union type separator. No spaces, fixable, and the PSR12 sniff skips it.

Activity

  1. XRafik commented on Oct 25, 2026

    @XRafik

    Proposed here as PR #94: a repo-owned OperatorSpacing extending the PSR12 sniff keeps every inherited check and treats the catch-list | like a union type separator (no spaces, fixable), so the inherited NoSpaceBefore/NoSpaceAfter no longer fire on it. The catch parenthesis owner identifies the context, so real bitwise operators in the catch body keep their spacing rule. Unit tests + PHPStan level 8 + the repo cs-check are clean.

  2. dereuromark commented on Oct 26, 2026

    @dereuromark
    ContributorAuthor

    Thx anyway!
    You are using the sniffer rules too?

  3. XRafik commented on Oct 26, 2026

    @XRafik

    Yes. The new sniff extends the repo's own PSR12 OperatorSpacing sniff, so every inherited check stays on and only the catch-list | rule changes. The PR code was also run through the repo cs-check and PHPStan level 8 before pushing, both clean.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions