diff options
author | Umherirrender <umherirrender_de.wp@web.de> | 2022-02-26 17:28:48 +0100 |
---|---|---|
committer | Umherirrender <umherirrender_de.wp@web.de> | 2022-03-01 18:19:33 +0100 |
commit | 9efd9ca45ec67ca17fdbb00fd0242966d6692caf (patch) | |
tree | 817815ded23dfb5b1b71d9e3b9ed7d7023214bbc /includes/objectcache | |
parent | b042d6577643985624d0f4ee867806e30b14c16b (diff) | |
download | mediawikicore-9efd9ca45ec67ca17fdbb00fd0242966d6692caf.tar.gz mediawikicore-9efd9ca45ec67ca17fdbb00fd0242966d6692caf.zip |
Add explicit casts between scalar types
* Some functions accept only string, cast ints and floats to string
* After preg_matches or explode() casts numbers to int to do maths
* Cast unix timestamps to int to do maths
* Cast return values from timestamp format function to int
* Cast bitwise operator to bool when needed as bool
* php internal functions like floor/round/ceil documented to return
float, most cases the result is used as int, added casts
Found by phan strict checks
Change-Id: Icb2de32107f43817acc45fe296fb77acf65c1786
Diffstat (limited to 'includes/objectcache')
-rw-r--r-- | includes/objectcache/SqlBagOStuff.php | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/includes/objectcache/SqlBagOStuff.php b/includes/objectcache/SqlBagOStuff.php index da555931957d..c5ae117f6b27 100644 --- a/includes/objectcache/SqlBagOStuff.php +++ b/includes/objectcache/SqlBagOStuff.php @@ -499,7 +499,7 @@ class SqlBagOStuff extends MediumSpecificBagOStuff { */ private function getTableNameByShard( $index ) { if ( $index !== null && $this->numTableShards > 1 ) { - $decimals = strlen( $this->numTableShards - 1 ); + $decimals = strlen( (string)( $this->numTableShards - 1 ) ); return $this->tableName . sprintf( "%0{$decimals}d", $index ); } @@ -1103,7 +1103,7 @@ class SqlBagOStuff extends MediumSpecificBagOStuff { // 67 bit integral portion of UNIX timestamp, qualified \Wikimedia\base_convert( // 35 bit integral seconds portion of UNIX timestamp - str_pad( base_convert( $seconds, 10, 2 ), 35, '0', STR_PAD_LEFT ) . + str_pad( base_convert( (string)$seconds, 10, 2 ), 35, '0', STR_PAD_LEFT ) . // 32 bit ID of the primary database server handling the write str_pad( base_convert( $id, 10, 2 ), 32, '0', STR_PAD_LEFT ), 2, @@ -1484,7 +1484,7 @@ class SqlBagOStuff extends MediumSpecificBagOStuff { if ( $res->numRows() ) { $row = $res->current(); if ( $minExpUnix === null ) { - $minExpUnix = ConvertibleTimestamp::convert( TS_UNIX, $row->exptime ); + $minExpUnix = (int)ConvertibleTimestamp::convert( TS_UNIX, $row->exptime ); $totalSeconds = max( $cutoffUnix - $minExpUnix, 1 ); } @@ -1507,7 +1507,7 @@ class SqlBagOStuff extends MediumSpecificBagOStuff { if ( $progress && is_callable( $progress['fn'] ) ) { if ( $totalSeconds ) { - $maxExpUnix = ConvertibleTimestamp::convert( TS_UNIX, $maxExp ); + $maxExpUnix = (int)ConvertibleTimestamp::convert( TS_UNIX, $maxExp ); $remainingSeconds = $cutoffUnix - $maxExpUnix; $processedSeconds = max( $totalSeconds - $remainingSeconds, 0 ); // For example, if we've done 1.5 table shard, and are thus half-way on the |