Skip to content

PSR12.Operators.OperatorSpacing and PHP 8.0 union types #3151

@rask

Description

@rask

Describe the bug
When using the PSR-12 implementation that ships with PHP_CodeSniffer, I cannot use union types as described in RFCs and other official or semi-official documentation.

Code sample

function foo(int|float $val) : void
{
     //
}

Custom ruleset

<?xml version="1.0"?>
<ruleset name="My Custom Standard">
    <rule ref="PSR12" />
</ruleset>

To reproduce
Steps to reproduce the behavior:

  1. Lint the file while running PHP 8.0 so you can use union types
  2. Get greeted with PSR12.Operators.OperatorSpacing errors (either NoSpaceBefore or NoSpaceAfter):
ERROR | [x] Expected at least 1 space after "|"; 0 found

Expected behavior
I would expect to be able to use PSR-12 operator spacing lints without it complaining about union type delimiters, as those to my understanding are not actually operators.

Versions (please complete the following information):

  • OS: Linux Ubuntu
  • PHP: 8.0 RC 1
  • PHPCS: Latest 3.5 stable
  • Standard: PSR12

Additional context
N/A

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions