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

Sniff::is_in_isset_or_empty(): improve code-style independence #1468

Merged

Conversation

jrfnl
Copy link
Member

@jrfnl jrfnl commented Aug 28, 2018

Includes unit tests in the ValidatedSanitizedInput test case file.

Relates to #763

Includes unit tests in the ValidatedSanitizedInput test case file.
@jrfnl jrfnl force-pushed the feature/is_in_isset_or_empty-codestyle-independence branch from 9cdf7ad to b4b50a6 Compare August 28, 2018 02:12
@@ -1505,7 +1505,8 @@ protected function is_in_isset_or_empty( $stackPtr ) {
end( $nested_parenthesis );
$open_parenthesis = key( $nested_parenthesis );

return \in_array( $this->tokens[ ( $open_parenthesis - 1 ) ]['code'], array( \T_ISSET, \T_EMPTY ), true );
Copy link
Member

Choose a reason for hiding this comment

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

So when looking for code-style assumptions, a good starting point is $this->tokens[ $var +/- X ]?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes and no. doing that calculation is very common and correct when it's to set the starting point for a findNext()/findPrevious() function call.
Code style assumptions are only problematic for best practice sniffs, not code style sniffs and to bypass those assumption you need to take every crappy way of writing PHP into account, so looking for checks using T_WHITESPACE is another typical search entry point. This should - for code style independence - be Tokens::$emptyTokens.

@jrfnl
Copy link
Member Author

jrfnl commented Sep 3, 2018

@WordPress-Coding-Standards/wpcs-admins Anything I can do to move this PR forward ?

@JDGrimes JDGrimes merged commit b51d476 into develop Sep 7, 2018
@JDGrimes JDGrimes deleted the feature/is_in_isset_or_empty-codestyle-independence branch September 7, 2018 20:40
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