Phoenix303 has uploaded a new change for review. https://gerrit.wikimedia.org/r/192168
Change subject: Fixed phpcs sniff verifies wg prefix against all global variables ...................................................................... Fixed phpcs sniff verifies wg prefix against all global variables Bug: T90365 Change-Id: Icc95fcd41a3d39abbf457ae10e3c18b27ca6bd39 --- M MediaWiki/Sniffs/NamingConventions/ValidGlobalNameSniff.php 1 file changed, 33 insertions(+), 27 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/tools/codesniffer refs/changes/68/192168/1 diff --git a/MediaWiki/Sniffs/NamingConventions/ValidGlobalNameSniff.php b/MediaWiki/Sniffs/NamingConventions/ValidGlobalNameSniff.php index c3ab05e..d324796 100644 --- a/MediaWiki/Sniffs/NamingConventions/ValidGlobalNameSniff.php +++ b/MediaWiki/Sniffs/NamingConventions/ValidGlobalNameSniff.php @@ -39,38 +39,44 @@ $tokens = $phpcsFile->getTokens(); $nameIndex = $phpcsFile->findNext( T_VARIABLE, $stackPtr + 1 ); - $globalName = $tokens[$nameIndex]['content']; + $semicolonIndex = $phpcsFile->findNext( T_SEMICOLON, $stackPtr + 1 ); - if( in_array( $globalName, self::$mediaWikiValid ) || - in_array( $globalName, self::$PHPReserved ) - ) { - return; - } + while( $nameIndex < $semicolonIndex ) { + if( $tokens[ $nameIndex ][ 'code' ] !== T_WHITESPACE && $tokens[ $nameIndex ][ 'code' ] !== T_COMMA ) { + $globalName = $tokens[$nameIndex]['content']; - // Skip '$' and forge a valid global variable name - $expected = '$wg' . ucfirst(substr( $globalName, 1 )); + if( in_array( $globalName, self::$mediaWikiValid ) || + in_array( $globalName, self::$PHPReserved ) + ) { + return; + } - // Verify global is prefixed with wg - if( strpos($globalName, '$wg' ) !== 0 ) { - $phpcsFile->addError( - 'Global variable "%s" is lacking \'wg\' prefix. Should be "%s".', - $stackPtr, - 'wgPrefix', - array( $globalName, $expected ) - ); - } else { - // Verify global is probably CamelCase - $val = ord( substr( $globalName, 3, 1 ) ); - if( !($val >= 65 && $val <= 90) ) { - $phpcsFile->addError( - 'Global variable "%s" should use CamelCase: "%s"', - $stackPtr, - 'CamelCase', - array( $globalName, $expected ) - ); + // Skip '$' and forge a valid global variable name + $expected = '$wg' . ucfirst(substr( $globalName, 1 )); + + // Verify global is prefixed with wg + if( strpos($globalName, '$wg' ) !== 0 ) { + $phpcsFile->addError( + 'Global variable "%s" is lacking \'wg\' prefix. Should be "%s".', + $stackPtr, + 'wgPrefix', + array( $globalName, $expected ) + ); + } else { + // Verify global is probably CamelCase + $val = ord( substr( $globalName, 3, 1 ) ); + if( !($val >= 65 && $val <= 90) ) { + $phpcsFile->addError( + 'Global variable "%s" should use CamelCase: "%s"', + $stackPtr, + 'CamelCase', + array( $globalName, $expected ) + ); + } + } } + $nameIndex++; } - } } -- To view, visit https://gerrit.wikimedia.org/r/192168 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Icc95fcd41a3d39abbf457ae10e3c18b27ca6bd39 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/tools/codesniffer Gerrit-Branch: master Gerrit-Owner: Phoenix303 <divyalife...@gmail.com> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits