Addshore has uploaded a new change for review. https://gerrit.wikimedia.org/r/154410
Change subject: Also catch use of globals through $GLOBALS ...................................................................... Also catch use of globals through $GLOBALS Change-Id: I707e717d99b6e1b7a600965b5bc0fc444232c92a --- M MediaWikiBreaks/Sniffs/RemovedStuff/GlobalSniff.php M MediaWikiBreaks/Tests/MediaWikiBreaksStandardTest.php M MediaWikiBreaks/Tests/RemovedStuff/Global.php 3 files changed, 20 insertions(+), 4 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/tools/codesniffer refs/changes/10/154410/1 diff --git a/MediaWikiBreaks/Sniffs/RemovedStuff/GlobalSniff.php b/MediaWikiBreaks/Sniffs/RemovedStuff/GlobalSniff.php index 577fee0..d32d141 100644 --- a/MediaWikiBreaks/Sniffs/RemovedStuff/GlobalSniff.php +++ b/MediaWikiBreaks/Sniffs/RemovedStuff/GlobalSniff.php @@ -2,8 +2,6 @@ /** * @author Adam Shorland - * - * @todo Catch use of MediaWikiGlobals through super globals! */ class MediaWikiBreaks_Sniffs_RemovedStuff_GlobalSniff implements PHP_CodeSniffer_Sniff { @@ -66,14 +64,28 @@ public function register() { return array( T_GLOBAL, + T_VARIABLE, ); } public function process( PHP_CodeSniffer_File $phpcsFile, $stackPtr ) { $tokens = $phpcsFile->getTokens(); + $token = $tokens[$stackPtr]; - $nameIndex = $phpcsFile->findNext( T_VARIABLE, $stackPtr ); - $globalName = $tokens[$nameIndex]['content']; + if( $token['type'] === 'T_GLOBAL' ) { + $globalName = $tokens[$phpcsFile->findNext( T_VARIABLE, $stackPtr )]['content']; + } elseif( $token['type'] === 'T_VARIABLE' && $token['content'] === '$GLOBALS' ) { + if( $phpcsFile->findNext( T_OPEN_SQUARE_BRACKET, $stackPtr ) <= $stackPtr + 2 ) { + $stringLocation = $phpcsFile->findNext( T_CONSTANT_ENCAPSED_STRING, $stackPtr ); + if( $stringLocation <= $stackPtr + 3 ) { + $globalName = '$' . trim( $tokens[$stringLocation]['content'], "'" ); + } + } + } + + if( !isset( $globalName ) ) { + return; + } foreach( $this->removedStuff as $version => $globals ) { if( in_array( $globalName, $globals ) ) { diff --git a/MediaWikiBreaks/Tests/MediaWikiBreaksStandardTest.php b/MediaWikiBreaks/Tests/MediaWikiBreaksStandardTest.php index a17ed36..11808e9 100644 --- a/MediaWikiBreaks/Tests/MediaWikiBreaksStandardTest.php +++ b/MediaWikiBreaks/Tests/MediaWikiBreaksStandardTest.php @@ -37,6 +37,7 @@ 'RemovedStuff/Global.php' => array( 'error' => array( 5 => 1, + 13 => 1, ), ), 'RemovedStuff/Method.php' => array( diff --git a/MediaWikiBreaks/Tests/RemovedStuff/Global.php b/MediaWikiBreaks/Tests/RemovedStuff/Global.php index dee9854..982463c 100644 --- a/MediaWikiBreaks/Tests/RemovedStuff/Global.php +++ b/MediaWikiBreaks/Tests/RemovedStuff/Global.php @@ -8,4 +8,7 @@ function FooBar() { //pass global $barBaz; + $foo = $GLOBALS; + $foo = $GLOBALS['bar']; + $foo = $GLOBALS['wgAPICacheHelp']; } \ No newline at end of file -- To view, visit https://gerrit.wikimedia.org/r/154410 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I707e717d99b6e1b7a600965b5bc0fc444232c92a Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/tools/codesniffer Gerrit-Branch: master Gerrit-Owner: Addshore <addshorew...@gmail.com> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits