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.ImportStatement should not apply to traits #2665

Closed
chrisminett opened this issue Oct 24, 2019 · 1 comment
Closed

PSR12.Files.ImportStatement should not apply to traits #2665

chrisminett opened this issue Oct 24, 2019 · 1 comment

Comments

@chrisminett
Copy link

The PSR12.Files.ImportStatement sniff is being applied to use statements within a class, where they are used to implement traits. The sniff should not be applied in this scenario.

The PSR-12 documentation in section 3 applies to import statements before the class definition as described in the list at the top of the section (class-based, function-based, constant-based).

Traits are documented separately in section 4.2 and describe the requirements for the use keyword to implement traits, but does not require that the value does not start with a backslash.

h2. Current behaviour

<?php

namespace MyNamespace;

class MyClass
{
    use \MyTrait;
}
 $ phpcs --standard=PSR12 test.php                                                                     -1-

FILE: test.php
---------------------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
---------------------------------------------------------------------------------
 7 | ERROR | Import statements must not begin with a leading backslash
---------------------------------------------------------------------------------

h2. Expected behaviour

With the same example, no error is found.

@gsherwood gsherwood added this to Idea Bank in PHPCS v3 Development via automation Oct 24, 2019
@gsherwood gsherwood added this to the 3.5.2 milestone Oct 24, 2019
@gsherwood
Copy link
Member

Thanks for reporting this. Fix will be in 3.5.2.

PHPCS v3 Development automation moved this from Idea Bank to Ready for Release Oct 24, 2019
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