/src/Standards/PSR12/Sniffs/Traits/UseDeclarationSniff.php ignores block comments.
For example this will cause the The first trait import statement must be declared on the first non-comment line after the class opening brace error to be shown:
class MyClass
{
/*
some comment
*/
use RegistersUsers;
while this will not:
class MyClass
{
use RegistersUsers;
/*
some comment
*/
This issue is triggered in recent Laravel versions: https://github.com/laravel/laravel/blob/master/app/Http/Controllers/Auth/ConfirmPasswordController.php#L22
class Foo implements Bar
{
/**
* Comment here;
*/
/**
* Another Comment here;
*/
use Baz;
}
Is also reported as an error.
This issue is triggered in recent Laravel versions: https://github.com/laravel/laravel/blob/master/app/Http/Controllers/Auth/ConfirmPasswordController.php#L22
I think the error is correctly reported for recent Laravel versions since there is a blank line.
I think the error is correctly reported for recent Laravel versions since there is a blank line.
That's true, but only half the story. phpcbf fixes that by removing the blank line, but it then runs into this exact problem.
I think the error is correctly reported for recent Laravel versions since there is a blank line.
That's true, but only half the story. phpcbf fixes that by removing the blank line, but it then runs into this exact problem.
Indeed. My PR can fix the second half of the story by fixing the false positive error for.
class Foo implements Bar
{
/**
* Comment here;
*/
/**
* Another Comment here;
*/
use Baz;
}
Can confirm that the PR fixes the original issue, and also sorts out that Laravel issue (the blank line should be removed, but no error should then be reported).
I think the error is correctly reported for recent Laravel versions since there is a blank line.
That's true, but only half the story. phpcbf fixes that by removing the blank line, but it then runs into this exact problem.
Same thing still happening to me... phpcbf 'fixed' (removed) the empty line between the comments and the Trait declaration but phpcs keeps showing an error on the file:
ERROR | [x] The first trait import statement must be declared on the first non-comment line after the class opening brace