[MediaWiki-commits] [Gerrit] Refactor ValidGlobalNameSniff - change (mediawiki...codesniffer)

2014-08-16 Thread jenkins-bot (Code Review)
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 
Gerrit-Reviewer: Addshore 
Gerrit-Reviewer: Hashar 
Gerrit-Reviewer: Hoo man 
Gerrit-Reviewer: Krinkle 
Gerrit-Reviewer: Legoktm 
Gerrit-Reviewer: Siebrand 
Gerrit-Reviewer: jenkins-bot <>

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


[MediaWiki-commits] [Gerrit] Refactor ValidGlobalNameSniff - change (mediawiki...codesniffer)

2014-08-10 Thread Addshore (Code Review)
Addshore has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/153314

Change subject: Refactor ValidGlobalNameSniff
..

Refactor ValidGlobalNameSniff

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


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/tools/codesniffer 
refs/changes/14/153314/1

diff --git a/MediaWiki/Sniffs/NamingConventions/ValidGlobalNameSniff.php 
b/MediaWiki/Sniffs/NamingConventions/ValidGlobalNameSniff.php
index f425730..0d6350c 100644
--- a/MediaWiki/Sniffs/NamingConventions/ValidGlobalNameSniff.php
+++ b/MediaWiki/Sniffs/NamingConventions/ValidGlobalNameSniff.php
@@ -1,4 +1,5 @@
 http://php.net/manual/en/reserved.variables.argv.php
 */
-   protected static $PHPReserved = array(
+   private static $PHPReserved = array(
'$GLOBALS',
'$_SERVER',
'$_GET',
@@ -25,7 +26,7 @@
'$argv'
);
 
-   protected static $mediaWikiValid = array(
+   private static $mediaWikiValid = array(
'$messageMemc',
'$parserMemc',
'$IP',
@@ -37,13 +38,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 +48,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: newchange
Gerrit-Change-Id: Ia198a09312bdf6cde44ec1adc36445f7f2be148e
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/tools/codesniffer
Gerrit-Branch: master
Gerrit-Owner: Addshore 

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