-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Closed
Description
Describe the bug
CodeSniffer do not distinguishes between "bitwise or" operator and union type.
Code sample
<?php
namespace test;
final class Country
{
private string $code;
public function __construct(string $code)
{
$this->code = $code;
}
public function equals(Country|string $country): bool
{
if ($country instanceof self) {
return $this->code === $country->code;
}
return $this->code === $country;
}
}To reproduce
Steps to reproduce the behavior:
- Create a file called
Country.phpwith the code sample above. - Run
phpcs --standard=PSR12 Country.php - See error message displayed
FILE: Country.php
----------------------------------------------------------------------
FOUND 2 ERRORS AFFECTING 1 LINE
----------------------------------------------------------------------
14 | ERROR | [x] Expected at least 1 space before "|"; 0 found
14 | ERROR | [x] Expected at least 1 space after "|"; 0 found
----------------------------------------------------------------------
PHPCBF CAN FIX THE 2 MARKED SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------
Expected behavior
I expected that error not to be reported, because the union type is not a operator described in PSR12 that needs spaces around it.
Versions (please complete the following information):
- OS: Ubuntu 20.04
- PHP: 8.0.1
- PHPCS: 3.5.8
- Standard: PSR12
jakubkosinski99, bronek89 and dazet
Metadata
Metadata
Assignees
Labels
No labels