From: Kunal Mehta Date: Tue, 7 Jun 2016 23:39:06 +0000 (-0700) Subject: Use callable type-hint in a few places X-Git-Tag: 1.31.0-rc.0~6687^2 X-Git-Url: http://git.cyclocoop.org//%27%40script%40/%27?a=commitdiff_plain;h=4a8ae0a0b466ed300d75e7f77046683be459c03d;p=lhc%2Fweb%2Fwiklou.git Use callable type-hint in a few places Mostly places which immediately had a: if ( !is_callable( $callback ) ) { throw new Exception(...); } check at the beginning of the function. Change-Id: Ia78663b2231629010816bd1cda8814b996968d1d --- diff --git a/includes/db/DBConnRef.php b/includes/db/DBConnRef.php index d73ba85fc0..af5f8f9fee 100644 --- a/includes/db/DBConnRef.php +++ b/includes/db/DBConnRef.php @@ -433,7 +433,7 @@ class DBConnRef implements IDatabase { return $this->__call( __FUNCTION__, func_get_args() ); } - public function doAtomicSection( $fname, $callback ) { + public function doAtomicSection( $fname, callable $callback ) { return $this->__call( __FUNCTION__, func_get_args() ); } diff --git a/includes/db/Database.php b/includes/db/Database.php index 92e89b0de1..6bdcb24cdb 100644 --- a/includes/db/Database.php +++ b/includes/db/Database.php @@ -2561,11 +2561,7 @@ abstract class DatabaseBase implements IDatabase { } } - final public function doAtomicSection( $fname, $callback ) { - if ( !is_callable( $callback ) ) { - throw new UnexpectedValueException( "Invalid callback." ); - }; - + final public function doAtomicSection( $fname, callable $callback ) { $this->startAtomic( $fname ); try { call_user_func_array( $callback, [ $this, $fname ] ); diff --git a/includes/db/IDatabase.php b/includes/db/IDatabase.php index 710efb2ca6..0a71df2312 100644 --- a/includes/db/IDatabase.php +++ b/includes/db/IDatabase.php @@ -1313,7 +1313,7 @@ interface IDatabase { * @throws UnexpectedValueException * @since 1.27 */ - public function doAtomicSection( $fname, $callback ); + public function doAtomicSection( $fname, callable $callback ); /** * Begin a transaction. If a transaction is already in progress, diff --git a/includes/libs/objectcache/BagOStuff.php b/includes/libs/objectcache/BagOStuff.php index dd22d9144d..1a2711abe9 100644 --- a/includes/libs/objectcache/BagOStuff.php +++ b/includes/libs/objectcache/BagOStuff.php @@ -267,11 +267,7 @@ abstract class BagOStuff implements IExpiringStore, LoggerAwareInterface { * @return bool Success * @throws InvalidArgumentException */ - public function merge( $key, $callback, $exptime = 0, $attempts = 10, $flags = 0 ) { - if ( !is_callable( $callback ) ) { - throw new InvalidArgumentException( "Got invalid callback." ); - } - + public function merge( $key, callable $callback, $exptime = 0, $attempts = 10, $flags = 0 ) { return $this->mergeViaLock( $key, $callback, $exptime, $attempts, $flags ); } diff --git a/includes/libs/objectcache/EmptyBagOStuff.php b/includes/libs/objectcache/EmptyBagOStuff.php index 4321b25ffb..408212a1b3 100644 --- a/includes/libs/objectcache/EmptyBagOStuff.php +++ b/includes/libs/objectcache/EmptyBagOStuff.php @@ -39,7 +39,7 @@ class EmptyBagOStuff extends BagOStuff { return true; } - public function merge( $key, $callback, $exptime = 0, $attempts = 10, $flags = 0 ) { + public function merge( $key, callable $callback, $exptime = 0, $attempts = 10, $flags = 0 ) { return true; // faster } } diff --git a/includes/libs/objectcache/MemcachedBagOStuff.php b/includes/libs/objectcache/MemcachedBagOStuff.php index 7a36214724..ba8c7363fc 100644 --- a/includes/libs/objectcache/MemcachedBagOStuff.php +++ b/includes/libs/objectcache/MemcachedBagOStuff.php @@ -75,11 +75,7 @@ class MemcachedBagOStuff extends BagOStuff { $this->fixExpiry( $exptime ) ); } - public function merge( $key, $callback, $exptime = 0, $attempts = 10, $flags = 0 ) { - if ( !is_callable( $callback ) ) { - throw new Exception( "Got invalid callback." ); - } - + public function merge( $key, callable $callback, $exptime = 0, $attempts = 10, $flags = 0 ) { return $this->mergeViaCas( $key, $callback, $exptime, $attempts ); } diff --git a/includes/libs/objectcache/ReplicatedBagOStuff.php b/includes/libs/objectcache/ReplicatedBagOStuff.php index 40ac1bb3a7..5f2c509ed6 100644 --- a/includes/libs/objectcache/ReplicatedBagOStuff.php +++ b/includes/libs/objectcache/ReplicatedBagOStuff.php @@ -112,7 +112,7 @@ class ReplicatedBagOStuff extends BagOStuff { return $this->writeStore->unlock( $key ); } - public function merge( $key, $callback, $exptime = 0, $attempts = 10, $flags = 0 ) { + public function merge( $key, callable $callback, $exptime = 0, $attempts = 10, $flags = 0 ) { return $this->writeStore->merge( $key, $callback, $exptime, $attempts, $flags ); } diff --git a/includes/libs/objectcache/WinCacheBagOStuff.php b/includes/libs/objectcache/WinCacheBagOStuff.php index 3d72abe84f..19cc66a8ba 100644 --- a/includes/libs/objectcache/WinCacheBagOStuff.php +++ b/includes/libs/objectcache/WinCacheBagOStuff.php @@ -64,11 +64,7 @@ class WinCacheBagOStuff extends BagOStuff { return true; } - public function merge( $key, $callback, $exptime = 0, $attempts = 10, $flags = 0 ) { - if ( !is_callable( $callback ) ) { - throw new Exception( "Got invalid callback." ); - } - + public function merge( $key, callable $callback, $exptime = 0, $attempts = 10, $flags = 0 ) { return $this->mergeViaCas( $key, $callback, $exptime, $attempts ); } } diff --git a/includes/objectcache/SqlBagOStuff.php b/includes/objectcache/SqlBagOStuff.php index a1394c13f8..98b6eb94da 100644 --- a/includes/objectcache/SqlBagOStuff.php +++ b/includes/objectcache/SqlBagOStuff.php @@ -459,11 +459,7 @@ class SqlBagOStuff extends BagOStuff { return $newValue; } - public function merge( $key, $callback, $exptime = 0, $attempts = 10, $flags = 0 ) { - if ( !is_callable( $callback ) ) { - throw new Exception( "Got invalid callback." ); - } - + public function merge( $key, callable $callback, $exptime = 0, $attempts = 10, $flags = 0 ) { $ok = $this->mergeViaCas( $key, $callback, $exptime, $attempts ); if ( ( $flags & self::WRITE_SYNC ) == self::WRITE_SYNC ) { $ok = $ok && $this->waitForSlaves();