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

Change subject: Address some PHP CodeSniffer errors and warnings
......................................................................


Address some PHP CodeSniffer errors and warnings

Change-Id: I495481e3532834f1f8a45cda9402d609de7e2bd7
---
M includes/AutoLoader.php
M includes/utils/CdbPHP.php
M includes/utils/ConfEditor.php
M includes/utils/MWCryptRand.php
M includes/utils/StringUtils.php
M includes/utils/ZipDirectoryReader.php
6 files changed, 42 insertions(+), 26 deletions(-)

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



diff --git a/includes/AutoLoader.php b/includes/AutoLoader.php
index f79fdc9..29d2209 100644
--- a/includes/AutoLoader.php
+++ b/includes/AutoLoader.php
@@ -843,12 +843,14 @@
        'ResourceLoaderNoscriptModule' => 
'includes/resourceloader/ResourceLoaderNoscriptModule.php',
        'ResourceLoaderSiteModule' => 
'includes/resourceloader/ResourceLoaderSiteModule.php',
        'ResourceLoaderStartUpModule' => 
'includes/resourceloader/ResourceLoaderStartUpModule.php',
-       'ResourceLoaderUserCSSPrefsModule' => 
'includes/resourceloader/ResourceLoaderUserCSSPrefsModule.php',
+       'ResourceLoaderUserCSSPrefsModule' =>
+               'includes/resourceloader/ResourceLoaderUserCSSPrefsModule.php',
        'ResourceLoaderUserGroupsModule' => 
'includes/resourceloader/ResourceLoaderUserGroupsModule.php',
        'ResourceLoaderUserModule' => 
'includes/resourceloader/ResourceLoaderUserModule.php',
        'ResourceLoaderUserOptionsModule' => 
'includes/resourceloader/ResourceLoaderUserOptionsModule.php',
        'ResourceLoaderUserTokensModule' => 
'includes/resourceloader/ResourceLoaderUserTokensModule.php',
-       'ResourceLoaderLanguageDataModule' => 
'includes/resourceloader/ResourceLoaderLanguageDataModule.php',
+       'ResourceLoaderLanguageDataModule' =>
+               'includes/resourceloader/ResourceLoaderLanguageDataModule.php',
        'ResourceLoaderWikiModule' => 
'includes/resourceloader/ResourceLoaderWikiModule.php',
 
        # includes/revisiondelete
diff --git a/includes/utils/CdbPHP.php b/includes/utils/CdbPHP.php
index f14921d..e7bb4bc 100644
--- a/includes/utils/CdbPHP.php
+++ b/includes/utils/CdbPHP.php
@@ -73,7 +73,8 @@
         */
        public static function hash( $s ) {
                $h = 5381;
-               for ( $i = 0; $i < strlen( $s ); $i++ ) {
+               $len = strlen( $s );
+               for ( $i = 0; $i < $len; $i++ ) {
                        $h5 = ( $h << 5 ) & 0xffffffff;
                        // Do a 32-bit sum
                        // Inlined here for speed
diff --git a/includes/utils/ConfEditor.php b/includes/utils/ConfEditor.php
index 163f73c..a2fe507 100644
--- a/includes/utils/ConfEditor.php
+++ b/includes/utils/ConfEditor.php
@@ -444,7 +444,8 @@
                        $this->nextToken();
                }
                $regionEnd = $path['endByte']; // past the end
-               for ( $offset = 0; $offset < count( $this->tokens ) - 
$this->pos; $offset++ ) {
+               $count = count( $this->tokens );
+               for ( $offset = 0; $offset < $count - $this->pos; $offset++ ) {
                        $token = $this->getTokenAhead( $offset );
                        if ( !$token->isSkip() ) {
                                break;
diff --git a/includes/utils/MWCryptRand.php b/includes/utils/MWCryptRand.php
index d71193f..0172974 100644
--- a/includes/utils/MWCryptRand.php
+++ b/includes/utils/MWCryptRand.php
@@ -25,7 +25,6 @@
  */
 
 class MWCryptRand {
-
        /**
         * Minimum number of iterations we want to make in our drift 
calculations.
         */
@@ -86,10 +85,11 @@
                $files[] = __DIR__;
                $files[] = dirname( __DIR__ );
 
-               // The config file is likely the most often edited file we know 
should be around
-               // so include its stat info into the state.
-               // The constant with its location will almost always be 
defined, as WebStart.php defines
-               // MW_CONFIG_FILE to $IP/LocalSettings.php unless being 
configured with MW_CONFIG_CALLBACK (eg. the installer)
+               // The config file is likely the most often edited file we know 
should
+               // be around so include its stat info into the state.
+               // The constant with its location will almost always be 
defined, as
+               // WebStart.php defines MW_CONFIG_FILE to $IP/LocalSettings.php 
unless
+               // being configured with MW_CONFIG_CALLBACK (e.g. the 
installer).
                if ( defined( 'MW_CONFIG_FILE' ) ) {
                        $files[] = MW_CONFIG_FILE;
                }
@@ -153,7 +153,8 @@
         * @author Tim Starling
         */
        protected function driftHash( $data ) {
-               // Minimum number of iterations (to avoid slow operations 
causing the loop to gather little entropy)
+               // Minimum number of iterations (to avoid slow operations 
causing the
+               // loop to gather little entropy)
                $minIterations = self::MIN_ITERATIONS;
                // Duration of time to spend doing calculations (in seconds)
                $duration = ( self::MSEC_PER_BYTE / 1000 ) * 
$this->hashLength();
@@ -296,7 +297,8 @@
        public function realGenerate( $bytes, $forceStrong = false ) {
                wfProfileIn( __METHOD__ );
 
-               wfDebug( __METHOD__ . ": Generating cryptographic random bytes 
for " . wfGetAllCallers( 5 ) . "\n" );
+               wfDebug( __METHOD__ . ": Generating cryptographic random bytes 
for " .
+                       wfGetAllCallers( 5 ) . "\n" );
 
                $bytes = floor( $bytes );
                static $buffer = '';
@@ -320,15 +322,17 @@
                                        wfDebug( __METHOD__ . ": 
mcrypt_create_iv returned false.\n" );
                                } else {
                                        $buffer .= $iv;
-                                       wfDebug( __METHOD__ . ": 
mcrypt_create_iv generated " . strlen( $iv ) . " bytes of randomness.\n" );
+                                       wfDebug( __METHOD__ . ": 
mcrypt_create_iv generated " . strlen( $iv ) .
+                                               " bytes of randomness.\n" );
                                }
                                wfProfileOut( __METHOD__ . '-mcrypt' );
                        }
                }
 
                if ( strlen( $buffer ) < $bytes ) {
-                       // If available make use of openssl's 
random_pseudo_bytes method to attempt to generate randomness.
-                       // However don't do this on Windows with PHP < 5.3.4 
due to a bug:
+                       // If available make use of openssl's 
random_pseudo_bytes method to
+                       // attempt to generate randomness. However don't do 
this on Windows
+                       // with PHP < 5.3.4 due to a bug:
                        // 
http://stackoverflow.com/questions/1940168/openssl-random-pseudo-bytes-is-slow-php
                        // 
http://git.php.net/?p=php-src.git;a=commitdiff;h=cd62a70863c261b07f6dadedad9464f7e213cad5
                        if ( function_exists( 'openssl_random_pseudo_bytes' )
@@ -341,7 +345,9 @@
                                        wfDebug( __METHOD__ . ": 
openssl_random_pseudo_bytes returned false.\n" );
                                } else {
                                        $buffer .= $openssl_bytes;
-                                       wfDebug( __METHOD__ . ": 
openssl_random_pseudo_bytes generated " . strlen( $openssl_bytes ) . " bytes of 
" . ( $openssl_strong ? "strong" : "weak" ) . " randomness.\n" );
+                                       wfDebug( __METHOD__ . ": 
openssl_random_pseudo_bytes generated " .
+                                               strlen( $openssl_bytes ) . " 
bytes of " .
+                                               ( $openssl_strong ? "strong" : 
"weak" ) . " randomness.\n" );
                                }
                                if ( strlen( $buffer ) >= $bytes ) {
                                        // openssl tells us if the random 
source was strong, if some of our data was generated
@@ -353,11 +359,14 @@
                }
 
                // Only read from urandom if we can control the buffer size or 
were passed forceStrong
-               if ( strlen( $buffer ) < $bytes && ( function_exists( 
'stream_set_read_buffer' ) || $forceStrong ) ) {
+               if ( strlen( $buffer ) < $bytes &&
+                       ( function_exists( 'stream_set_read_buffer' ) || 
$forceStrong )
+               ) {
                        wfProfileIn( __METHOD__ . '-fopen-urandom' );
                        $rem = $bytes - strlen( $buffer );
                        if ( !function_exists( 'stream_set_read_buffer' ) && 
$forceStrong ) {
-                               wfDebug( __METHOD__ . ": Was forced to read 
from /dev/urandom without control over the buffer size.\n" );
+                               wfDebug( __METHOD__ . ": Was forced to read 
from /dev/urandom " .
+                                       "without control over the buffer 
size.\n" );
                        }
                        // /dev/urandom is generally considered the best 
possible commonly
                        // available random source, and is available on most 
*nix systems.
@@ -382,7 +391,9 @@
                                $random_bytes = fread( $urandom, max( 
$chunk_size, $rem ) );
                                $buffer .= $random_bytes;
                                fclose( $urandom );
-                               wfDebug( __METHOD__ . ": /dev/urandom generated 
" . strlen( $random_bytes ) . " bytes of randomness.\n" );
+                               wfDebug( __METHOD__ . ": /dev/urandom generated 
" . strlen( $random_bytes ) .
+                                       " bytes of randomness.\n" );
+
                                if ( strlen( $buffer ) >= $bytes ) {
                                        // urandom is always strong, set to 
true if all our data was generated using it
                                        $this->strong = true;
@@ -400,7 +411,8 @@
                // We hash the random state with more salt to avoid the state 
from leaking
                // out and being used to predict the /randomness/ that follows.
                if ( strlen( $buffer ) < $bytes ) {
-                       wfDebug( __METHOD__ . ": Falling back to using a pseudo 
random state to generate randomness.\n" );
+                       wfDebug( __METHOD__ .
+                               ": Falling back to using a pseudo random state 
to generate randomness.\n" );
                }
                while ( strlen( $buffer ) < $bytes ) {
                        wfProfileIn( __METHOD__ . '-fallback' );
@@ -417,7 +429,8 @@
                $generated = substr( $buffer, 0, $bytes );
                $buffer = substr( $buffer, $bytes );
 
-               wfDebug( __METHOD__ . ": " . strlen( $buffer ) . " bytes of 
randomness leftover in the buffer.\n" );
+               wfDebug( __METHOD__ . ": " . strlen( $buffer ) .
+                       " bytes of randomness leftover in the buffer.\n" );
 
                wfProfileOut( __METHOD__ );
 
diff --git a/includes/utils/StringUtils.php b/includes/utils/StringUtils.php
index 0ebba2a..167c268 100644
--- a/includes/utils/StringUtils.php
+++ b/includes/utils/StringUtils.php
@@ -24,7 +24,6 @@
  * A collection of static methods to play with strings.
  */
 class StringUtils {
-
        /**
         * Test whether a string is valid UTF-8.
         *
@@ -166,7 +165,9 @@
         * @throws MWException
         * @return string
         */
-       static function delimiterReplaceCallback( $startDelim, $endDelim, 
$callback, $subject, $flags = '' ) {
+       static function delimiterReplaceCallback( $startDelim, $endDelim, 
$callback,
+               $subject, $flags = ''
+       ) {
                $inputPos = 0;
                $outputPos = 0;
                $output = '';
@@ -320,7 +321,6 @@
  * StringUtils::delimiterReplaceCallback()
  */
 class Replacer {
-
        /**
         * @return array
         */
@@ -360,7 +360,6 @@
  * Class to perform secondary replacement within each replacement string
  */
 class DoubleReplacer extends Replacer {
-
        /**
         * @param $from
         * @param $to
diff --git a/includes/utils/ZipDirectoryReader.php 
b/includes/utils/ZipDirectoryReader.php
index 7bf538a..5c92525 100644
--- a/includes/utils/ZipDirectoryReader.php
+++ b/includes/utils/ZipDirectoryReader.php
@@ -247,8 +247,8 @@
                );
                $structSize = $this->getStructSize( $info );
 
-               $block = $this->getBlock( $this->getFileLength() - 
$this->eocdr['EOCDR size']
-                       - $structSize, $structSize );
+               $start = $this->getFileLength() - $this->eocdr['EOCDR size'] - 
$structSize;
+               $block = $this->getBlock( $start, $structSize );
                $this->eocdr64Locator = $data = $this->unpack( $block, $info );
 
                if ( $data['signature'] !== "PK\x06\x07" ) {

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I495481e3532834f1f8a45cda9402d609de7e2bd7
Gerrit-PatchSet: 7
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Siebrand <[email protected]>
Gerrit-Reviewer: Chad <[email protected]>
Gerrit-Reviewer: Hashar <[email protected]>
Gerrit-Reviewer: Reedy <[email protected]>
Gerrit-Reviewer: Siebrand <[email protected]>
Gerrit-Reviewer: jenkins-bot

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

Reply via email to