Addshore has uploaded a new change for review.
https://gerrit.wikimedia.org/r/286299
Change subject: Factor out getToken method in PrefixedGlobalFunctionSniff
......................................................................
Factor out getToken method in PrefixedGlobalFunctionSniff
This is the expensive logic in this sniff which we should
try to kill.
Change-Id: I05045cb739ae97617d5dd4d63668fa470c8bf45c
---
M MediaWiki/Sniffs/NamingConventions/PrefixedGlobalFunctionsSniff.php
1 file changed, 20 insertions(+), 9 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/tools/codesniffer
refs/changes/99/286299/1
diff --git
a/MediaWiki/Sniffs/NamingConventions/PrefixedGlobalFunctionsSniff.php
b/MediaWiki/Sniffs/NamingConventions/PrefixedGlobalFunctionsSniff.php
index f2c7481..b2d8f4b 100644
--- a/MediaWiki/Sniffs/NamingConventions/PrefixedGlobalFunctionsSniff.php
+++ b/MediaWiki/Sniffs/NamingConventions/PrefixedGlobalFunctionsSniff.php
@@ -17,16 +17,10 @@
public function process( PHP_CodeSniffer_File $phpcsFile, $stackPtr ) {
$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;
- }
- $ptr--;
+ $token = $this->getToken( $tokens, $stackPtr );
+ if( $token === null ) {
+ return;
}
- $token = $tokens[$stackPtr];
// Name of function
$name = $tokens[$stackPtr + 2]['content'];
@@ -49,4 +43,21 @@
}
}
}
+
+ /**
+ * @param array $tokens
+ * @param int $stackPtr
+ * @return array|null array of token details or null
+ */
+ private function getToken( array $tokens, $stackPtr ) {
+ while ( $stackPtr > 0 ) {
+ $token = $tokens[$stackPtr];
+ if ( $token['type'] === "T_NAMESPACE" && !isset(
$token['scope_opener'] ) ) {
+ // In the format of "namespace Foo;", which
applies to the entire file
+ return null;
+ }
+ $stackPtr--;
+ }
+ return $tokens[$stackPtr];
+ }
}
--
To view, visit https://gerrit.wikimedia.org/r/286299
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I05045cb739ae97617d5dd4d63668fa470c8bf45c
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/tools/codesniffer
Gerrit-Branch: master
Gerrit-Owner: Addshore <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits