Use PHP 5.6 '**' operator instead of 'pow()' function
authorBartosz Dziewoński <matma.rex@gmail.com>
Fri, 6 Oct 2017 19:17:52 +0000 (21:17 +0200)
committerJames D. Forrester <jforrester@wikimedia.org>
Thu, 31 May 2018 01:05:19 +0000 (18:05 -0700)
Change-Id: Ieb22e1dbfcffaa4e7b3dcfabbcc999e5dd59a4bf

includes/diff/DiffEngine.php
includes/libs/IP.php
includes/libs/filebackend/FileBackendStore.php
includes/media/FormatMetadata.php
includes/media/GIFMetadataExtractor.php
includes/utils/UIDGenerator.php
includes/utils/ZipDirectoryReader.php
maintenance/generateSitemap.php
maintenance/storage/storageTypeStats.php
tests/phpunit/includes/api/RandomImageGenerator.php
tests/phpunit/languages/LanguageTest.php

index 273d1d6..142c51d 100644 (file)
@@ -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" );
                        }
 
index 06589d2..8efcd15 100644 (file)
@@ -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 ) {
index 06b263a..16ea3ea 100644 (file)
@@ -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 );
                        }
index 2a8b375..52d7373 100644 (file)
@@ -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 ),
index a26539a..591ccf1 100644 (file)
@@ -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 );
                        }
index 4d5c3af..c23d999 100644 (file)
@@ -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
index f0ace2c..20bad13 100644 (file)
@@ -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.' );
index 5a2c6c7..e2dc9b8 100644 (file)
@@ -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() );
index 9ba3d1b..af9dd08 100644 (file)
@@ -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;
                }
index 50a59f9..7fd5f1d 100644 (file)
@@ -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++ ) {
index 050ed83..8653bcd 100644 (file)
@@ -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"
                        ],