-
Notifications
You must be signed in to change notification settings - Fork 15
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
False positives #228
Comments
Thanks for the reports! Let's take them one at a time.
This is a tricky one. The issue is that the only way we can know the file-scoped The reason you saw this report as a regression was probably because 2.10 has much better scope detection, and finally supports the file-level scope (as of #190). If you're going to be using a lot of global variables, you might want to enable the allowUndefinedVariablesInFileScope option so those will be ignored (at least, I think they will... I wonder if we need another option to allow unused variables in file scope too).
That does sound like a bug, but I've so far been unable to reproduce it. I created a file called
Then I ran |
I realized that there's no complete way to disable scope detection for the global scope. |
The exact code is
throwing a A bit convoluted I know, it’s old code. Maybe you can recreate the problem with that one. |
Another example:
throws an |
And another one:
throws |
Thank you for the examples! With the first one I was able to reproduce the error where if($q = getData())
echo $q;
else
echo $q->asXML(); // $q is reported as undefined That doesn't happen with curly braces, though: if($q = getData()) {
echo $q;
} else {
echo $q->asXML(); // no warnings
} So this is a bug that has something to do with scope detection and inline conditional blocks. I tried the other examples you gave, however, and I was not able to get the same results. Maybe the actual warning was coming from some use that's part of the excluded code? In any case, let me try to fix the regression above and we'll see if it solves the other reports you're seeing. |
I found it. Could you give v2.10.3-beta.1 a try to see if it resolves your issues? https://github.com/sirbrillig/phpcs-variable-analysis/releases/tag/v2.10.3-beta.1 |
Since I haven't heard anything, I'll assume this issue is resolved. Please let me know if not! |
After upgrading from v2.9.0 to v2.10.2 I got a lot of false positives and I had to downgrade again. For example:
causes a
VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
.Also
causes a
VariableAnalysis.CodeAnalysis.VariableAnalysis.UndefinedVariable
.The text was updated successfully, but these errors were encountered: