From d107f8ed3030c416ea3056f34b4ca242ff26af30 Mon Sep 17 00:00:00 2001 From: Jan Tojnar Date: Wed, 6 Jul 2022 12:14:04 +0200 Subject: [PATCH] Improve Factory variable names (#2895) --- actions/ConnectivityAction.php | 6 +++--- actions/DetectAction.php | 8 ++++---- actions/DisplayAction.php | 14 +++++++------- actions/ListAction.php | 8 ++++---- bridges/ElloBridge.php | 4 ++-- bridges/InstagramBridge.php | 4 ++-- bridges/SoundcloudBridge.php | 4 ++-- bridges/SpotifyBridge.php | 4 ++-- bridges/TwitterBridge.php | 10 +++++----- formats/HtmlFormat.php | 6 +++--- index.php | 4 ++-- lib/BridgeAbstract.php | 8 ++++---- lib/BridgeCard.php | 4 ++-- lib/BridgeList.php | 14 +++++++------- lib/contents.php | 4 ++-- lib/error.php | 4 ++-- tests/Actions/ListActionTest.php | 8 ++++---- tests/Formats/BaseFormatTest.php | 4 ++-- 18 files changed, 59 insertions(+), 59 deletions(-) diff --git a/actions/ConnectivityAction.php b/actions/ConnectivityAction.php index c657f21b..dc7f3697 100644 --- a/actions/ConnectivityAction.php +++ b/actions/ConnectivityAction.php @@ -57,9 +57,9 @@ class ConnectivityAction implements ActionInterface */ private function reportBridgeConnectivity($bridgeName) { - $bridgeFac = new \BridgeFactory(); + $bridgeFactory = new \BridgeFactory(); - if (!$bridgeFac->isWhitelisted($bridgeName)) { + if (!$bridgeFactory->isWhitelisted($bridgeName)) { header('Content-Type: text/html'); returnServerError('Bridge is not whitelisted!'); } @@ -72,7 +72,7 @@ class ConnectivityAction implements ActionInterface 'http_code' => 200, ]; - $bridge = $bridgeFac->create($bridgeName); + $bridge = $bridgeFactory->create($bridgeName); if ($bridge === false) { echo json_encode($retVal); diff --git a/actions/DetectAction.php b/actions/DetectAction.php index 149b239d..bc34c0c7 100644 --- a/actions/DetectAction.php +++ b/actions/DetectAction.php @@ -24,14 +24,14 @@ class DetectAction implements ActionInterface $format = $this->userData['format'] or returnClientError('You must specify a format!'); - $bridgeFac = new \BridgeFactory(); + $bridgeFactory = new \BridgeFactory(); - foreach ($bridgeFac->getBridgeNames() as $bridgeName) { - if (!$bridgeFac->isWhitelisted($bridgeName)) { + foreach ($bridgeFactory->getBridgeNames() as $bridgeName) { + if (!$bridgeFactory->isWhitelisted($bridgeName)) { continue; } - $bridge = $bridgeFac->create($bridgeName); + $bridge = $bridgeFactory->create($bridgeName); if ($bridge === false) { continue; diff --git a/actions/DisplayAction.php b/actions/DisplayAction.php index c404dcf5..5edf5c82 100644 --- a/actions/DisplayAction.php +++ b/actions/DisplayAction.php @@ -33,16 +33,16 @@ class DisplayAction implements ActionInterface $format = $this->userData['format'] or returnClientError('You must specify a format!'); - $bridgeFac = new \BridgeFactory(); + $bridgeFactory = new \BridgeFactory(); // whitelist control - if (!$bridgeFac->isWhitelisted($bridge)) { + if (!$bridgeFactory->isWhitelisted($bridge)) { throw new \Exception('This bridge is not whitelisted', 401); die; } // Data retrieval - $bridge = $bridgeFac->create($bridge); + $bridge = $bridgeFactory->create($bridge); $bridge->loadConfiguration(); $noproxy = array_key_exists('_noproxy', $this->userData) @@ -99,9 +99,9 @@ class DisplayAction implements ActionInterface ); // Initialize cache - $cacheFac = new CacheFactory(); + $cacheFactory = new CacheFactory(); - $cache = $cacheFac->create(); + $cache = $cacheFactory->create(); $cache->setScope(''); $cache->purgeCache(86400); // 24 hours $cache->setKey($cache_params); @@ -205,8 +205,8 @@ class DisplayAction implements ActionInterface // Data transformation try { - $formatFac = new FormatFactory(); - $format = $formatFac->create($format); + $formatFactory = new FormatFactory(); + $format = $formatFactory->create($format); $format->setItems($items); $format->setExtraInfos($infos); $lastModified = $cache->getTime(); diff --git a/actions/ListAction.php b/actions/ListAction.php index 7ddc42cb..1ad96717 100644 --- a/actions/ListAction.php +++ b/actions/ListAction.php @@ -20,10 +20,10 @@ class ListAction implements ActionInterface $list->bridges = []; $list->total = 0; - $bridgeFac = new \BridgeFactory(); + $bridgeFactory = new \BridgeFactory(); - foreach ($bridgeFac->getBridgeNames() as $bridgeName) { - $bridge = $bridgeFac->create($bridgeName); + foreach ($bridgeFactory->getBridgeNames() as $bridgeName) { + $bridge = $bridgeFactory->create($bridgeName); if ($bridge === false) { // Broken bridge, show as inactive $list->bridges[$bridgeName] = [ @@ -33,7 +33,7 @@ class ListAction implements ActionInterface continue; } - $status = $bridgeFac->isWhitelisted($bridgeName) ? 'active' : 'inactive'; + $status = $bridgeFactory->isWhitelisted($bridgeName) ? 'active' : 'inactive'; $list->bridges[$bridgeName] = [ 'status' => $status, diff --git a/bridges/ElloBridge.php b/bridges/ElloBridge.php index 22830b49..6d9c1a70 100644 --- a/bridges/ElloBridge.php +++ b/bridges/ElloBridge.php @@ -113,9 +113,9 @@ class ElloBridge extends BridgeAbstract private function getAPIKey() { - $cacheFac = new CacheFactory(); + $cacheFactory = new CacheFactory(); - $cache = $cacheFac->create(); + $cache = $cacheFactory->create(); $cache->setScope(get_called_class()); $cache->setKey(['key']); $key = $cache->loadData(); diff --git a/bridges/InstagramBridge.php b/bridges/InstagramBridge.php index 6b65bbcf..4e3bd23d 100644 --- a/bridges/InstagramBridge.php +++ b/bridges/InstagramBridge.php @@ -94,9 +94,9 @@ class InstagramBridge extends BridgeAbstract return $username; } - $cacheFac = new CacheFactory(); + $cacheFactory = new CacheFactory(); - $cache = $cacheFac->create(); + $cache = $cacheFactory->create(); $cache->setScope(get_called_class()); $cache->setKey([$username]); $key = $cache->loadData(); diff --git a/bridges/SoundcloudBridge.php b/bridges/SoundcloudBridge.php index 4b77ea30..996e9731 100644 --- a/bridges/SoundcloudBridge.php +++ b/bridges/SoundcloudBridge.php @@ -122,9 +122,9 @@ HTML; return; } - $cacheFac = new CacheFactory(); + $cacheFactory = new CacheFactory(); - $this->clientIDCache = $cacheFac->create(); + $this->clientIDCache = $cacheFactory->create(); $this->clientIDCache->setScope(get_called_class()); $this->clientIDCache->setKey(['client_id']); } diff --git a/bridges/SpotifyBridge.php b/bridges/SpotifyBridge.php index 48506e6d..8af3f232 100644 --- a/bridges/SpotifyBridge.php +++ b/bridges/SpotifyBridge.php @@ -100,9 +100,9 @@ class SpotifyBridge extends BridgeAbstract private function getToken() { - $cacheFac = new CacheFactory(); + $cacheFactory = new CacheFactory(); - $cache = $cacheFac->create(); + $cache = $cacheFactory->create(); $cache->setScope(get_called_class()); $cache->setKey(['token']); diff --git a/bridges/TwitterBridge.php b/bridges/TwitterBridge.php index b4622788..940d1b0f 100644 --- a/bridges/TwitterBridge.php +++ b/bridges/TwitterBridge.php @@ -503,9 +503,9 @@ EOD; //This function takes 2 requests, and therefore is cached private function getApiKey($forceNew = 0) { - $cacheFac = new CacheFactory(); + $cacheFactory = new CacheFactory(); - $r_cache = $cacheFac->create(); + $r_cache = $cacheFactory->create(); $r_cache->setScope(get_called_class()); $r_cache->setKey(['refresh']); $data = $r_cache->loadData(); @@ -518,9 +518,9 @@ EOD; $refresh = $data; } - $cacheFac = new CacheFactory(); + $cacheFactory = new CacheFactory(); - $cache = $cacheFac->create(); + $cache = $cacheFactory->create(); $cache->setScope(get_called_class()); $cache->setKey(['api_key']); $data = $cache->loadData(); @@ -557,7 +557,7 @@ EOD; $cacheFac2 = new CacheFactory(); - $gt_cache = $cacheFac->create(); + $gt_cache = $cacheFactory->create(); $gt_cache->setScope(get_called_class()); $gt_cache->setKey(['guest_token']); $guestTokenUses = $gt_cache->loadData(); diff --git a/formats/HtmlFormat.php b/formats/HtmlFormat.php index d60c4d81..d9ab65ef 100644 --- a/formats/HtmlFormat.php +++ b/formats/HtmlFormat.php @@ -13,12 +13,12 @@ class HtmlFormat extends FormatAbstract $donationsAllowed = Configuration::getConfig('admin', 'donations'); // Dynamically build buttons for all formats (except HTML) - $formatFac = new FormatFactory(); + $formatFactory = new FormatFactory(); $buttons = ''; $links = ''; - foreach ($formatFac->getFormatNames() as $format) { + foreach ($formatFactory->getFormatNames() as $format) { if (strcasecmp($format, 'HTML') === 0) { continue; } @@ -26,7 +26,7 @@ class HtmlFormat extends FormatAbstract $query = str_ireplace('format=Html', 'format=' . $format, htmlentities($_SERVER['QUERY_STRING'])); $buttons .= $this->buildButton($format, $query) . PHP_EOL; - $mime = $formatFac->create($format)->getMimeType(); + $mime = $formatFactory->create($format)->getMimeType(); $links .= $this->buildLink($format, $query, $mime) . PHP_EOL; } diff --git a/index.php b/index.php index 8ca1990c..b8dee496 100644 --- a/index.php +++ b/index.php @@ -14,10 +14,10 @@ if (isset($argv)) { } try { - $actionFac = new ActionFactory(); + $actionFactory = new ActionFactory(); if (array_key_exists('action', $params)) { - $action = $actionFac->create($params['action']); + $action = $actionFactory->create($params['action']); $action->userData = $params; $action->execute(); } else { diff --git a/lib/BridgeAbstract.php b/lib/BridgeAbstract.php index de6cd906..1a06ea8a 100644 --- a/lib/BridgeAbstract.php +++ b/lib/BridgeAbstract.php @@ -405,9 +405,9 @@ abstract class BridgeAbstract implements BridgeInterface */ protected function loadCacheValue($key, $duration = 86400) { - $cacheFac = new CacheFactory(); + $cacheFactory = new CacheFactory(); - $cache = $cacheFac->create(); + $cache = $cacheFactory->create(); $cache->setScope(get_called_class()); $cache->setKey($key); if ($cache->getTime() < time() - $duration) { @@ -424,9 +424,9 @@ abstract class BridgeAbstract implements BridgeInterface */ protected function saveCacheValue($key, $value) { - $cacheFac = new CacheFactory(); + $cacheFactory = new CacheFactory(); - $cache = $cacheFac->create(); + $cache = $cacheFactory->create(); $cache->setScope(get_called_class()); $cache->setKey($key); $cache->saveData($value); diff --git a/lib/BridgeCard.php b/lib/BridgeCard.php index 78132776..9ff7fcce 100644 --- a/lib/BridgeCard.php +++ b/lib/BridgeCard.php @@ -304,9 +304,9 @@ This bridge is not fetching its content through a secure connection'; */ public static function displayBridgeCard($bridgeName, $formats, $isActive = true) { - $bridgeFac = new \BridgeFactory(); + $bridgeFactory = new \BridgeFactory(); - $bridge = $bridgeFac->create($bridgeName); + $bridge = $bridgeFactory->create($bridgeName); if ($bridge == false) { return ''; diff --git a/lib/BridgeList.php b/lib/BridgeList.php index 921dfe50..d3056e62 100644 --- a/lib/BridgeList.php +++ b/lib/BridgeList.php @@ -65,16 +65,16 @@ EOD; $totalActiveBridges = 0; $inactiveBridges = ''; - $bridgeFac = new \BridgeFactory(); - $bridgeList = $bridgeFac->getBridgeNames(); + $bridgeFactory = new \BridgeFactory(); + $bridgeNames = $bridgeFactory->getBridgeNames(); - $formatFac = new FormatFactory(); - $formats = $formatFac->getFormatNames(); + $formatFactory = new FormatFactory(); + $formats = $formatFactory->getFormatNames(); - $totalBridges = count($bridgeList); + $totalBridges = count($bridgeNames); - foreach ($bridgeList as $bridgeName) { - if ($bridgeFac->isWhitelisted($bridgeName)) { + foreach ($bridgeNames as $bridgeName) { + if ($bridgeFactory->isWhitelisted($bridgeName)) { $body .= BridgeCard::displayBridgeCard($bridgeName, $formats); $totalActiveBridges++; } elseif ($showInactive) { diff --git a/lib/contents.php b/lib/contents.php index aaa078d6..d55edf8f 100644 --- a/lib/contents.php +++ b/lib/contents.php @@ -317,9 +317,9 @@ function getSimpleHTMLDOMCached( Debug::log('Caching url ' . $url . ', duration ' . $duration); // Initialize cache - $cacheFac = new CacheFactory(); + $cacheFactory = new CacheFactory(); - $cache = $cacheFac->create(); + $cache = $cacheFactory->create(); $cache->setScope('pages'); $cache->purgeCache(86400); // 24 hours (forced) diff --git a/lib/error.php b/lib/error.php index 39dd99f6..b8b2f9af 100644 --- a/lib/error.php +++ b/lib/error.php @@ -56,9 +56,9 @@ function returnServerError($message) */ function logBridgeError($bridgeName, $code) { - $cacheFac = new CacheFactory(); + $cacheFactory = new CacheFactory(); - $cache = $cacheFac->create(); + $cache = $cacheFactory->create(); $cache->setScope('error_reporting'); $cache->setkey($bridgeName . '_' . $code); $cache->purgeCache(86400); // 24 hours diff --git a/tests/Actions/ListActionTest.php b/tests/Actions/ListActionTest.php index 2eb2049d..437f184f 100644 --- a/tests/Actions/ListActionTest.php +++ b/tests/Actions/ListActionTest.php @@ -46,10 +46,10 @@ class ListActionTest extends TestCase 'Item count doesn\'t match' ); - $bridgeFac = new BridgeFactory(); + $bridgeFactory = new BridgeFactory(); $this->assertEquals( - count($bridgeFac->getBridgeNames()), + count($bridgeFactory->getBridgeNames()), count($items['bridges']), 'Number of bridges doesn\'t match' ); @@ -80,9 +80,9 @@ class ListActionTest extends TestCase private function initAction() { - $actionFac = new ActionFactory(); + $actionFactory = new ActionFactory(); - $action = $actionFac->create('list'); + $action = $actionFactory->create('list'); ob_start(); $action->execute(); diff --git a/tests/Formats/BaseFormatTest.php b/tests/Formats/BaseFormatTest.php index ace4d3ea..30ce1063 100644 --- a/tests/Formats/BaseFormatTest.php +++ b/tests/Formats/BaseFormatTest.php @@ -58,8 +58,8 @@ abstract class BaseFormatTest extends TestCase protected function formatData(string $formatName, \stdClass $sample): string { - $formatFac = new FormatFactory(); - $format = $formatFac->create($formatName); + $formatFactory = new FormatFactory(); + $format = $formatFactory->create($formatName); $format->setItems($sample->items); $format->setExtraInfos($sample->meta); $format->setLastModified(strtotime('2000-01-01 12:00:00 UTC'));