-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Closed
PHPCSStandards/PHP_CodeSniffer
#461Labels
Description
Describe the bug
DNF in properties and as return types creates spurious formatting errors
Code sample
<?php
declare(strict_types=1);
namespace Test;
interface A
{
public function foo(): void;
}
interface B
{
public function bar(): void;
}
class C implements A, B
{
public function foo(): void
{
echo 'foo';
}
public function bar(): void
{
echo 'bar';
}
}
class Dnf
{
protected (A&B)|null $property;
public function getProperty(): (A&B)|null
{
return $this->property;
}
}
To reproduce
Steps to reproduce the behavior:
- Create a file called
test.php
with the code sample above... - Run
phpcs test.php ...
- See error message displayed
FILE: test.php
-------------------------------------------------------------------------------------------------------
FOUND 12 ERRORS AFFECTING 5 LINES
-------------------------------------------------------------------------------------------------------
11 | ERROR | [ ] Each interface must be in a file by itself
16 | ERROR | [ ] Each interface must be in a file by itself
28 | ERROR | [ ] Each class must be in a file by itself
30 | ERROR | [x] Expected at least 1 space before "&"; 0 found
30 | ERROR | [x] Expected at least 1 space after "&"; 0 found
30 | ERROR | [x] Expected at least 1 space before "|"; 0 found
30 | ERROR | [x] Expected at least 1 space after "|"; 0 found
32 | ERROR | [ ] There must be a single space between the colon and type in a return type declaration
32 | ERROR | [x] Expected at least 1 space before "&"; 0 found
32 | ERROR | [x] Expected at least 1 space after "&"; 0 found
32 | ERROR | [x] Expected at least 1 space before "|"; 0 found
32 | ERROR | [x] Expected at least 1 space after "|"; 0 found
-------------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 8 MARKED SNIFF VIOLATIONS AUTOMATICALLY
-------------------------------------------------------------------------------------------------------
Expected behavior
Ignoring the "each interface/class must be in a file by itself" all the rest of the errors marked are NOT errors
and definitely should not be autocorrecting
The single space between colon and type declaration doesn't apparently recognize the parentheses () as part of the type declaration
Versions (please complete the following information):
- OS: all
- PHP: 8.2
- PHPCS: version 4.0.0 (alpha)
- Standard: PSR12
simPod and LastDragon-ru