-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Inconsistent behavior of PHP_CodeSniffer_File::findEndOfStatement #1203
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
Comments
First, the For the method itself, the goal is to find the end of the statement, which is typically a semicolon. But when you are within a different scope, like an array, there is no semicolon to return as the ending. If it returns the Hope that makes sense. |
I've fixed the method to ensure the two array formats return the same result. |
The problem is that here:
findEndOfStatement returns I had to duplicate I also don't understand why it returns on My sniff on the other hand finds all object creation expressions, and since they could be in most of the positions that findEndOfStatement deals with, the inconsistent behavior caused problems. E.g. the first version did this:
|
PHP_CodeSniffer_File::findEndOfStatement sometimes returns end token, but sometimes it returns the last not empty token before that.
E.g. if
$start
isnew
:[new Datetime]
it returns]
.array(new Datetime)
it returnsDatetime
.new Datetime;
it returns;
.The difference between
array()
and[]
is probably a mistake, because[]
was added later in 4df216f, but I don't understand why there's a difference at all.The examples above are from a sniff that adds
()
tonew
. If findEndOfStatement consistently returned the last non-empty statement (like it does forarray(new Datetime)
), I could insert the()
after that.The text was updated successfully, but these errors were encountered: