From c782b8ccd740a206bf2b7af393dcade94a38ef7d Mon Sep 17 00:00:00 2001
From: mattab <matthieu.aubry@gmail.com>
Date: Thu, 10 Oct 2013 17:52:46 +1300
Subject: [PATCH] Refs #4208 refactor all singletons except the hard ones (with
 custom getInstance() (some tests failing)

---
 core/API/Proxy.php                        | 22 ++------------
 core/Config.php                           | 19 ++----------
 core/DataTable/Manager.php                | 18 ++---------
 core/Db/Schema.php                        | 21 ++-----------
 core/EventDispatcher.php                  | 18 +----------
 core/FrontController.php                  | 17 +----------
 core/Log.php                              | 33 ++------------------
 core/Menu/MenuAbstract.php                |  3 +-
 core/Menu/MenuAdmin.php                   | 13 --------
 core/Menu/MenuMain.php                    | 13 --------
 core/Menu/MenuTop.php                     | 14 ---------
 core/Plugin/API.php                       | 18 +++++++++++
 core/Plugin/Controller.php                | 11 +++----
 core/Plugin/Manager.php                   | 18 ++---------
 core/Registry.php                         | 18 ++---------
 core/Singleton.php                        | 37 +++++++++++++++++++++++
 piwik.php                                 |  1 +
 plugins/API/API.php                       | 15 +--------
 plugins/Actions/API.php                   | 15 +--------
 plugins/Annotations/API.php               | 17 +----------
 plugins/CoreAdminHome/API.php             | 15 +--------
 plugins/CoreConsole/templates/api/API.php | 16 +---------
 plugins/CustomVariables/API.php           | 15 +--------
 plugins/DBStats/API.php                   | 18 ++---------
 plugins/Dashboard/API.php                 | 21 ++-----------
 plugins/DevicesDetection/API.php          | 17 +----------
 plugins/ExampleAPI/API.php                | 36 +---------------------
 plugins/ExampleUI/API.php                 | 16 +---------
 plugins/Goals/API.php                     | 15 +--------
 plugins/ImageGraph/API.php                | 16 +---------
 plugins/LanguagesManager/API.php          | 15 +--------
 plugins/Live/API.php                      | 15 +--------
 plugins/MobileMessaging/API.php           | 15 +--------
 plugins/MultiSites/API.php                | 22 +-------------
 plugins/Overlay/API.php                   | 17 +----------
 plugins/Provider/API.php                  | 12 +-------
 plugins/Referrers/API.php                 | 12 +-------
 plugins/SEO/API.php                       | 15 +--------
 plugins/ScheduledReports/API.php          | 15 +--------
 plugins/SegmentEditor/API.php             | 15 +--------
 plugins/SitesManager/API.php              | 15 +--------
 plugins/Transitions/API.php               | 13 +-------
 plugins/UserCountry/API.php               | 12 +-------
 plugins/UserSettings/API.php              | 12 +-------
 plugins/UsersManager/API.php              |  2 +-
 plugins/VisitFrequency/API.php            | 12 +-------
 plugins/VisitTime/API.php                 | 12 +-------
 plugins/VisitorInterest/API.php           | 12 +-------
 plugins/VisitsSummary/API.php             | 15 +--------
 tests/PHPUnit/Core/LogTest.php            |  4 +--
 50 files changed, 115 insertions(+), 673 deletions(-)
 create mode 100644 core/Plugin/API.php
 create mode 100644 core/Singleton.php

diff --git a/core/API/Proxy.php b/core/API/Proxy.php
index 43d07bc25f..f504bdeb8f 100644
--- a/core/API/Proxy.php
+++ b/core/API/Proxy.php
@@ -14,6 +14,7 @@ namespace Piwik\API;
 use Exception;
 use Piwik\Common;
 use Piwik\Piwik;
+use Piwik\Singleton;
 use ReflectionClass;
 use ReflectionMethod;
 
@@ -28,7 +29,7 @@ use ReflectionMethod;
  * @package Piwik
  * @subpackage Piwik_API
  */
-class Proxy
+class Proxy extends Singleton
 {
     // array of already registered plugins names
     protected $alreadyRegistered = array();
@@ -39,12 +40,6 @@ class Proxy
     // when a parameter doesn't have a default value we use this
     private $noDefaultValue;
 
-    /**
-     * Singleton instance
-     * @var \Piwik\API\Proxy|null
-     */
-    static private $instance = null;
-
     /**
      * protected constructor
      */
@@ -53,19 +48,6 @@ class Proxy
         $this->noDefaultValue = new NoDefaultValue();
     }
 
-    /**
-     * Singleton, returns instance
-     *
-     * @return \Piwik\API\Proxy
-     */
-    static public function getInstance()
-    {
-        if (self::$instance == null) {
-            self::$instance = new self;
-        }
-        return self::$instance;
-    }
-
     /**
      * Returns array containing reflection meta data for all the loaded classes
      * eg. number of parameters, method names, etc.
diff --git a/core/Config.php b/core/Config.php
index 1ed8ddee47..c7a5ad9d27 100644
--- a/core/Config.php
+++ b/core/Config.php
@@ -42,23 +42,8 @@ use Exception;
  * @package Piwik
  * @subpackage Piwik_Config
  */
-class Config
+class Config extends Singleton
 {
-    private static $instance = null;
-
-    /**
-     * Returns the singleton Piwik_Config
-     *
-     * @return \Piwik\Config
-     * @api
-     */
-    public static function getInstance()
-    {
-        if (self::$instance == null) {
-            self::$instance = new self;
-        }
-        return self::$instance;
-    }
 
     /**
      * Contains configuration files values
@@ -298,7 +283,7 @@ class Config
 
             // must be called here, not in init(), since setTestEnvironment() calls init(). (this avoids
             // infinite recursion)
-            Piwik::postTestEvent('Config.createConfigSingleton', array(self::$instance));
+            Piwik::postTestEvent('Config.createConfigSingleton', array( $this->getInstance() ));
         }
 
         // check cache for merged section
diff --git a/core/DataTable/Manager.php b/core/DataTable/Manager.php
index b32463b176..0ae03ede89 100644
--- a/core/DataTable/Manager.php
+++ b/core/DataTable/Manager.php
@@ -14,6 +14,7 @@ namespace Piwik\DataTable;
 use Exception;
 use Piwik\Common;
 use Piwik\DataTable;
+use Piwik\Singleton;
 
 /**
  * The DataTable_Manager registers all the instanciated DataTable and provides an
@@ -23,23 +24,8 @@ use Piwik\DataTable;
  * @package Piwik
  * @subpackage DataTable
  */
-class Manager
+class Manager extends Singleton
 {
-    static private $instance = null;
-
-    /**
-     * Returns instance
-     *
-     * @return \Piwik\DataTable\Manager
-     */
-    static public function getInstance()
-    {
-        if (self::$instance == null) {
-            self::$instance = new self;
-        }
-        return self::$instance;
-    }
-
     /**
      * Array used to store the DataTable
      *
diff --git a/core/Db/Schema.php b/core/Db/Schema.php
index 015899928c..5ce1d55d62 100644
--- a/core/Db/Schema.php
+++ b/core/Db/Schema.php
@@ -11,6 +11,7 @@
 namespace Piwik\Db;
 
 use Piwik\Config;
+use Piwik\Singleton;
 
 /**
  * Schema abstraction
@@ -20,14 +21,8 @@ use Piwik\Config;
  * @package Piwik
  * @subpackage Piwik_Db
  */
-class Schema
+class Schema extends Singleton
 {
-    /**
-     * Singleton instance
-     *
-     * @var \Piwik\Db\Schema
-     */
-    static private $instance = null;
 
     /**
      * Type of database schema
@@ -36,18 +31,6 @@ class Schema
      */
     private $schema = null;
 
-    /**
-     * Returns the singleton Schema
-     *
-     * @return \Piwik\Db\Schema
-     */
-    static public function getInstance()
-    {
-        if (self::$instance === null) {
-            self::$instance = new self;
-        }
-        return self::$instance;
-    }
 
     /**
      * Get schema class name
diff --git a/core/EventDispatcher.php b/core/EventDispatcher.php
index 66cef418ef..c57cea990e 100644
--- a/core/EventDispatcher.php
+++ b/core/EventDispatcher.php
@@ -17,29 +17,13 @@ use Piwik\Plugin;
  * This class allows code to post events from anywhere in Piwik and for
  * plugins to associate callbacks to be executed when events are posted.
  */
-class EventDispatcher
+class EventDispatcher extends Singleton
 {
     // implementation details for postEvent
     const EVENT_CALLBACK_GROUP_FIRST = 0;
     const EVENT_CALLBACK_GROUP_SECOND = 1;
     const EVENT_CALLBACK_GROUP_THIRD = 2;
 
-    /**
-     * Singleton instance.
-     */
-    private static $instance = null;
-
-    /**
-     * Returns the singleton EventDispatcher instance. Creates it if necessary.
-     */
-    public static function getInstance()
-    {
-        if (self::$instance === null) {
-            self::$instance = new EventDispatcher();
-        }
-        return self::$instance;
-    }
-
     /**
      * Array of observers (callbacks attached to events) that are not methods
      * of plugin classes.
diff --git a/core/FrontController.php b/core/FrontController.php
index f93a607ee9..8b42c87a98 100644
--- a/core/FrontController.php
+++ b/core/FrontController.php
@@ -27,7 +27,7 @@ use Piwik\Session;
  * @package Piwik
  * @subpackage FrontController
  */
-class FrontController
+class FrontController extends Singleton
 {
     /**
      * Set to false and the Front Controller will not dispatch the request
@@ -36,8 +36,6 @@ class FrontController
      */
     public static $enableDispatch = true;
 
-    private static $instance = null;
-
     protected function prepareDispatch($module, $action, $parameters)
     {
         if (is_null($module)) {
@@ -91,19 +89,6 @@ class FrontController
         return array($module, $action, $parameters, $controller);
     }
 
-    /**
-     * returns singleton
-     *
-     * @return \Piwik\FrontController
-     */
-    public static function getInstance()
-    {
-        if (self::$instance == null) {
-            self::$instance = new self;
-        }
-        return self::$instance;
-    }
-
     /**
      * Dispatches the request to the right plugin and executes the requested action on the plugin controller.
      *
diff --git a/core/Log.php b/core/Log.php
index 026f63c839..23017acd59 100644
--- a/core/Log.php
+++ b/core/Log.php
@@ -26,7 +26,7 @@ use Piwik\Db;
  * The logging utility can be configured by manipulating the INI config options in the
  * [log] section.
  */
-class Log
+class Log extends Singleton
 {
     // log levels
     const NONE = 0;
@@ -50,35 +50,6 @@ class Log
 
     const GET_AVAILABLE_WRITERS_EVENT = 'Log.getAvailableWriters';
 
-    /**
-     * The singleton Log instance.
-     *
-     * @var Log
-     */
-    private static $instance = null;
-
-    /**
-     * Returns the singleton Log instance or creates it if it doesn't exist.
-     *
-     * @return Log
-     */
-    public static function getInstance()
-    {
-        if (self::$instance === null) {
-            self::$instance = new Log();
-        }
-        return self::$instance;
-    }
-
-    /**
-     * Unsets the singleton instance so it will be re-created the next time getInstance() is
-     * called. For testing purposes only.
-     */
-    public static function clearInstance()
-    {
-        self::$instance = null;
-    }
-
     /**
      * The current logging level. Everything of equal or greater priority will be logged.
      * Everything else will be ignored.
@@ -120,7 +91,7 @@ class Log
     /**
      * Constructor.
      */
-    private function __construct()
+    protected function __construct()
     {
         $logConfig = Config::getInstance()->log;
         $this->setCurrentLogLevelFromConfig($logConfig);
diff --git a/core/Menu/MenuAbstract.php b/core/Menu/MenuAbstract.php
index edd53161ba..b8f5b11e1a 100644
--- a/core/Menu/MenuAbstract.php
+++ b/core/Menu/MenuAbstract.php
@@ -12,11 +12,12 @@ namespace Piwik\Menu;
 
 use Piwik\Common;
 use Piwik\Plugins\SitesManager\API;
+use Piwik\Singleton;
 
 /**
  * @package Piwik_Menu
  */
-abstract class MenuAbstract
+abstract class MenuAbstract extends Singleton
 {
 
     protected $menu = null;
diff --git a/core/Menu/MenuAdmin.php b/core/Menu/MenuAdmin.php
index 4a29db3e29..eb3576d37e 100644
--- a/core/Menu/MenuAdmin.php
+++ b/core/Menu/MenuAdmin.php
@@ -17,19 +17,6 @@ use Piwik\Piwik;
  */
 class MenuAdmin extends MenuAbstract
 {
-    static private $instance = null;
-
-    /**
-     * @return MenuAdmin
-     */
-    static public function getInstance()
-    {
-        if (self::$instance == null) {
-            self::$instance = new self;
-        }
-        return self::$instance;
-    }
-
     /**
      * Adds a new AdminMenu entry.
      *
diff --git a/core/Menu/MenuMain.php b/core/Menu/MenuMain.php
index 2485f18294..4146559fcd 100644
--- a/core/Menu/MenuMain.php
+++ b/core/Menu/MenuMain.php
@@ -17,19 +17,6 @@ use Piwik\Piwik;
  */
 class MenuMain extends MenuAbstract
 {
-    static private $instance = null;
-
-    /**
-     * @return MenuAbstract
-     */
-    static public function getInstance()
-    {
-        if (self::$instance == null) {
-            self::$instance = new self;
-        }
-        return self::$instance;
-    }
-
     /**
      * Returns if the URL was found in the menu.
      *
diff --git a/core/Menu/MenuTop.php b/core/Menu/MenuTop.php
index 29f056367a..ab2d312799 100644
--- a/core/Menu/MenuTop.php
+++ b/core/Menu/MenuTop.php
@@ -17,20 +17,6 @@ use Piwik\Piwik;
  */
 class MenuTop extends MenuAbstract
 {
-    static private $instance = null;
-
-    /**
-     * @return MenuTop
-     */
-    static public function getInstance()
-    {
-        if (self::$instance == null) {
-            self::$instance = new self;
-        }
-        return self::$instance;
-    }
-
-
     /**
      * Adds a new entry to the TopMenu.
      *
diff --git a/core/Plugin/API.php b/core/Plugin/API.php
new file mode 100644
index 0000000000..e10baf7888
--- /dev/null
+++ b/core/Plugin/API.php
@@ -0,0 +1,18 @@
+<?php
+/**
+ * Piwik - Open source web analytics
+ *
+ * @link http://piwik.org
+ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
+ *
+ * @category Piwik
+ * @package Piwik_PluginArchiver
+ */
+
+namespace Piwik\Plugin;
+
+use Piwik\Singleton;
+
+abstract class API extends Singleton
+{
+}
diff --git a/core/Plugin/Controller.php b/core/Plugin/Controller.php
index f54c068d0d..99d5a9668d 100644
--- a/core/Plugin/Controller.php
+++ b/core/Plugin/Controller.php
@@ -24,7 +24,6 @@ use Piwik\Period\Month;
 use Piwik\Period;
 use Piwik\Period\Range;
 use Piwik\Piwik;
-use Piwik\Plugins\API\API;
 use Piwik\Plugins\LanguagesManager\LanguagesManager;
 use Piwik\Plugins\SitesManager\API as APISitesManager;
 use Piwik\Plugins\UsersManager\API as APIUsersManager;
@@ -207,7 +206,7 @@ abstract class Controller
         $idSite = Common::getRequestVar('idSite');
         $period = Common::getRequestVar('period');
         $date = Common::getRequestVar('date');
-        $meta = API::getInstance()->getReportMetadata($idSite, $period, $date);
+        $meta = \Piwik\Plugins\API\API::getInstance()->getReportMetadata($idSite, $period, $date);
 
         $columns = array_merge($columnsToDisplay, $selectableColumns);
         $translations = array_combine($columns, $columns);
@@ -452,10 +451,10 @@ abstract class Controller
         $view->isSuperUser = Access::getInstance()->isSuperUser();
         $view->hasSomeAdminAccess = Piwik::isUserHasSomeAdminAccess();
         $view->isCustomLogo = Config::getInstance()->branding['use_custom_logo'];
-        $view->logoHeader = API::getInstance()->getHeaderLogoUrl();
-        $view->logoLarge = API::getInstance()->getLogoUrl();
-        $view->logoSVG = API::getInstance()->getSVGLogoUrl();
-        $view->hasSVGLogo = API::getInstance()->hasSVGLogo();
+        $view->logoHeader = \Piwik\Plugins\API\API::getInstance()->getHeaderLogoUrl();
+        $view->logoLarge = \Piwik\Plugins\API\API::getInstance()->getLogoUrl();
+        $view->logoSVG = \Piwik\Plugins\API\API::getInstance()->getSVGLogoUrl();
+        $view->hasSVGLogo = \Piwik\Plugins\API\API::getInstance()->hasSVGLogo();
 
         $view->enableFrames = Config::getInstance()->General['enable_framed_pages']
             || @Config::getInstance()->General['enable_framed_logins'];
diff --git a/core/Plugin/Manager.php b/core/Plugin/Manager.php
index d7add95fdb..7dbb4f86c4 100644
--- a/core/Plugin/Manager.php
+++ b/core/Plugin/Manager.php
@@ -16,6 +16,7 @@ use Piwik\EventDispatcher;
 use Piwik\Filesystem;
 use Piwik\Option;
 use Piwik\Plugin;
+use Piwik\Singleton;
 use Piwik\Translate;
 use Piwik\Updater;
 
@@ -27,7 +28,7 @@ require_once PIWIK_INCLUDE_PATH . '/core/EventDispatcher.php';
  * @package Piwik
  * @subpackage Manager
  */
-class Manager
+class Manager extends Singleton
 {
     protected $pluginsToLoad = array();
 
@@ -69,21 +70,6 @@ class Manager
     // If a plugin hooks onto at least an event starting with "Tracker.", we load the plugin during tracker
     const TRACKER_EVENT_PREFIX = 'Tracker.';
 
-    static private $instance = null;
-
-    /**
-     * Returns the singleton Manager
-     *
-     * @return Manager
-     */
-    static public function getInstance()
-    {
-        if (self::$instance == null) {
-            self::$instance = new self;
-        }
-        return self::$instance;
-    }
-
     /**
      * Update Plugins config
      *
diff --git a/core/Registry.php b/core/Registry.php
index 5fe90370b9..88ecc1ce95 100644
--- a/core/Registry.php
+++ b/core/Registry.php
@@ -15,24 +15,15 @@ namespace Piwik;
  *
  * @package Piwik
  */
-class Registry
+class Registry extends Singleton
 {
-    private static $instance;
     private $data;
 
-    private function __construct()
+    protected function __construct()
     {
         $this->data = array();
     }
 
-    public static function getInstance()
-    {
-        if (self::$instance == null) {
-            self::$instance = new Registry();
-        }
-        return self::$instance;
-    }
-
     public static function isRegistered($key)
     {
         return self::getInstance()->hasKey($key);
@@ -48,11 +39,6 @@ class Registry
         self::getInstance()->setKey($key, $value);
     }
 
-    public static function unsetInstance()
-    {
-        self::$instance = null;
-    }
-
     public function setKey($key, $value)
     {
         $this->data[$key] = $value;
diff --git a/core/Singleton.php b/core/Singleton.php
new file mode 100644
index 0000000000..7e7679c67a
--- /dev/null
+++ b/core/Singleton.php
@@ -0,0 +1,37 @@
+<?php
+/**
+ * Piwik - Open source web analytics
+ *
+ * @link http://piwik.org
+ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
+ *
+ * @category Piwik
+ * @package Piwik
+ */
+
+namespace Piwik;
+
+class Singleton
+{
+
+    protected static $instances;
+
+    protected function __construct() { }
+
+    final private function __clone() { }
+
+    public static function getInstance() {
+        $class = get_called_class();
+
+        if (!isset(self::$instances[$class])) {
+            self::$instances[$class] = new $class;
+        }
+        return self::$instances[$class];
+    }
+
+    public static function unsetInstance()
+    {
+        $class = get_called_class();
+        unset(self::$instances[$class]);
+    }
+}
diff --git a/piwik.php b/piwik.php
index 018fb2fa6e..fa98df9076 100644
--- a/piwik.php
+++ b/piwik.php
@@ -36,6 +36,7 @@ if (!defined('PIWIK_INCLUDE_PATH')) {
 @ignore_user_abort(true);
 
 require_once PIWIK_INCLUDE_PATH . '/libs/upgradephp/upgrade.php';
+require_once PIWIK_INCLUDE_PATH . '/core/Singleton.php';
 require_once PIWIK_INCLUDE_PATH . '/core/Plugin/Manager.php';
 require_once PIWIK_INCLUDE_PATH . '/core/Plugin.php';
 require_once PIWIK_INCLUDE_PATH . '/core/Common.php';
diff --git a/plugins/API/API.php b/plugins/API/API.php
index 0673e55a2d..5bd4a6c898 100644
--- a/plugins/API/API.php
+++ b/plugins/API/API.php
@@ -46,21 +46,8 @@ require_once PIWIK_INCLUDE_PATH . '/core/Config.php';
  *
  * @package Piwik_API
  */
-class API
+class API extends \Piwik\Plugin\API
 {
-    static private $instance = null;
-
-    /**
-     * @return \Piwik\Plugins\API\API
-     */
-    static public function getInstance()
-    {
-        if (self::$instance == null) {
-            self::$instance = new self;
-        }
-        return self::$instance;
-    }
-
     /**
      * Get Piwik version
      * @return string
diff --git a/plugins/Actions/API.php b/plugins/Actions/API.php
index e9c9d4c810..84ceca80ac 100644
--- a/plugins/Actions/API.php
+++ b/plugins/Actions/API.php
@@ -36,21 +36,8 @@ use Piwik\Tracker\Action;
  * Note: pageName, pageUrl, outlinkUrl, downloadUrl parameters must be URL encoded before you call the API.
  * @package Actions
  */
-class API
+class API extends \Piwik\Plugin\API
 {
-    static private $instance = null;
-
-    /**
-     * @return \Piwik\Plugins\Actions\API
-     */
-    static public function getInstance()
-    {
-        if (self::$instance == null) {
-            self::$instance = new self;
-        }
-        return self::$instance;
-    }
-
     /**
      * Returns the list of metrics (pages, downloads, outlinks)
      *
diff --git a/plugins/Annotations/API.php b/plugins/Annotations/API.php
index b18a2264f9..7863d0ff5c 100755
--- a/plugins/Annotations/API.php
+++ b/plugins/Annotations/API.php
@@ -30,23 +30,8 @@ require_once PIWIK_INCLUDE_PATH . '/plugins/Annotations/AnnotationList.php';
  *
  * @package Annotations
  */
-class API
+class API extends \Piwik\Plugin\API
 {
-    static private $instance = null;
-
-    /**
-     * Returns this API's singleton instance.
-     *
-     * @return \Piwik\Plugins\Annotations\API
-     */
-    static public function getInstance()
-    {
-        if (self::$instance == null) {
-            self::$instance = new self;
-        }
-        return self::$instance;
-    }
-
     /**
      * Create a new annotation for a site.
      *
diff --git a/plugins/CoreAdminHome/API.php b/plugins/CoreAdminHome/API.php
index 909a178738..ab3ff062a8 100644
--- a/plugins/CoreAdminHome/API.php
+++ b/plugins/CoreAdminHome/API.php
@@ -27,21 +27,8 @@ use Piwik\TaskScheduler;
 /**
  * @package CoreAdminHome
  */
-class API
+class API extends \Piwik\Plugin\API
 {
-    static private $instance = null;
-
-    /**
-     * @return \Piwik\Plugins\CoreAdminHome\API
-     */
-    static public function getInstance()
-    {
-        if (self::$instance == null) {
-            self::$instance = new self;
-        }
-        return self::$instance;
-    }
-
     /**
      * Will run all scheduled tasks due to run at this time.
      *
diff --git a/plugins/CoreConsole/templates/api/API.php b/plugins/CoreConsole/templates/api/API.php
index 74e8abb13a..bc3da69fb2 100644
--- a/plugins/CoreConsole/templates/api/API.php
+++ b/plugins/CoreConsole/templates/api/API.php
@@ -15,22 +15,8 @@ namespace Piwik\Plugins\PLUGINNAME;
  *
  * @package Piwik_PLUGINNAME
  */
-class API
+class API extends \Piwik\Plugin\API
 {
-    static private $instance = null;
-
-    /**
-     * @return \Piwik\Plugins\PLUGINNAME\API
-     */
-    static public function getInstance()
-    {
-        if (self::$instance == null) {
-            self::$instance = new self;
-        }
-
-        return self::$instance;
-    }
-
     /**
      * Example method. Please remove if you do not need this API method.
      * You can call this API method like this:
diff --git a/plugins/CustomVariables/API.php b/plugins/CustomVariables/API.php
index 8c87124099..522a05cf81 100644
--- a/plugins/CustomVariables/API.php
+++ b/plugins/CustomVariables/API.php
@@ -22,21 +22,8 @@ use Piwik\Tracker\Action;
  *
  * @package CustomVariables
  */
-class API
+class API extends \Piwik\Plugin\API
 {
-    static private $instance = null;
-
-    /**
-     * @return \Piwik\Plugins\CustomVariables\API
-     */
-    static public function getInstance()
-    {
-        if (self::$instance == null) {
-            self::$instance = new self;
-        }
-        return self::$instance;
-    }
-
     /**
      * @param int $idSite
      * @param string $period
diff --git a/plugins/DBStats/API.php b/plugins/DBStats/API.php
index 1e3224cf2f..af71b4cf42 100644
--- a/plugins/DBStats/API.php
+++ b/plugins/DBStats/API.php
@@ -24,22 +24,8 @@ require_once PIWIK_INCLUDE_PATH . '/plugins/DBStats/MySQLMetadataProvider.php';
  *
  * @package DBStats
  */
-class API
+class API extends \Piwik\Plugin\API
 {
-    /** Singleton instance of this class. */
-    static private $instance = null;
-
-    /**
-     * Gets or creates the DBStats API singleton.
-     */
-    static public function getInstance()
-    {
-        if (self::$instance == null) {
-            self::$instance = new self;
-        }
-        return self::$instance;
-    }
-
     /**
      * The MySQLMetadataProvider instance that fetches table/db status information.
      */
@@ -48,7 +34,7 @@ class API
     /**
      * Constructor.
      */
-    public function __construct()
+    protected function __construct()
     {
         $this->metadataProvider = new MySQLMetadataProvider();
     }
diff --git a/plugins/Dashboard/API.php b/plugins/Dashboard/API.php
index a6acf6c26a..1841775211 100644
--- a/plugins/Dashboard/API.php
+++ b/plugins/Dashboard/API.php
@@ -17,32 +17,15 @@ use Piwik\WidgetsList;
  *
  * @package Piwik_API
  */
-class API
+class API extends \Piwik\Plugin\API
 {
-    /**
-     * @var \Piwik\Plugins\Dashboard\API
-     */
-    static private $instance = null;
-
     private $dashboard = null;
 
-    public function __construct()
+    protected function __construct()
     {
         $this->dashboard = new Dashboard();
     }
 
-    /**
-     * @return \Piwik\Plugins\Dashboard\API
-     */
-    static public function getInstance()
-    {
-        if (null == self::$instance) {
-            self::$instance = new self;
-        }
-
-        return self::$instance;
-    }
-
     /**
      * Get each dashboard that belongs to a user including the containing widgets that are placed within each dashboard.
      * If the user has not created any dashboard yet, the default dashboard will be returned.
diff --git a/plugins/DevicesDetection/API.php b/plugins/DevicesDetection/API.php
index f899b0ce78..0c466ef0b6 100644
--- a/plugins/DevicesDetection/API.php
+++ b/plugins/DevicesDetection/API.php
@@ -19,23 +19,8 @@ use Piwik\Piwik;
 /**
  * The DevicesDetection API lets you access reports on your visitors devices, brands, models, Operating system, Browsers.
  */
-class API
+class API extends \Piwik\Plugin\API
 {
-
-    static private $instance = null;
-
-    /**
-     *
-     * @return \Piwik\Plugins\DevicesDetection\API
-     */
-    static public function getInstance()
-    {
-        if (self::$instance == null) {
-            self::$instance = new self;
-        }
-        return self::$instance;
-    }
-
     /**
      * @param string $name
      * @param int $idSite
diff --git a/plugins/ExampleAPI/API.php b/plugins/ExampleAPI/API.php
index a6c012a644..5d9809334b 100644
--- a/plugins/ExampleAPI/API.php
+++ b/plugins/ExampleAPI/API.php
@@ -21,42 +21,8 @@ use Piwik\Version;
  * Please see the <a href='http://dev.piwik.org/trac/browser/trunk/plugins/ExampleAPI/API.php#L1' target='_blank'>source code in in the file plugins/ExampleAPI/API.php</a> for more documentation.
  * @package Piwik_ExampleAPI
  */
-class API
+class API extends \Piwik\Plugin\API
 {
-    /**
-     *  * This is an example of a basic API file. Each plugin can have one public API.
-     * Each public function in this class will be available to be called via the API.
-     * Protected and private members will not be callable.
-     * Functions can be called internally using the PHP objects directly, or via the
-     * Piwik Web APIs, using HTTP requests. For more information, check out:
-     * http://piwik.org/docs/analytics-api/calling-techniques
-     *
-     * Parameters are passed automatically from the GET request to the API functions.
-     *
-     * Common API uses include:
-     * - requesting stats for a given date and period, for one or several websites
-     * - creating, editing, deleting entities (Goals, Websites, Users)
-     * - any logic that could be useful to a larger scope than the Controller (make a setting editable for example)
-     *
-     * It is highly recommended that all the plugin logic is done inside API implementations, and the
-     * Controller and other objects would all call the API internally using, eg.
-     *  API::getInstance()->getSum(1, 2);
-     *
-     */
-    static private $instance = null;
-
-    /**
-     * Singleton
-     * @return \Piwik\Plugins\ExampleAPI\API
-     */
-    static public function getInstance()
-    {
-        if (self::$instance == null) {
-            self::$instance = new self;
-        }
-        return self::$instance;
-    }
-
     /**
      * Get Piwik version
      * @return string
diff --git a/plugins/ExampleUI/API.php b/plugins/ExampleUI/API.php
index 5827acac67..681e2afb4b 100644
--- a/plugins/ExampleUI/API.php
+++ b/plugins/ExampleUI/API.php
@@ -21,24 +21,10 @@ use Piwik\Period\Range;
  *
  * @package ExampleUI
  */
-class API
+class API extends \Piwik\Plugin\API
 {
     public static $disableRandomness = false;
 
-    private static $instance = null;
-
-    /**
-     * @return \Piwik\Plugins\ExampleUI\API
-     */
-    public static function getInstance()
-    {
-        if (self::$instance == null) {
-            self::$instance = new self;
-        }
-
-        return self::$instance;
-    }
-
     public function getTemperaturesEvolution($date, $period)
     {
         $temperatures = array();
diff --git a/plugins/Goals/API.php b/plugins/Goals/API.php
index d61af04626..34b3083f88 100644
--- a/plugins/Goals/API.php
+++ b/plugins/Goals/API.php
@@ -41,21 +41,8 @@ use Piwik\Tracker\GoalManager;
  *
  * @package Goals
  */
-class API
+class API extends \Piwik\Plugin\API
 {
-    static private $instance = null;
-
-    /**
-     * @return \Piwik\Plugins\Goals\API
-     */
-    static public function getInstance()
-    {
-        if (self::$instance == null) {
-            self::$instance = new self;
-        }
-        return self::$instance;
-    }
-
     /**
      * Returns all Goals for a given website, or list of websites
      *
diff --git a/plugins/ImageGraph/API.php b/plugins/ImageGraph/API.php
index 48a28f1f7b..ce0b600f6b 100644
--- a/plugins/ImageGraph/API.php
+++ b/plugins/ImageGraph/API.php
@@ -33,7 +33,7 @@ use Piwik\Translate;
  *
  * @package ImageGraph
  */
-class API
+class API extends \Piwik\Plugin\API
 {
     const FILENAME_KEY = 'filename';
     const TRUNCATE_KEY = 'truncate';
@@ -104,20 +104,6 @@ class API
     const DEFAULT_NB_ROW_EVOLUTIONS = 5;
     const MAX_NB_ROW_LABELS = 10;
 
-    static private $instance = null;
-
-    /**
-     * @return \Piwik\Plugins\ImageGraph\API
-     */
-    static public function getInstance()
-    {
-        if (self::$instance == null) {
-            $c = __CLASS__;
-            self::$instance = new $c();
-        }
-        return self::$instance;
-    }
-
     public function get(
         $idSite,
         $period,
diff --git a/plugins/LanguagesManager/API.php b/plugins/LanguagesManager/API.php
index 64a58ccdf2..6309ff5a39 100644
--- a/plugins/LanguagesManager/API.php
+++ b/plugins/LanguagesManager/API.php
@@ -28,21 +28,8 @@ use Piwik\Piwik;
  *
  * @package LanguagesManager
  */
-class API
+class API extends \Piwik\Plugin\API
 {
-    static private $instance = null;
-
-    /**
-     * @return \Piwik\Plugins\LanguagesManager\API
-     */
-    static public function getInstance()
-    {
-        if (self::$instance == null) {
-            self::$instance = new self;
-        }
-        return self::$instance;
-    }
-
     protected $availableLanguageNames = null;
     protected $languageNames = null;
 
diff --git a/plugins/Live/API.php b/plugins/Live/API.php
index 04083c86ba..56f6338192 100644
--- a/plugins/Live/API.php
+++ b/plugins/Live/API.php
@@ -57,25 +57,12 @@ require_once PIWIK_INCLUDE_PATH . '/plugins/Live/Visitor.php';
  * See also the documentation about <a href='http://piwik.org/docs/real-time/' target='_blank'>Real time widget and visitor level reports</a> in Piwik.
  * @package Live
  */
-class API
+class API extends \Piwik\Plugin\API
 {
     const VISITOR_PROFILE_MAX_VISITS_TO_AGGREGATE = 100;
     const VISITOR_PROFILE_MAX_VISITS_TO_SHOW = 10;
     const VISITOR_PROFILE_DATE_FORMAT = '%day% %shortMonth% %longYear%';
 
-    static private $instance = null;
-
-    /**
-     * @return \Piwik\Plugins\Live\API
-     */
-    static public function getInstance()
-    {
-        if (self::$instance == null) {
-            self::$instance = new self;
-        }
-        return self::$instance;
-    }
-
     /**
      * This will return simple counters, for a given website ID, for visits over the last N minutes
      *
diff --git a/plugins/MobileMessaging/API.php b/plugins/MobileMessaging/API.php
index 3c369785a8..0aa7e3b924 100644
--- a/plugins/MobileMessaging/API.php
+++ b/plugins/MobileMessaging/API.php
@@ -24,24 +24,11 @@ use Piwik\Plugins\ScheduledReports\API as APIScheduledReports;
  *  - send SMS
  * @package MobileMessaging
  */
-class API
+class API extends \Piwik\Plugin\API
 {
     const VERIFICATION_CODE_LENGTH = 5;
     const SMS_FROM = 'Piwik';
 
-    static private $instance = null;
-
-    /**
-     * @return \Piwik\Plugins\MobileMessaging\API
-     */
-    static public function getInstance()
-    {
-        if (self::$instance == null) {
-            self::$instance = new self;
-        }
-        return self::$instance;
-    }
-
     /**
      * @param string $provider
      * @return SMSProvider
diff --git a/plugins/MultiSites/API.php b/plugins/MultiSites/API.php
index d92af8e82c..763a1e28d3 100755
--- a/plugins/MultiSites/API.php
+++ b/plugins/MultiSites/API.php
@@ -26,7 +26,7 @@ use Piwik\TaskScheduler;
 /**
  * The MultiSites API lets you request the key metrics (visits, page views, revenue) for all Websites in Piwik.
  */
-class API
+class API extends \Piwik\Plugin\API
 {
     const METRIC_TRANSLATION_KEY = 'translation';
     const METRIC_EVOLUTION_COL_NAME_KEY = 'evolution_column_name';
@@ -63,26 +63,6 @@ class API
         )
     );
 
-    /**
-     * The singleton instance of this class.
-     */
-    static private $instance = null;
-
-    /**
-     * Returns the singleton instance of this class. The instance is created
-     * if it hasn't been already.
-     *
-     * @return \Piwik\Plugins\MultiSites\API
-     */
-    static public function getInstance()
-    {
-        if (self::$instance == null) {
-            self::$instance = new self;
-        }
-
-        return self::$instance;
-    }
-
     /**
      * Returns a report displaying the total visits, actions and revenue, as
      * well as the evolution of these values, of all existing sites over a
diff --git a/plugins/Overlay/API.php b/plugins/Overlay/API.php
index 0c736932f1..334cd712b3 100644
--- a/plugins/Overlay/API.php
+++ b/plugins/Overlay/API.php
@@ -20,23 +20,8 @@ use Piwik\Plugins\SitesManager\SitesManager;
 use Piwik\Plugins\Transitions\API as APITransitions;
 use Piwik\Tracker\Action;
 
-class API
+class API extends \Piwik\Plugin\API
 {
-
-    private static $instance = null;
-
-    /**
-     * Get Singleton instance
-     * @return \Piwik\Plugins\Overlay\API
-     */
-    public static function getInstance()
-    {
-        if (self::$instance == null) {
-            self::$instance = new self;
-        }
-        return self::$instance;
-    }
-
     /**
      * Get translation strings
      */
diff --git a/plugins/Provider/API.php b/plugins/Provider/API.php
index 106fbd5883..ae53d0f2f8 100644
--- a/plugins/Provider/API.php
+++ b/plugins/Provider/API.php
@@ -24,18 +24,8 @@ require_once PIWIK_INCLUDE_PATH . '/plugins/Provider/functions.php';
  *
  * @package Provider
  */
-class API
+class API extends \Piwik\Plugin\API
 {
-    static private $instance = null;
-
-    static public function getInstance()
-    {
-        if (self::$instance == null) {
-            self::$instance = new self;
-        }
-        return self::$instance;
-    }
-
     public function getProvider($idSite, $period, $date, $segment = false)
     {
         Piwik::checkUserHasViewAccess($idSite);
diff --git a/plugins/Referrers/API.php b/plugins/Referrers/API.php
index 1599546b4f..15d4785771 100644
--- a/plugins/Referrers/API.php
+++ b/plugins/Referrers/API.php
@@ -30,18 +30,8 @@ use Piwik\Piwik;
  * Check out the widget <a href='http://demo.piwik.org/index.php?module=Widgetize&action=iframe&moduleToWidgetize=Referrers&actionToWidgetize=getKeywordsForPage&idSite=7&period=day&date=2011-02-15&disableLink=1' target='_blank'>"Top keywords used to find this page"</a> that you can easily re-use on your website.
  * @package Referrers
  */
-class API
+class API extends \Piwik\Plugin\API
 {
-    static private $instance = null;
-
-    static public function getInstance()
-    {
-        if (self::$instance == null) {
-            self::$instance = new self;
-        }
-        return self::$instance;
-    }
-
     /**
      * @param string $name
      * @param int $idSite
diff --git a/plugins/SEO/API.php b/plugins/SEO/API.php
index f23875812a..4111c6d5f7 100644
--- a/plugins/SEO/API.php
+++ b/plugins/SEO/API.php
@@ -24,21 +24,8 @@ require_once PIWIK_INCLUDE_PATH . '/plugins/Referrers/functions.php';
  *
  * @package SEO
  */
-class API
+class API extends \Piwik\Plugin\API
 {
-    static private $instance = null;
-
-    /**
-     * @return \Piwik\Plugins\SEO\API
-     */
-    static public function getInstance()
-    {
-        if (self::$instance == null) {
-            self::$instance = new self;
-        }
-        return self::$instance;
-    }
-
     /**
      * Returns SEO statistics for a URL.
      *
diff --git a/plugins/ScheduledReports/API.php b/plugins/ScheduledReports/API.php
index 4feb8dfcb5..4980870aa9 100644
--- a/plugins/ScheduledReports/API.php
+++ b/plugins/ScheduledReports/API.php
@@ -35,7 +35,7 @@ use Zend_Mime;
  *
  * @package ScheduledReports
  */
-class API
+class API extends \Piwik\Plugin\API
 {
     const VALIDATE_PARAMETERS_EVENT = 'ScheduledReports.validateReportParameters';
     const GET_REPORT_PARAMETERS_EVENT = 'ScheduledReports.getReportParameters';
@@ -66,19 +66,6 @@ class API
 
     const REPORT_TRUNCATE = 23;
 
-    static private $instance = null;
-
-    /**
-     * @return \Piwik\Plugins\ScheduledReports\API
-     */
-    static public function getInstance()
-    {
-        if (self::$instance == null) {
-            self::$instance = new self;
-        }
-        return self::$instance;
-    }
-
     /**
      * Creates a new report and schedules it.
      *
diff --git a/plugins/SegmentEditor/API.php b/plugins/SegmentEditor/API.php
index 62fd909bc1..85a69f0710 100644
--- a/plugins/SegmentEditor/API.php
+++ b/plugins/SegmentEditor/API.php
@@ -22,23 +22,10 @@ use Piwik\Segment;
  *
  * @package SegmentEditor
  */
-class API
+class API extends \Piwik\Plugin\API
 {
     const DEACTIVATE_SEGMENT_EVENT = 'SegmentEditor.deactivate';
 
-    static private $instance = null;
-
-    /**
-     * @return \Piwik\Plugins\SegmentEditor\API
-     */
-    static public function getInstance()
-    {
-        if (self::$instance == null) {
-            self::$instance = new self;
-        }
-        return self::$instance;
-    }
-
     protected function checkSegmentValue($definition, $idSite)
     {
         // unsanitize so we don't record the HTML entitied segment
diff --git a/plugins/SitesManager/API.php b/plugins/SitesManager/API.php
index c78e0a9d2c..e1b367d9c3 100644
--- a/plugins/SitesManager/API.php
+++ b/plugins/SitesManager/API.php
@@ -43,22 +43,9 @@ use Piwik\UrlHelper;
  * See also the documentation about <a href='http://piwik.org/docs/manage-websites/' target='_blank'>Managing Websites</a> in Piwik.
  * @package SitesManager
  */
-class API
+class API extends \Piwik\Plugin\API
 {
-    static private $instance = null;
     const DEFAULT_SEARCH_KEYWORD_PARAMETERS = 'q,query,s,search,searchword,k,keyword';
-
-    /**
-     * @return \Piwik\Plugins\SitesManager\API
-     */
-    static public function getInstance()
-    {
-        if (self::$instance == null) {
-            self::$instance = new self;
-        }
-        return self::$instance;
-    }
-
     const OPTION_EXCLUDED_IPS_GLOBAL = 'SitesManager_ExcludedIpsGlobal';
     const OPTION_DEFAULT_TIMEZONE = 'SitesManager_DefaultTimezone';
     const OPTION_DEFAULT_CURRENCY = 'SitesManager_DefaultCurrency';
diff --git a/plugins/Transitions/API.php b/plugins/Transitions/API.php
index e6fe825617..f48ca9d9a7 100644
--- a/plugins/Transitions/API.php
+++ b/plugins/Transitions/API.php
@@ -34,19 +34,8 @@ use Piwik\Tracker\Action;
 /**
  * @package Transitions
  */
-class API
+class API extends \Piwik\Plugin\API
 {
-
-    static private $instance = null;
-
-    static public function getInstance()
-    {
-        if (self::$instance == null) {
-            self::$instance = new self;
-        }
-        return self::$instance;
-    }
-
     public function getTransitionsForPageTitle($pageTitle, $idSite, $period, $date, $segment = false, $limitBeforeGrouping = false)
     {
         return $this->getTransitionsForAction($pageTitle, 'title', $idSite, $period, $date, $segment, $limitBeforeGrouping);
diff --git a/plugins/UserCountry/API.php b/plugins/UserCountry/API.php
index 85ff3973c4..79ac0cb6ec 100644
--- a/plugins/UserCountry/API.php
+++ b/plugins/UserCountry/API.php
@@ -28,18 +28,8 @@ require_once PIWIK_INCLUDE_PATH . '/plugins/UserCountry/functions.php';
  * The UserCountry API lets you access reports about your visitors' Countries and Continents.
  * @package UserCountry
  */
-class API
+class API extends \Piwik\Plugin\API
 {
-    static private $instance = null;
-
-    static public function getInstance()
-    {
-        if (self::$instance == null) {
-            self::$instance = new self;
-        }
-        return self::$instance;
-    }
-
     public function getCountry($idSite, $period, $date, $segment = false)
     {
         $dataTable = $this->getDataTable(Archiver::COUNTRY_RECORD_NAME, $idSite, $period, $date, $segment);
diff --git a/plugins/UserSettings/API.php b/plugins/UserSettings/API.php
index 1fc12059c1..90dd4752c7 100644
--- a/plugins/UserSettings/API.php
+++ b/plugins/UserSettings/API.php
@@ -26,18 +26,8 @@ require_once PIWIK_INCLUDE_PATH . '/plugins/UserSettings/functions.php';
  *
  * @package UserSettings
  */
-class API
+class API extends \Piwik\Plugin\API
 {
-    static private $instance = null;
-
-    static public function getInstance()
-    {
-        if (self::$instance == null) {
-            self::$instance = new self;
-        }
-        return self::$instance;
-    }
-
     protected function getDataTable($name, $idSite, $period, $date, $segment)
     {
         Piwik::checkUserHasViewAccess($idSite);
diff --git a/plugins/UsersManager/API.php b/plugins/UsersManager/API.php
index 34bca9c465..c71995b728 100644
--- a/plugins/UsersManager/API.php
+++ b/plugins/UsersManager/API.php
@@ -34,7 +34,7 @@ use Piwik\Tracker\Cache;
  * See also the documentation about <a href='http://piwik.org/docs/manage-users/' target='_blank'>Managing Users</a> in Piwik.
  * @package UsersManager
  */
-class API
+class API extends \Piwik\Plugin\API
 {
     const PREFERENCE_DEFAULT_REPORT = 'defaultReport';
     const PREFERENCE_DEFAULT_REPORT_DATE = 'defaultReportDate';
diff --git a/plugins/VisitFrequency/API.php b/plugins/VisitFrequency/API.php
index 18142916d7..fa4007f309 100644
--- a/plugins/VisitFrequency/API.php
+++ b/plugins/VisitFrequency/API.php
@@ -19,21 +19,11 @@ use Piwik\SegmentExpression;
  * VisitFrequency API lets you access a list of metrics related to Returning Visitors.
  * @package VisitFrequency
  */
-class API
+class API extends \Piwik\Plugin\API
 {
     const RETURNING_VISITOR_SEGMENT = "visitorType==returning";
     const COLUMN_SUFFIX = "_returning";
 
-    static private $instance = null;
-
-    static public function getInstance()
-    {
-        if (self::$instance == null) {
-            self::$instance = new self;
-        }
-        return self::$instance;
-    }
-
     /**
      * @param int $idSite
      * @param string $period
diff --git a/plugins/VisitTime/API.php b/plugins/VisitTime/API.php
index f87708e4ef..fe5c70bd05 100644
--- a/plugins/VisitTime/API.php
+++ b/plugins/VisitTime/API.php
@@ -26,18 +26,8 @@ require_once PIWIK_INCLUDE_PATH . '/plugins/VisitTime/functions.php';
  *
  * @package VisitTime
  */
-class API
+class API extends \Piwik\Plugin\API
 {
-    static private $instance = null;
-
-    static public function getInstance()
-    {
-        if (self::$instance == null) {
-            self::$instance = new self;
-        }
-        return self::$instance;
-    }
-
     protected function getDataTable($name, $idSite, $period, $date, $segment)
     {
         Piwik::checkUserHasViewAccess($idSite);
diff --git a/plugins/VisitorInterest/API.php b/plugins/VisitorInterest/API.php
index 1cb1fc3a1e..68b6c44715 100644
--- a/plugins/VisitorInterest/API.php
+++ b/plugins/VisitorInterest/API.php
@@ -21,18 +21,8 @@ use Piwik\Piwik;
  *
  * @package VisitorInterest
  */
-class API
+class API extends \Piwik\Plugin\API
 {
-    static private $instance = null;
-
-    static public function getInstance()
-    {
-        if (self::$instance == null) {
-            self::$instance = new self;
-        }
-        return self::$instance;
-    }
-
     protected function getDataTable($name, $idSite, $period, $date, $segment, $column = Metrics::INDEX_NB_VISITS)
     {
         Piwik::checkUserHasViewAccess($idSite);
diff --git a/plugins/VisitsSummary/API.php b/plugins/VisitsSummary/API.php
index 3578d8f411..c0f32f39f1 100644
--- a/plugins/VisitsSummary/API.php
+++ b/plugins/VisitsSummary/API.php
@@ -21,21 +21,8 @@ use Piwik\SettingsPiwik;
  *
  * @package VisitsSummary
  */
-class API
+class API extends \Piwik\Plugin\API
 {
-    static private $instance = null;
-
-    /**
-     * @return \Piwik\Plugins\VisitsSummary\API
-     */
-    static public function getInstance()
-    {
-        if (self::$instance == null) {
-            self::$instance = new self;
-        }
-        return self::$instance;
-    }
-
     public function get($idSite, $period, $date, $segment = false, $columns = false)
     {
         Piwik::checkUserHasViewAccess($idSite);
diff --git a/tests/PHPUnit/Core/LogTest.php b/tests/PHPUnit/Core/LogTest.php
index 706c8f16a6..ead7b7488d 100644
--- a/tests/PHPUnit/Core/LogTest.php
+++ b/tests/PHPUnit/Core/LogTest.php
@@ -67,7 +67,7 @@ dummy backtrace'
         Config::getInstance()->log['string_message_format'] = self::STRING_MESSAGE_FORMAT;
         Config::getInstance()->log['logger_file_path'] = self::getDefaultLogFileLocation();
         @unlink(self::getLogFileLocation());
-        Log::clearInstance();
+        Log::unsetInstance();
         Error::$debugBacktraceForTests = ExceptionHandler::$debugBacktraceForTests = "dummy backtrace";
     }
 
@@ -75,7 +75,7 @@ dummy backtrace'
     {
         parent::tearDown();
 
-        Log::clearInstance();
+        Log::unsetInstance();
         @unlink(self::getLogFileLocation());
         Error::$debugBacktraceForTests = ExceptionHandler::$debugBacktraceForTests = null;
     }
-- 
GitLab