jenkins-bot has submitted this change and it was merged. Change subject: Handle interfaces or abstract functions and heredoc in UnusedGlobalVariablesSniff ......................................................................
Handle interfaces or abstract functions and heredoc in UnusedGlobalVariablesSniff Follows up 585e0d171d248da2c0. Co-Authored-By: Divya <[email protected]> Change-Id: I3a9859aae5b55b5dec4b0f2c657d2e4883b526de --- M MediaWiki/Sniffs/VariableAnalysis/UnusedGlobalVariablesSniff.php A MediaWiki/Tests/files/VariableAnalysis/unused_global_variables_heredoc_pass.php A MediaWiki/Tests/files/VariableAnalysis/used_global_variables_regression_pass.php 3 files changed, 24 insertions(+), 2 deletions(-) Approvals: Legoktm: Looks good to me, approved jenkins-bot: Verified diff --git a/MediaWiki/Sniffs/VariableAnalysis/UnusedGlobalVariablesSniff.php b/MediaWiki/Sniffs/VariableAnalysis/UnusedGlobalVariablesSniff.php index f7409dd..5d18160 100644 --- a/MediaWiki/Sniffs/VariableAnalysis/UnusedGlobalVariablesSniff.php +++ b/MediaWiki/Sniffs/VariableAnalysis/UnusedGlobalVariablesSniff.php @@ -11,7 +11,10 @@ public function process( PHP_CodeSniffer_File $phpcsFile, $stackPtr ) { $tokens = $phpcsFile->getTokens(); - + if ( !isset( $tokens[$stackPtr]['scope_opener'] ) ) { + // An interface or abstract function which doesn't have a body + return; + } $scopeOpener = ++$tokens[$stackPtr]['scope_opener']; $scopeCloser = $tokens[$stackPtr]['scope_closer']; @@ -34,7 +37,7 @@ if ( $tokens[$i]['type'] === 'T_VARIABLE' && $tokens[$i]['line'] != $globalLine ) { $otherVariables[] = $tokens[$i]['content']; } - if ( $tokens[$i]['type'] === 'T_DOUBLE_QUOTED_STRING' ) { + if ( $tokens[$i]['type'] === 'T_DOUBLE_QUOTED_STRING' || $tokens[$i]['type'] === "T_HEREDOC" ) { preg_match_all( '/[$]\w+/', $tokens[$i]['content'], $matches ); $strVariables = array_merge_recursive( $strVariables, $matches ); } diff --git a/MediaWiki/Tests/files/VariableAnalysis/unused_global_variables_heredoc_pass.php b/MediaWiki/Tests/files/VariableAnalysis/unused_global_variables_heredoc_pass.php new file mode 100644 index 0000000..213d01f --- /dev/null +++ b/MediaWiki/Tests/files/VariableAnalysis/unused_global_variables_heredoc_pass.php @@ -0,0 +1,10 @@ +<?php + +function fooFoo () { + global $wgSomething; + $foo = <<<PHP +/** +* foo $wgSomething +*/ +PHP; +} diff --git a/MediaWiki/Tests/files/VariableAnalysis/used_global_variables_regression_pass.php b/MediaWiki/Tests/files/VariableAnalysis/used_global_variables_regression_pass.php new file mode 100644 index 0000000..181a790 --- /dev/null +++ b/MediaWiki/Tests/files/VariableAnalysis/used_global_variables_regression_pass.php @@ -0,0 +1,9 @@ +<?php + +interface FooBar { + public function funcFooBar(); +} + +abstract class FooFoo { + abstract public function funcFooFoo(); +} -- To view, visit https://gerrit.wikimedia.org/r/193660 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: I3a9859aae5b55b5dec4b0f2c657d2e4883b526de Gerrit-PatchSet: 3 Gerrit-Project: mediawiki/tools/codesniffer Gerrit-Branch: master Gerrit-Owner: Legoktm <[email protected]> Gerrit-Reviewer: Addshore <[email protected]> Gerrit-Reviewer: Legoktm <[email protected]> Gerrit-Reviewer: Phoenix303 <[email protected]> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list [email protected] https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
