From: Siebrand Mazeland Date: Mon, 4 Nov 2013 10:02:48 +0000 (+0100) Subject: Address some PHP CodeSniffer errors and warnings X-Git-Tag: 1.31.0-rc.0~18240 X-Git-Url: http://git.cyclocoop.org/%24href?a=commitdiff_plain;h=7a95d47961b1aa2d60c483603902e485b5dd1d8f;p=lhc%2Fweb%2Fwiklou.git Address some PHP CodeSniffer errors and warnings Change-Id: I495481e3532834f1f8a45cda9402d609de7e2bd7 --- diff --git a/includes/AutoLoader.php b/includes/AutoLoader.php index f79fdc9243..29d2209373 100644 --- a/includes/AutoLoader.php +++ b/includes/AutoLoader.php @@ -843,12 +843,14 @@ $wgAutoloadLocalClasses = array( '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 f14921d6b6..e7bb4bc59b 100644 --- a/includes/utils/CdbPHP.php +++ b/includes/utils/CdbPHP.php @@ -73,7 +73,8 @@ class CdbFunctions { */ 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 163f73c746..a2fe507b86 100644 --- a/includes/utils/ConfEditor.php +++ b/includes/utils/ConfEditor.php @@ -444,7 +444,8 @@ class ConfEditor { $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 d71193f0d1..0172974d6a 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 @@ class MWCryptRand { $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 @@ class MWCryptRand { * @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 @@ class MWCryptRand { 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 @@ class MWCryptRand { 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 @@ class MWCryptRand { 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 @@ class MWCryptRand { } // 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 @@ class MWCryptRand { $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 @@ class MWCryptRand { // 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 @@ class MWCryptRand { $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 0ebba2a5f4..167c268ea3 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 @@ class StringUtils { * @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 @@ class StringUtils { * StringUtils::delimiterReplaceCallback() */ class Replacer { - /** * @return array */ @@ -360,7 +360,6 @@ class RegexlikeReplacer extends Replacer { * 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 7bf538aad2..5c92525e32 100644 --- a/includes/utils/ZipDirectoryReader.php +++ b/includes/utils/ZipDirectoryReader.php @@ -247,8 +247,8 @@ class ZipDirectoryReader { ); $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" ) {