Skip to content

PSR12.Files.FileHeader blank line error with multiple namespaces in one file #2888

@kwhat

Description

@kwhat

Hi,

Thanks for this amazing tool and your continued support. I have noticed some strange behavior with phpcs --standard=PSR1,PSR2,PSR12 and files that define multiple namespaces in them.

FILE: /home/kwhat/projects/requestful/tests/Unit/Http/ClientTest.php

----------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
----------------------------------------------------------------------
 161 | ERROR | [x] Header blocks must not contain blank lines
----------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------

If I "fixed" this issue by removing the space on line 162, but then I am greeted with a new issue in the same file that was not previously detected.

----------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
----------------------------------------------------------------------
 3 | ERROR | [x] There must be one blank line after the namespace
   |       |     declaration
----------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------

None of the PSR code style specifications make mention of multiple namespaces in a file and don't appear to account for the specific case where one would need to mock a built in php function. I am aware of a couple of tools like runkit that maybe able to work around this, but it seems like a lot of effort to produce a less desirable result. CBF could not fix the file in question so I was wondering if this was the intended behavior of this sniff or an undefined case / side effect.

This maybe related to #2608

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions