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

Undefined offset in Squiz.Strings.ConcatenationSpacing during live coding #2988

Merged
merged 2 commits into from
Sep 21, 2020
Merged

Undefined offset in Squiz.Strings.ConcatenationSpacing during live coding #2988

merged 2 commits into from
Sep 21, 2020

Conversation

thiemowmde
Copy link
Contributor

This can happen when PHPCS runs on a file that is currently being worked on, but not yet completed. The file might end with a dot. We can not assume there are always 2 more tokens after a dot.

This can happen when PHPCS runs on a file that is currently being worked on, but not yet completed. The file might end with a dot. We can not assume there are always 2 more tokens after a dot.
Copy link
Contributor

@jrfnl jrfnl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @thiemowmde I see what you are trying to do here. I'd like to suggest a change though, and that is to bow out completely when $tokens[($stackPtr + 1)] isn't set as doing any checking for the space after the concatenation operator if there isn't a next token is futile.

What do you think ?

@thiemowmde
Copy link
Contributor Author

Nice catch. Indeed, my original proposal would create awkward reports that don't make much sense if the line of code is not even complete. I changed it to don't report anything in such a situation.

@jrfnl
Copy link
Contributor

jrfnl commented Jun 17, 2020

I changed it to don't report anything in such a situation.

That's not what I intended. The "spacing before" could still be safely reported/fixed in that case. It's only the spacing after where the problem lies.

@thiemowmde
Copy link
Contributor Author

There is no separate message for "spacing before". There are only messages that talk about "Concat operator must [not] be surrounded by …". All these messages are confusing when the line of code that ends with something like $s = '…' . is not even complete. Sure, we could introduce separate messages that only talk about the "spacing before" in such a situation. But that would be quite some overkill.

@jrfnl
Copy link
Contributor

jrfnl commented Jun 17, 2020

@thiemowmde You're right. Sorry, I was getting confused by the metrics which are recorded separately
Bit surprising nonetheless as most of these types of sniffs would have separate error codes, but as this one doesn't, I agree, no need to change that at this time.

@gsherwood gsherwood added this to the 3.5.7 milestone Sep 21, 2020
@gsherwood gsherwood changed the title Fix rare undefined offset errors in ConcatenationSpacingSniff Undefined offset in Squiz.Strings.ConcatenationSpacing during live coding Sep 21, 2020
gsherwood added a commit that referenced this pull request Sep 21, 2020
@gsherwood gsherwood merged commit e8bdb51 into squizlabs:master Sep 21, 2020
@gsherwood
Copy link
Member

Thanks a lot for this PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants