diff options
author | diosmosis <benakamoorthi@fastmail.fm> | 2014-08-20 12:13:04 +0400 |
---|---|---|
committer | diosmosis <benakamoorthi@fastmail.fm> | 2014-08-20 12:21:07 +0400 |
commit | 34904e642034d10b728b429dcb213344a0157e74 (patch) | |
tree | ec2b732fe86e4720c328b13bc75e3d54949edc7c /plugins/ImageGraph | |
parent | ca0bdf191bf1ab85525169242cbfef754855dfec (diff) |
Refactor factory methods into base Factory type for ease of testing.
Diffstat (limited to 'plugins/ImageGraph')
-rw-r--r-- | plugins/ImageGraph/StaticGraph.php | 34 |
1 files changed, 13 insertions, 21 deletions
diff --git a/plugins/ImageGraph/StaticGraph.php b/plugins/ImageGraph/StaticGraph.php index e98b8bda28..8adef6e411 100644 --- a/plugins/ImageGraph/StaticGraph.php +++ b/plugins/ImageGraph/StaticGraph.php @@ -14,6 +14,7 @@ use pData; use pImage; use Piwik\Piwik; use Piwik\SettingsPiwik; +use Piwik\Factory; require_once PIWIK_INCLUDE_PATH . "/libs/pChart2.1.3/class/pDraw.class.php"; require_once PIWIK_INCLUDE_PATH . "/libs/pChart2.1.3/class/pImage.class.php"; @@ -23,7 +24,7 @@ require_once PIWIK_INCLUDE_PATH . "/libs/pChart2.1.3/class/pData.class.php"; * The StaticGraph abstract class is used as a base class for different types of static graphs. * */ -abstract class StaticGraph +abstract class StaticGraph extends Factory { const GRAPH_TYPE_BASIC_LINE = "evolution"; const GRAPH_TYPE_VERTICAL_BAR = "verticalBar"; @@ -72,28 +73,19 @@ abstract class StaticGraph abstract public function renderGraph(); - /** - * Return the StaticGraph according to the static graph type $graphType - * - * @throws Exception If the static graph type is unknown - * @param string $graphType - * @return \Piwik\Plugins\ImageGraph\StaticGraph - */ - public static function factory($graphType) + protected static function getClassNameFromClassId($graphType) { - if (isset(self::$availableStaticGraphTypes[$graphType])) { + $className = self::$availableStaticGraphTypes[$graphType]; + $className = __NAMESPACE__ . "\\StaticGraph\\" . $className; + return new $className; + } - $className = self::$availableStaticGraphTypes[$graphType]; - $className = __NAMESPACE__ . "\\StaticGraph\\" . $className; - return new $className; - } else { - throw new Exception( - Piwik::translate( - 'General_ExceptionInvalidStaticGraphType', - array($graphType, implode(', ', self::getAvailableStaticGraphTypes())) - ) - ); - } + protected static function getInvalidClassIdExceptionMessage($graphType) + { + return Piwik::translate( + 'General_ExceptionInvalidStaticGraphType', + array($graphType, implode(', ', self::getAvailableStaticGraphTypes())) + ); } public static function getAvailableStaticGraphTypes() |