jenkins-bot has submitted this change and it was merged. 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 A MediaWiki/Tests/files/NamingConventions/wg_global_name2_fail.php M MediaWiki/Tests/files/NamingConventions/wg_global_name_fail.php 3 files changed, 40 insertions(+), 29 deletions(-) Approvals: Legoktm: Looks good to me, approved jenkins-bot: Verified diff --git a/MediaWiki/Sniffs/NamingConventions/ValidGlobalNameSniff.php b/MediaWiki/Sniffs/NamingConventions/ValidGlobalNameSniff.php index c3ab05e..60f3a8a 100644 --- a/MediaWiki/Sniffs/NamingConventions/ValidGlobalNameSniff.php +++ b/MediaWiki/Sniffs/NamingConventions/ValidGlobalNameSniff.php @@ -39,39 +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++; } - } - } diff --git a/MediaWiki/Tests/files/NamingConventions/wg_global_name2_fail.php b/MediaWiki/Tests/files/NamingConventions/wg_global_name2_fail.php new file mode 100644 index 0000000..bd3987e --- /dev/null +++ b/MediaWiki/Tests/files/NamingConventions/wg_global_name2_fail.php @@ -0,0 +1,6 @@ +<?php + +function fooFoo () { + // The first global is fine, the second isn't + global $wgContLang, $LocalInterwikis; +} diff --git a/MediaWiki/Tests/files/NamingConventions/wg_global_name_fail.php b/MediaWiki/Tests/files/NamingConventions/wg_global_name_fail.php index ba12d41..d453874 100644 --- a/MediaWiki/Tests/files/NamingConventions/wg_global_name_fail.php +++ b/MediaWiki/Tests/files/NamingConventions/wg_global_name_fail.php @@ -3,4 +3,4 @@ function fooFoo () { // The below should start with wg... global $someotherglobal; -} \ No newline at end of file +} -- To view, visit https://gerrit.wikimedia.org/r/192168 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: Icc95fcd41a3d39abbf457ae10e3c18b27ca6bd39 Gerrit-PatchSet: 4 Gerrit-Project: mediawiki/tools/codesniffer Gerrit-Branch: master Gerrit-Owner: Phoenix303 <divyalife...@gmail.com> Gerrit-Reviewer: Addshore <addshorew...@gmail.com> Gerrit-Reviewer: Krinkle <krinklem...@gmail.com> Gerrit-Reviewer: Legoktm <legoktm.wikipe...@gmail.com> Gerrit-Reviewer: Phoenix303 <divyalife...@gmail.com> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits