-
Notifications
You must be signed in to change notification settings - Fork 31
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
Warning about "unused code after RETURN." #40
Comments
Yes, I've already had some false positives with this rule. The analysis done is too simple. This is where a real AST could help a lot. |
I'd say that #32 is related to this. |
https://github.com/nikic/PHP-Parser I found decent AST, but it ignores whitespace. Apparently, there is an issue for this but it hasn't been worked on for two years. |
@rr- I'm going to try and spend a bit of time looking at PHP-Parser if I can. The introduction says:
The bit I'm interested is in bold. So |
Another way to go may be to look at how Scrutinzer works. |
Yes, using tokenizer would be cool to do checks like whitespace around operators, etc. In each use case, I'd go with whatever makes the code most maintainable. Note that If implemented carefully, it probably would decrease size of existing codebase twofold without breaking current functionality, which is a good thing. |
PHPCheckstyle does add some missing tokens in to account for those which aren't included. I've started a new branch which you're more than welcome to contribute to. |
As an additional consideration, it should be added that the php-parser is much slower than token_get_all. I don't know how much slower off the top of my head, but at least 10 times. So including it is probably only worth the slowdown if you're going to do multiple complex inspections. It's possible to switch from the syntax tree to the underlying tokens with a bit of extra code. By using a custom token offset lexer you can get the start and end offsets for a particular AST node in the token array. I'm using this approach to inspect the exact formatting of a node or do changes to code without breaking formatting. Sadly I don't have open-source examples for this right now. |
I confirm that currently PHPCheckstyle use token_get_all() with some modifications to take into account spaces, tabs and carriage return and to count the line returns in the inlined HTML. I've been very interested in PHP-Parser for a long time (thanks nikic, it's a nice job you've done) but no time to try to implement something. We should also followx what will happend with PHP 7 and its AST. |
Consider this example:
PHPCheckstyle warns me about it:
even though it isn't true. To make the warning go away, I need to refactor the code like this:
The text was updated successfully, but these errors were encountered: