From 03d7247e047c21d2733f837148a1499f56784ae3 Mon Sep 17 00:00:00 2001
From: Dominik Eckelmann <deckelmann@gmail.com>
Date: Sun, 5 Feb 2012 12:36:19 +0100
Subject: [PATCH] moved plugin and core method calls to seperate function

---
 inc/remote.php | 38 +++++++++++++++++++++++---------------
 1 file changed, 23 insertions(+), 15 deletions(-)

diff --git a/inc/remote.php b/inc/remote.php
index 82a0d3c08..105969f8b 100644
--- a/inc/remote.php
+++ b/inc/remote.php
@@ -82,23 +82,31 @@ class RemoteAPI {
         }
         list($type, $pluginName, $call) = explode('.', $method, 3);
         if ($type === 'plugin') {
-            $plugin = plugin_load('remote', $pluginName);
-            $methods = $this->getPluginMethods();
-            if (!$plugin) {
-                throw new RemoteException('Method dose not exists');
-            }
-            $this->checkAccess($methods[$method]);
-            $name = $this->getMethodName($methods, $method);
-            return call_user_func_array(array($plugin, $name), $args);
+            return $this->callPlugin($pluginName, $method, $args);
         } else {
-            $coreMethods = $this->getCoreMethods();
-            $this->checkAccess($coreMethods[$method]);
-            if (!isset($coreMethods[$method])) {
-                throw new RemoteException('Method dose not exists');
-            }
-            $this->checkArgumentLength($coreMethods[$method], $args);
-            return call_user_func_array(array($this->coreMethods, $this->getMethodName($coreMethods, $method)), $args);
+            return $this->callCoreMethod($method, $args);
+        }
+    }
+
+    private function callPlugin($pluginName, $method, $args) {
+        $plugin = plugin_load('remote', $pluginName);
+        $methods = $this->getPluginMethods();
+        if (!$plugin) {
+            throw new RemoteException('Method dose not exists');
+        }
+        $this->checkAccess($methods[$method]);
+        $name = $this->getMethodName($methods, $method);
+        return call_user_func_array(array($plugin, $name), $args);
+    }
+
+    private function callCoreMethod($method, $args) {
+        $coreMethods = $this->getCoreMethods();
+        $this->checkAccess($coreMethods[$method]);
+        if (!isset($coreMethods[$method])) {
+            throw new RemoteException('Method dose not exists');
         }
+        $this->checkArgumentLength($coreMethods[$method], $args);
+        return call_user_func_array(array($this->coreMethods, $this->getMethodName($coreMethods, $method)), $args);
     }
 
     private function checkAccess($methodMeta) {
-- 
GitLab