squizlabs / PHP_CodeSniffer

PHP_CodeSniffer tokenizes PHP files and detects violations of a defined set of coding standards.
BSD 3-Clause "New" or "Revised" License
10.68k stars 1.48k forks source link

PSR12.Files.FileHeader.SpacingAfterBlock: false positive when `use` is used for class and function #3935

Closed VladyslavSikailo closed 11 months ago

VladyslavSikailo commented 11 months ago

Describe the bug

PSR12.Files.FileHeader.SpacingAfterBlock check is false positive when use is used for class and function.

Code sample

<?php

namespace Foo;

use Countable;
use function str_replace;

class Test
{
}

To reproduce

Steps to reproduce the behavior:

  1. Create a file called Test.php with the code sample above
  2. Run phpcs -s --standard=PSR12 --no-cache Test.php
  3. See the error message displayed
    -------------------------------------------------------------------------------------------------------------------
    FOUND 1 ERROR AFFECTING 1 LINE
    -------------------------------------------------------------------------------------------------------------------
    5 | ERROR | [x] Header blocks must be separated by a single blank line
    |       |     (PSR12.Files.FileHeader.SpacingAfterBlock)
    -------------------------------------------------------------------------------------------------------------------
    PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
    -------------------------------------------------------------------------------------------------------------------

Expected behavior

Checking should be passed

Versions (please complete the following information)

Operating System MacOS 14.0
PHP version 8.2.6
PHP_CodeSniffer version master
Standard PSR12
Install type Composer (local)

Please confirm:

jrfnl commented 11 months ago

@VladyslavSikailo Not a false positive. PSR12 demands a blank line between different type of use statements, so there should be a blank line between the last class use statement and the first function use statement.

P.S.: for the future, please open new issues in https://github.com/PHPCSStandards/PHP_CodeSniffer - also see #3932