Use callable type-hint in a few places
authorKunal Mehta <legoktm@member.fsf.org>
Tue, 7 Jun 2016 23:39:06 +0000 (16:39 -0700)
committerKunal Mehta <legoktm@member.fsf.org>
Tue, 7 Jun 2016 23:39:22 +0000 (16:39 -0700)
Mostly places which immediately had a:
 if ( !is_callable( $callback ) ) {
  throw new Exception(...);
 }
check at the beginning of the function.

Change-Id: Ia78663b2231629010816bd1cda8814b996968d1d

includes/db/DBConnRef.php
includes/db/Database.php
includes/db/IDatabase.php
includes/libs/objectcache/BagOStuff.php
includes/libs/objectcache/EmptyBagOStuff.php
includes/libs/objectcache/MemcachedBagOStuff.php
includes/libs/objectcache/ReplicatedBagOStuff.php
includes/libs/objectcache/WinCacheBagOStuff.php
includes/objectcache/SqlBagOStuff.php

index d73ba85..af5f8f9 100644 (file)
@@ -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() );
        }
 
index 92e89b0..6bdcb24 100644 (file)
@@ -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 ] );
index 710efb2..0a71df2 100644 (file)
@@ -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,
index dd22d91..1a2711a 100644 (file)
@@ -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 );
        }
 
index 4321b25..408212a 100644 (file)
@@ -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
        }
 }
index 7a36214..ba8c736 100644 (file)
@@ -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 );
        }
 
index 40ac1bb..5f2c509 100644 (file)
@@ -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 );
        }
 
index 3d72abe..19cc66a 100644 (file)
@@ -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 );
        }
 }
index a1394c1..98b6eb9 100644 (file)
@@ -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();