From 4fd27f006f3a233f2bed8585b1325d318763abb0 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Bartosz=20Dziewo=C5=84ski?= Date: Fri, 6 Oct 2017 21:17:52 +0200 Subject: [PATCH] Use PHP 5.6 '**' operator instead of 'pow()' function Change-Id: Ieb22e1dbfcffaa4e7b3dcfabbcc999e5dd59a4bf --- includes/diff/DiffEngine.php | 2 +- includes/libs/IP.php | 6 ++--- .../libs/filebackend/FileBackendStore.php | 2 +- includes/media/FormatMetadata.php | 2 +- includes/media/GIFMetadataExtractor.php | 2 +- includes/utils/UIDGenerator.php | 8 +++---- includes/utils/ZipDirectoryReader.php | 2 +- maintenance/generateSitemap.php | 2 +- maintenance/storage/storageTypeStats.php | 2 +- .../includes/api/RandomImageGenerator.php | 2 +- tests/phpunit/languages/LanguageTest.php | 24 +++++++++---------- 11 files changed, 27 insertions(+), 27 deletions(-) diff --git a/includes/diff/DiffEngine.php b/includes/diff/DiffEngine.php index 273d1d61f6..142c51d7a0 100644 --- a/includes/diff/DiffEngine.php +++ b/includes/diff/DiffEngine.php @@ -351,7 +351,7 @@ class DiffEngine { $this->maxDifferences = ceil( ( $this->m + $this->n ) / 2.0 ); if ( $this->m * $this->n > $this->tooLong ) { // limit complexity to D^POW_LIMIT for long sequences - $this->maxDifferences = floor( pow( $this->maxDifferences, $this->powLimit - 1.0 ) ); + $this->maxDifferences = floor( $this->maxDifferences ** ( $this->powLimit - 1.0 ) ); wfDebug( "Limiting max number of differences to $this->maxDifferences\n" ); } diff --git a/includes/libs/IP.php b/includes/libs/IP.php index 06589d2787..8efcd1589b 100644 --- a/includes/libs/IP.php +++ b/includes/libs/IP.php @@ -425,7 +425,7 @@ class IP { $ip = self::sanitizeIP( $ip ); $n = ip2long( $ip ); if ( $n < 0 ) { - $n += pow( 2, 32 ); + $n += 2 ** 32; # On 32-bit platforms (and on Windows), 2^32 does not fit into an int, # so $n becomes a float. We convert it to string instead. if ( is_float( $n ) ) { @@ -487,7 +487,7 @@ class IP { } # Convert to unsigned if ( $network < 0 ) { - $network += pow( 2, 32 ); + $network += 2 ** 32; } } else { $network = false; @@ -523,7 +523,7 @@ class IP { $start = $end = false; } else { $start = sprintf( '%08X', $network ); - $end = sprintf( '%08X', $network + pow( 2, ( 32 - $bits ) ) - 1 ); + $end = sprintf( '%08X', $network + 2 ** ( 32 - $bits ) - 1 ); } // Explicit range } elseif ( strpos( $range, '-' ) !== false ) { diff --git a/includes/libs/filebackend/FileBackendStore.php b/includes/libs/filebackend/FileBackendStore.php index 06b263a8c6..16ea3ea497 100644 --- a/includes/libs/filebackend/FileBackendStore.php +++ b/includes/libs/filebackend/FileBackendStore.php @@ -1560,7 +1560,7 @@ abstract class FileBackendStore extends FileBackend { $shards = []; list( $digits, $base ) = $this->getContainerHashLevels( $container ); if ( $digits > 0 ) { - $numShards = pow( $base, $digits ); + $numShards = $base ** $digits; for ( $index = 0; $index < $numShards; $index++ ) { $shards[] = '.' . Wikimedia\base_convert( $index, 10, $base, $digits ); } diff --git a/includes/media/FormatMetadata.php b/includes/media/FormatMetadata.php index 2a8b375a40..52d7373aab 100644 --- a/includes/media/FormatMetadata.php +++ b/includes/media/FormatMetadata.php @@ -787,7 +787,7 @@ class FormatMetadata extends ContextSource { } } if ( is_numeric( $val ) ) { - $fNumber = pow( 2, $val / 2 ); + $fNumber = 2 ** ( $val / 2 ); if ( $fNumber !== false ) { $val = $this->msg( 'exif-maxaperturevalue-value', $this->formatNum( $val ), diff --git a/includes/media/GIFMetadataExtractor.php b/includes/media/GIFMetadataExtractor.php index a26539a87a..591ccf191f 100644 --- a/includes/media/GIFMetadataExtractor.php +++ b/includes/media/GIFMetadataExtractor.php @@ -264,7 +264,7 @@ class GIFMetadataExtractor { */ static function readGCT( $fh, $bpp ) { if ( $bpp > 0 ) { - $max = pow( 2, $bpp ); + $max = 2 ** $bpp; for ( $i = 1; $i <= $max; ++$i ) { fread( $fh, 3 ); } diff --git a/includes/utils/UIDGenerator.php b/includes/utils/UIDGenerator.php index 4d5c3af82f..c23d99920c 100644 --- a/includes/utils/UIDGenerator.php +++ b/includes/utils/UIDGenerator.php @@ -400,14 +400,14 @@ class UIDGenerator { // Write back the new counter value ftruncate( $handle, 0 ); rewind( $handle ); - fwrite( $handle, fmod( $counter, pow( 2, 48 ) ) ); // warp-around as needed + fwrite( $handle, fmod( $counter, 2 ** 48 ) ); // warp-around as needed fflush( $handle ); // Release the UID lock file flock( $handle, LOCK_UN ); } $ids = []; - $divisor = pow( 2, $bits ); + $divisor = 2 ** $bits; $currentId = floor( $counter - $count ); // pre-increment counter value for ( $i = 0; $i < $count; ++$i ) { $ids[] = fmod( ++$currentId, $divisor ); @@ -532,7 +532,7 @@ class UIDGenerator { protected function millisecondsSinceEpochBinary( array $time ) { list( $sec, $msec ) = $time; $ts = 1000 * $sec + $msec; - if ( $ts > pow( 2, 52 ) ) { + if ( $ts > 2 ** 52 ) { throw new RuntimeException( __METHOD__ . ': sorry, this function doesn\'t work after the year 144680' ); } @@ -551,7 +551,7 @@ class UIDGenerator { $offset = '122192928000000000'; if ( PHP_INT_SIZE >= 8 ) { // 64 bit integers $ts = ( 1000 * $sec + $msec ) * 10000 + (int)$offset + $delta; - $id_bin = str_pad( decbin( $ts % pow( 2, 60 ) ), 60, '0', STR_PAD_LEFT ); + $id_bin = str_pad( decbin( $ts % ( 2 ** 60 ) ), 60, '0', STR_PAD_LEFT ); } elseif ( extension_loaded( 'gmp' ) ) { $ts = gmp_add( gmp_mul( (string)$sec, '1000' ), (string)$msec ); // ms $ts = gmp_add( gmp_mul( $ts, '10000' ), $offset ); // 100ns intervals diff --git a/includes/utils/ZipDirectoryReader.php b/includes/utils/ZipDirectoryReader.php index f0ace2ccb3..20bad13515 100644 --- a/includes/utils/ZipDirectoryReader.php +++ b/includes/utils/ZipDirectoryReader.php @@ -656,7 +656,7 @@ class ZipDirectoryReader { } // Throw an exception if there was loss of precision - if ( $value > pow( 2, 52 ) ) { + if ( $value > 2 ** 52 ) { $this->error( 'zip-unsupported', 'number too large to be stored in a double. ' . 'This could happen if we tried to unpack a 64-bit structure ' . 'at an invalid location.' ); diff --git a/maintenance/generateSitemap.php b/maintenance/generateSitemap.php index 5a2c6c7bdf..e2dc9b8263 100644 --- a/maintenance/generateSitemap.php +++ b/maintenance/generateSitemap.php @@ -177,7 +177,7 @@ class GenerateSitemap extends Maintenance { public function execute() { $this->setNamespacePriorities(); $this->url_limit = 50000; - $this->size_limit = pow( 2, 20 ) * 10; + $this->size_limit = ( 2 ** 20 ) * 10; # Create directory if needed $fspath = $this->getOption( 'fspath', getcwd() ); diff --git a/maintenance/storage/storageTypeStats.php b/maintenance/storage/storageTypeStats.php index 9ba3d1b9a7..af9dd088dc 100644 --- a/maintenance/storage/storageTypeStats.php +++ b/maintenance/storage/storageTypeStats.php @@ -31,7 +31,7 @@ class StorageTypeStats extends Maintenance { exit( 1 ); } - $binSize = intval( pow( 10, floor( log10( $endId ) ) - 3 ) ); + $binSize = intval( 10 ** ( floor( log10( $endId ) ) - 3 ) ); if ( $binSize < 100 ) { $binSize = 100; } diff --git a/tests/phpunit/includes/api/RandomImageGenerator.php b/tests/phpunit/includes/api/RandomImageGenerator.php index 50a59f97e8..7fd5f1dd38 100644 --- a/tests/phpunit/includes/api/RandomImageGenerator.php +++ b/tests/phpunit/includes/api/RandomImageGenerator.php @@ -187,7 +187,7 @@ class RandomImageGenerator { $spec['height'] = mt_rand( $this->minHeight, $this->maxHeight ); $spec['fill'] = $this->getRandomColor(); - $diagonalLength = sqrt( pow( $spec['width'], 2 ) + pow( $spec['height'], 2 ) ); + $diagonalLength = sqrt( $spec['width'] ** 2 + $spec['height'] ** 2 ); $draws = []; for ( $i = 0; $i <= $this->shapesToDraw; $i++ ) { diff --git a/tests/phpunit/languages/LanguageTest.php b/tests/phpunit/languages/LanguageTest.php index 050ed83bed..8653bcd5b8 100644 --- a/tests/phpunit/languages/LanguageTest.php +++ b/tests/phpunit/languages/LanguageTest.php @@ -1110,27 +1110,27 @@ class LanguageTest extends LanguageClassesTestCase { "1 gigabyte" ], [ - pow( 1024, 4 ), + 1024 ** 4, "1 TB", "1 terabyte" ], [ - pow( 1024, 5 ), + 1024 ** 5, "1 PB", "1 petabyte" ], [ - pow( 1024, 6 ), + 1024 ** 6, "1 EB", "1,024 exabyte" ], [ - pow( 1024, 7 ), + 1024 ** 7, "1 ZB", "1 zetabyte" ], [ - pow( 1024, 8 ), + 1024 ** 8, "1 YB", "1 yottabyte" ], @@ -1173,37 +1173,37 @@ class LanguageTest extends LanguageClassesTestCase { "1 megabit per second" ], [ - pow( 10, 9 ), + 10 ** 9, "1 Gbps", "1 gigabit per second" ], [ - pow( 10, 12 ), + 10 ** 12, "1 Tbps", "1 terabit per second" ], [ - pow( 10, 15 ), + 10 ** 15, "1 Pbps", "1 petabit per second" ], [ - pow( 10, 18 ), + 10 ** 18, "1 Ebps", "1 exabit per second" ], [ - pow( 10, 21 ), + 10 ** 21, "1 Zbps", "1 zetabit per second" ], [ - pow( 10, 24 ), + 10 ** 24, "1 Ybps", "1 yottabit per second" ], [ - pow( 10, 27 ), + 10 ** 27, "1,000 Ybps", "1,000 yottabits per second" ], -- 2.20.1