Open
Description
Describe the bug
PSR12.Operators.OperatorSpacing produces false positives on type alternatives in catch clause.
Code sample
<?php
try {
} catch (A|B $exception) {
}
To reproduce
Steps to reproduce the behavior:
- Create a file called
test.php
with the code sample above... - Run
phpcs -s --standard=PSR12 test.php
- See error message displayed
FILE: /tmp/tmp.0QHXuAapol/foo.php
---------------------------------------------------------------------------------------------------------------
FOUND 2 ERRORS AFFECTING 1 LINE
---------------------------------------------------------------------------------------------------------------
4 | ERROR | [x] Expected at least 1 space before "|"; 0 found
| | (PSR12.Operators.OperatorSpacing.NoSpaceBefore)
4 | ERROR | [x] Expected at least 1 space after "|"; 0 found
| | (PSR12.Operators.OperatorSpacing.NoSpaceAfter)
---------------------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 2 MARKED SNIFF VIOLATIONS AUTOMATICALLY
---------------------------------------------------------------------------------------------------------------
Expected behavior
No error, since the pipe character in the code is not an operator. This already works as expected for function declarations, i.e. this is fine:
<?php
function f(A|B $x)
{
}
Versions (please complete the following information):
- OS: Fedora 53
- PHP: 8.0
- PHPCS: 3.7.1
- Standard: PSR12
Metadata
Metadata
Assignees
Labels
No labels