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

Add some more PHP magic constants which can be skipped … #621

Merged
merged 2 commits into from
Jul 19, 2016

Conversation

jrfnl
Copy link
Member

@jrfnl jrfnl commented Jul 19, 2016

… to the EscapeOutputSniff.

@@ -226,7 +226,7 @@ public function process( PHP_CodeSniffer_File $phpcsFile, $stackPtr ) {
}

// Handle magic constants for debug functions.
if ( in_array( $tokens[ $i ]['code'], array( T_METHOD_C, T_FUNC_C, T_FILE, T_CLASS_C ), true ) ) {
if ( in_array( $tokens[ $i ]['code'], array( T_CLASS_C, T_FILE, T_FUNC_C, T_LINE, T_METHOD_C, T_NS_C, T_TRAIT_C ), true ) ) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe we should also move these to a property. Make them the keys so that we can use isset() here instead of in_array(). Not sure if there would be any use for this list outside of this sniff or not; if you don't think so then just have it be a property of this sniff instead of the base sniff class.

Copy link
Member Author

@jrfnl jrfnl Jul 19, 2016

Choose a reason for hiding this comment

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

When I made the change I checked that:

  1. there wasn't already a (static) property in the PHPCS Tokens class we could use for this (there isn't)
  2. whether any of these tokens are used anywhere else in WPCS (they are not).

I thought about making it a property, but am a bit wary what with the fact that the actual values these constants represent are integers which change between PHP versions. It shouldn't be an issue, but still.

Thinking now - I might as well make it a property with the string name as keys and check against the $tokens[ $i ]['type'] value instead of code. That should work and be stable.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done.

@jrfnl jrfnl force-pushed the WPCS/feature/magic-constants branch from 282d940 to be7951c Compare July 19, 2016 21:53
@JDGrimes JDGrimes added this to the 0.10.0 milestone Jul 19, 2016
@JDGrimes JDGrimes merged commit e0283de into develop Jul 19, 2016
@JDGrimes JDGrimes deleted the WPCS/feature/magic-constants branch July 19, 2016 22:20
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