Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
kwhat opened this issue Mar 3, 2020 · 2 comments
Closed

Comments

@kwhat
Copy link

kwhat commented Mar 3, 2020

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

@gsherwood
Copy link
Member

Sample code to reproduce:

namespace Foo {

    use Baz;

}

namespace Bar {

    use Baz;

}

@gsherwood gsherwood added this to Idea Bank in PHPCS v3 Development via automation Mar 8, 2020
@gsherwood gsherwood added this to the 3.5.6 milestone Mar 8, 2020
kwhat added a commit to kwhat/requestful that referenced this issue Mar 12, 2020
@gsherwood gsherwood moved this from Idea Bank to Selected for Development in PHPCS v3 Development May 21, 2020
@gsherwood gsherwood changed the title Couple of interesting observations with multiple namespaces in one file PSR12.Files.FileHeader blank line error with multiple namespaces in one file Jun 22, 2020
gsherwood added a commit that referenced this issue Jun 22, 2020
@gsherwood
Copy link
Member

This has been fixed by assuming the file header is complete when a bracketed statement is found. The fix will be in 3.5.6. Thanks for reporting the bug.

PHPCS v3 Development automation moved this from Selected for Development to Ready for Release Jun 22, 2020
gsherwood added a commit that referenced this issue Jul 21, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
PHPCS v3 Development
Ready for Release
Development

No branches or pull requests

2 participants