-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Support for group use declaration (PHP7) #878
Comments
Edit: There is already code for that. It's something else. For the use declaration error, I don't think I can fix that. PSR2 is pretty clear about having one declaration per line, so they would need some errata to change that rule and allow for PHP7 syntax, if they want that to be allowed. But as you've said, you can ignore it in your ruleset. |
The issues are actually caused by the curly braces being assigned to the |
I've assigned the curly braces new tokens so there is no confusion with sniffs and the tokenizer. It also lets sniffs detect this syntax and apply coding standards to it more easily. |
Excellent, thanks 🙏 |
Did this ever get done and released? I'm on 2.6.1 and php-cs is certainly unhappy with my grouped imports. |
If it is unhappy for reasons like If you are getting brace or side effect errors, then please let me know as these should be fixed and the unit tests are currently passing. |
Apologies, I misunderstood your previous comments on what exactly was fixed. I'm not getting any undue errors due to parsing, PHP-CS is indeed applying PSR-2 correctly in this case. |
No problem. Thanks for getting back to me so quickly. |
With respect to PSR-2, I wonder if there is still more to do here. Specifically around the fixer code. As of 2.6.2, the fixer still seems to corrupt PHP 7 grouped I'm considering a patch that determines if the following token is a grouped use curly and, if so, expands the grouped declaration to individual |
@jasonmccreary I wasn't aware there was an issue (but there clearly is) so I'd be very happy to look at any PR to fix this. |
Cool. I'll submit something tomorrow as I have a need for it anyway and am happy to give back to this excellent tool. |
Thanks a lot. If you get stuck, just open an issue and we can discuss options. |
Changed title of incorrect issue - please ignore |
Has this issue been fully resolved and as part of the update for code sniffer. Thanks everyone |
This issue was resolved via a PR and released in version 2.6.0. The current stable version is 2.8.1, so it's been around for a few releases. |
Hi everyone, Example.php
I ran command phpcs version is 3.0.1 (stable) Please advice on this. |
@nsaumini the problem is not in phpcs. There's no provision in PSR2 for grouped imports, hence phpcs correctly calling out on their usage. |
@luispabon Noted thanks. |
PSR are working on a new coding style extending PSR2 btw, hopefully it'll be accepted/published soonish: https://github.com/php-fig/fig-standards/blob/master/proposed/extended-coding-style-guide.md That'd include a lot of new stuff that came in on PHP7. |
There's only hope left, or we've got any information when it will be published :D ? |
any info on this? |
in your ruleset.xml resolves a problem while we waiting for update :) |
I am using that already, thanks @agriboed |
Anyone solved this apart from the exclude pattern above? PHP 7 has been out for a little while now... |
I'm using it for now, to no write directly the |
With PHP 7:
Source + example code.
Using the PSR2 Standard, the following happens (sample output):
I can get rid of the
one USE keyword
error excludingPSR2.Namespaces.UseDeclaration
. I can also work around the side effects warning excludingPSR1.Files.SideEffects
, though not ideal.However, I have no idea how work around the closing brace error, and I don't want to exclude that rule since I still want it to apply on the rest of the code.
Is there a clean way to work around this issue ?
The text was updated successfully, but these errors were encountered: