Merge "Update type of PermissionManager::resultToError"
[lhc/web/wiklou.git] / includes / libs / Xhprof.php
index e58d98f..8175427 100644 (file)
@@ -54,13 +54,14 @@ class Xhprof {
                        throw new Exception( 'Profiling is already enabled.' );
                }
                self::$enabled = true;
-               if ( function_exists( 'xhprof_enable' ) ) {
-                       xhprof_enable( $flags, $options );
-               } elseif ( function_exists( 'tideways_enable' ) ) {
-                       tideways_enable( $flags, $options );
-               } else {
-                       throw new Exception( "Neither xhprof nor tideways are installed" );
-               }
+               self::callAny(
+                       [
+                               'xhprof_enable',
+                               'tideways_enable',
+                               'tideways_xhprof_enable'
+                       ],
+                       [ $flags, $options ]
+               );
        }
 
        /**
@@ -71,12 +72,27 @@ class Xhprof {
        public static function disable() {
                if ( self::isEnabled() ) {
                        self::$enabled = false;
-                       if ( function_exists( 'xhprof_disable' ) ) {
-                               return xhprof_disable();
-                       } else {
-                               // tideways
-                               return tideways_disable();
+                       return self::callAny( [
+                               'xhprof_disable',
+                               'tideways_disable',
+                               'tideways_xhprof_disable'
+                       ] );
+               }
+       }
+
+       /**
+        * Call the first available function from $functions.
+        * @param array $functions
+        * @param array $args
+        * @throws Exception
+        */
+       protected static function callAny( array $functions, array $args = [] ) {
+               foreach ( $functions as $func ) {
+                       if ( function_exists( $func ) ) {
+                               return $func( ...$args );
                        }
                }
+
+               throw new Exception( "Neither xhprof nor tideways are installed" );
        }
 }