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

Change subject: Refactor ValidGlobalNameSniff
......................................................................


Refactor ValidGlobalNameSniff

Change-Id: Ia198a09312bdf6cde44ec1adc36445f7f2be148e
---
M MediaWiki/Sniffs/NamingConventions/ValidGlobalNameSniff.php
1 file changed, 17 insertions(+), 29 deletions(-)

Approvals:
  Hashar: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/MediaWiki/Sniffs/NamingConventions/ValidGlobalNameSniff.php 
b/MediaWiki/Sniffs/NamingConventions/ValidGlobalNameSniff.php
index f425730..c3ab05e 100644
--- a/MediaWiki/Sniffs/NamingConventions/ValidGlobalNameSniff.php
+++ b/MediaWiki/Sniffs/NamingConventions/ValidGlobalNameSniff.php
@@ -8,7 +8,7 @@
        /**
         * http://php.net/manual/en/reserved.variables.argv.php
         */
-       protected static $PHPReserved = array(
+       private static $PHPReserved = array(
                '$GLOBALS',
                '$_SERVER',
                '$_GET',
@@ -25,7 +25,7 @@
                '$argv'
        );
 
-       protected static $mediaWikiValid = array(
+       private static $mediaWikiValid = array(
                '$messageMemc',
                '$parserMemc',
                '$IP',
@@ -37,13 +37,6 @@
 
        public function process( PHP_CodeSniffer_File $phpcsFile, $stackPtr ) {
                $tokens = $phpcsFile->getTokens();
-               $token = $tokens[$stackPtr];
-
-               if( $token['code'] !== T_GLOBAL ) {
-                       return;
-               }
-
-               $errorIssued = false;
 
                $nameIndex  = $phpcsFile->findNext( T_VARIABLE, $stackPtr + 1 );
                $globalName = $tokens[$nameIndex]['content'];
@@ -54,36 +47,31 @@
                        return;
                }
 
-               // skip '$' and forge a valid global variable name
+               // 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 ) {
-
-                       $error = 'Global variable "%s" is lacking \'wg\' 
prefix. Should be "%s".';
-                       $type = 'wgPrefix';
-                       $data = array( $globalName, $expected );
-                       $phpcsFile->addError( $error, $stackPtr, $type, $data );
-
-                       $errorIssued = true;
-               }
-
-               if( !$errorIssued ) { // no need to warn twice.
+                       $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) ) {
-
-                               $error = 'Global variable "%s" should use 
CamelCase: "%s"';
-                               $type = 'CamelCase';
-                               $data = array( $globalName, $expected );
-                               $phpcsFile->addError( $error, $stackPtr, $type, 
$data );
-
-                               $errorIssued = true;
+                               $phpcsFile->addError(
+                                       'Global variable "%s" should use 
CamelCase: "%s"',
+                                       $stackPtr,
+                                       'CamelCase',
+                                       array( $globalName, $expected )
+                               );
                        }
                }
 
-       }//end process()
+       }
 
 }
 

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

Gerrit-MessageType: merged
Gerrit-Change-Id: Ia198a09312bdf6cde44ec1adc36445f7f2be148e
Gerrit-PatchSet: 4
Gerrit-Project: mediawiki/tools/codesniffer
Gerrit-Branch: master
Gerrit-Owner: Addshore <addshorew...@gmail.com>
Gerrit-Reviewer: Addshore <addshorew...@gmail.com>
Gerrit-Reviewer: Hashar <has...@free.fr>
Gerrit-Reviewer: Hoo man <h...@online.de>
Gerrit-Reviewer: Krinkle <krinklem...@gmail.com>
Gerrit-Reviewer: Legoktm <legoktm.wikipe...@gmail.com>
Gerrit-Reviewer: Siebrand <siebr...@kitano.nl>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to