jenkins-bot has submitted this change and it was merged.

Change subject: Factor our tokenIsNamespaced method
......................................................................


Factor our tokenIsNamespaced method

This makes what this sniff is doing far clearer

Change-Id: I05045cb739ae97617d5dd4d63668fa470c8bf45c
---
M MediaWiki/Sniffs/NamingConventions/PrefixedGlobalFunctionsSniff.php
1 file changed, 15 insertions(+), 3 deletions(-)

Approvals:
  WMDE-Fisch: Looks good to me, but someone else must approve
  Legoktm: Looks good to me, approved
  jenkins-bot: Verified



diff --git 
a/MediaWiki/Sniffs/NamingConventions/PrefixedGlobalFunctionsSniff.php 
b/MediaWiki/Sniffs/NamingConventions/PrefixedGlobalFunctionsSniff.php
index f2c7481..5075d5c 100644
--- a/MediaWiki/Sniffs/NamingConventions/PrefixedGlobalFunctionsSniff.php
+++ b/MediaWiki/Sniffs/NamingConventions/PrefixedGlobalFunctionsSniff.php
@@ -15,17 +15,29 @@
                return [ T_FUNCTION ];
        }
 
-       public function process( PHP_CodeSniffer_File $phpcsFile, $stackPtr ) {
+       /**
+        * @param PHP_CodeSniffer_File $phpcsFile
+        * @param int $ptr
+        * @return bool Does a namespace statement exist before this position 
in the file?
+        */
+       private function tokenIsNamespaced( PHP_CodeSniffer_File $phpcsFile, 
$ptr ) {
                $tokens = $phpcsFile->getTokens();
-               $ptr = $stackPtr;
                while ( $ptr > 0 ) {
                        $token = $tokens[$ptr];
                        if ( $token['type'] === "T_NAMESPACE" && !isset( 
$token['scope_opener'] ) ) {
                                // In the format of "namespace Foo;", which 
applies to the entire file
-                               return;
+                               return true;
                        }
                        $ptr--;
                }
+               return false;
+       }
+
+       public function process( PHP_CodeSniffer_File $phpcsFile, $stackPtr ) {
+               if ( $this->tokenIsNamespaced( $phpcsFile, $stackPtr ) ) {
+                       return;
+               }
+               $tokens = $phpcsFile->getTokens();
                $token = $tokens[$stackPtr];
 
                // Name of function

-- 
To view, visit https://gerrit.wikimedia.org/r/286299
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I05045cb739ae97617d5dd4d63668fa470c8bf45c
Gerrit-PatchSet: 3
Gerrit-Project: mediawiki/tools/codesniffer
Gerrit-Branch: master
Gerrit-Owner: Addshore <[email protected]>
Gerrit-Reviewer: Hashar <[email protected]>
Gerrit-Reviewer: Legoktm <[email protected]>
Gerrit-Reviewer: Polybuildr <[email protected]>
Gerrit-Reviewer: WMDE-Fisch <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to