Improve Factory variable names (#2895)

This commit is contained in:
Jan Tojnar 2022-07-06 12:14:04 +02:00 committed by GitHub
parent e3dad86bca
commit d107f8ed30
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
18 changed files with 59 additions and 59 deletions

View File

@ -57,9 +57,9 @@ class ConnectivityAction implements ActionInterface
*/ */
private function reportBridgeConnectivity($bridgeName) private function reportBridgeConnectivity($bridgeName)
{ {
$bridgeFac = new \BridgeFactory(); $bridgeFactory = new \BridgeFactory();
if (!$bridgeFac->isWhitelisted($bridgeName)) { if (!$bridgeFactory->isWhitelisted($bridgeName)) {
header('Content-Type: text/html'); header('Content-Type: text/html');
returnServerError('Bridge is not whitelisted!'); returnServerError('Bridge is not whitelisted!');
} }
@ -72,7 +72,7 @@ class ConnectivityAction implements ActionInterface
'http_code' => 200, 'http_code' => 200,
]; ];
$bridge = $bridgeFac->create($bridgeName); $bridge = $bridgeFactory->create($bridgeName);
if ($bridge === false) { if ($bridge === false) {
echo json_encode($retVal); echo json_encode($retVal);

View File

@ -24,14 +24,14 @@ class DetectAction implements ActionInterface
$format = $this->userData['format'] $format = $this->userData['format']
or returnClientError('You must specify a format!'); or returnClientError('You must specify a format!');
$bridgeFac = new \BridgeFactory(); $bridgeFactory = new \BridgeFactory();
foreach ($bridgeFac->getBridgeNames() as $bridgeName) { foreach ($bridgeFactory->getBridgeNames() as $bridgeName) {
if (!$bridgeFac->isWhitelisted($bridgeName)) { if (!$bridgeFactory->isWhitelisted($bridgeName)) {
continue; continue;
} }
$bridge = $bridgeFac->create($bridgeName); $bridge = $bridgeFactory->create($bridgeName);
if ($bridge === false) { if ($bridge === false) {
continue; continue;

View File

@ -33,16 +33,16 @@ class DisplayAction implements ActionInterface
$format = $this->userData['format'] $format = $this->userData['format']
or returnClientError('You must specify a format!'); or returnClientError('You must specify a format!');
$bridgeFac = new \BridgeFactory(); $bridgeFactory = new \BridgeFactory();
// whitelist control // whitelist control
if (!$bridgeFac->isWhitelisted($bridge)) { if (!$bridgeFactory->isWhitelisted($bridge)) {
throw new \Exception('This bridge is not whitelisted', 401); throw new \Exception('This bridge is not whitelisted', 401);
die; die;
} }
// Data retrieval // Data retrieval
$bridge = $bridgeFac->create($bridge); $bridge = $bridgeFactory->create($bridge);
$bridge->loadConfiguration(); $bridge->loadConfiguration();
$noproxy = array_key_exists('_noproxy', $this->userData) $noproxy = array_key_exists('_noproxy', $this->userData)
@ -99,9 +99,9 @@ class DisplayAction implements ActionInterface
); );
// Initialize cache // Initialize cache
$cacheFac = new CacheFactory(); $cacheFactory = new CacheFactory();
$cache = $cacheFac->create(); $cache = $cacheFactory->create();
$cache->setScope(''); $cache->setScope('');
$cache->purgeCache(86400); // 24 hours $cache->purgeCache(86400); // 24 hours
$cache->setKey($cache_params); $cache->setKey($cache_params);
@ -205,8 +205,8 @@ class DisplayAction implements ActionInterface
// Data transformation // Data transformation
try { try {
$formatFac = new FormatFactory(); $formatFactory = new FormatFactory();
$format = $formatFac->create($format); $format = $formatFactory->create($format);
$format->setItems($items); $format->setItems($items);
$format->setExtraInfos($infos); $format->setExtraInfos($infos);
$lastModified = $cache->getTime(); $lastModified = $cache->getTime();

View File

@ -20,10 +20,10 @@ class ListAction implements ActionInterface
$list->bridges = []; $list->bridges = [];
$list->total = 0; $list->total = 0;
$bridgeFac = new \BridgeFactory(); $bridgeFactory = new \BridgeFactory();
foreach ($bridgeFac->getBridgeNames() as $bridgeName) { foreach ($bridgeFactory->getBridgeNames() as $bridgeName) {
$bridge = $bridgeFac->create($bridgeName); $bridge = $bridgeFactory->create($bridgeName);
if ($bridge === false) { // Broken bridge, show as inactive if ($bridge === false) { // Broken bridge, show as inactive
$list->bridges[$bridgeName] = [ $list->bridges[$bridgeName] = [
@ -33,7 +33,7 @@ class ListAction implements ActionInterface
continue; continue;
} }
$status = $bridgeFac->isWhitelisted($bridgeName) ? 'active' : 'inactive'; $status = $bridgeFactory->isWhitelisted($bridgeName) ? 'active' : 'inactive';
$list->bridges[$bridgeName] = [ $list->bridges[$bridgeName] = [
'status' => $status, 'status' => $status,

View File

@ -113,9 +113,9 @@ class ElloBridge extends BridgeAbstract
private function getAPIKey() private function getAPIKey()
{ {
$cacheFac = new CacheFactory(); $cacheFactory = new CacheFactory();
$cache = $cacheFac->create(); $cache = $cacheFactory->create();
$cache->setScope(get_called_class()); $cache->setScope(get_called_class());
$cache->setKey(['key']); $cache->setKey(['key']);
$key = $cache->loadData(); $key = $cache->loadData();

View File

@ -94,9 +94,9 @@ class InstagramBridge extends BridgeAbstract
return $username; return $username;
} }
$cacheFac = new CacheFactory(); $cacheFactory = new CacheFactory();
$cache = $cacheFac->create(); $cache = $cacheFactory->create();
$cache->setScope(get_called_class()); $cache->setScope(get_called_class());
$cache->setKey([$username]); $cache->setKey([$username]);
$key = $cache->loadData(); $key = $cache->loadData();

View File

@ -122,9 +122,9 @@ HTML;
return; return;
} }
$cacheFac = new CacheFactory(); $cacheFactory = new CacheFactory();
$this->clientIDCache = $cacheFac->create(); $this->clientIDCache = $cacheFactory->create();
$this->clientIDCache->setScope(get_called_class()); $this->clientIDCache->setScope(get_called_class());
$this->clientIDCache->setKey(['client_id']); $this->clientIDCache->setKey(['client_id']);
} }

View File

@ -100,9 +100,9 @@ class SpotifyBridge extends BridgeAbstract
private function getToken() private function getToken()
{ {
$cacheFac = new CacheFactory(); $cacheFactory = new CacheFactory();
$cache = $cacheFac->create(); $cache = $cacheFactory->create();
$cache->setScope(get_called_class()); $cache->setScope(get_called_class());
$cache->setKey(['token']); $cache->setKey(['token']);

View File

@ -503,9 +503,9 @@ EOD;
//This function takes 2 requests, and therefore is cached //This function takes 2 requests, and therefore is cached
private function getApiKey($forceNew = 0) 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->setScope(get_called_class());
$r_cache->setKey(['refresh']); $r_cache->setKey(['refresh']);
$data = $r_cache->loadData(); $data = $r_cache->loadData();
@ -518,9 +518,9 @@ EOD;
$refresh = $data; $refresh = $data;
} }
$cacheFac = new CacheFactory(); $cacheFactory = new CacheFactory();
$cache = $cacheFac->create(); $cache = $cacheFactory->create();
$cache->setScope(get_called_class()); $cache->setScope(get_called_class());
$cache->setKey(['api_key']); $cache->setKey(['api_key']);
$data = $cache->loadData(); $data = $cache->loadData();
@ -557,7 +557,7 @@ EOD;
$cacheFac2 = new CacheFactory(); $cacheFac2 = new CacheFactory();
$gt_cache = $cacheFac->create(); $gt_cache = $cacheFactory->create();
$gt_cache->setScope(get_called_class()); $gt_cache->setScope(get_called_class());
$gt_cache->setKey(['guest_token']); $gt_cache->setKey(['guest_token']);
$guestTokenUses = $gt_cache->loadData(); $guestTokenUses = $gt_cache->loadData();

View File

@ -13,12 +13,12 @@ class HtmlFormat extends FormatAbstract
$donationsAllowed = Configuration::getConfig('admin', 'donations'); $donationsAllowed = Configuration::getConfig('admin', 'donations');
// Dynamically build buttons for all formats (except HTML) // Dynamically build buttons for all formats (except HTML)
$formatFac = new FormatFactory(); $formatFactory = new FormatFactory();
$buttons = ''; $buttons = '';
$links = ''; $links = '';
foreach ($formatFac->getFormatNames() as $format) { foreach ($formatFactory->getFormatNames() as $format) {
if (strcasecmp($format, 'HTML') === 0) { if (strcasecmp($format, 'HTML') === 0) {
continue; continue;
} }
@ -26,7 +26,7 @@ class HtmlFormat extends FormatAbstract
$query = str_ireplace('format=Html', 'format=' . $format, htmlentities($_SERVER['QUERY_STRING'])); $query = str_ireplace('format=Html', 'format=' . $format, htmlentities($_SERVER['QUERY_STRING']));
$buttons .= $this->buildButton($format, $query) . PHP_EOL; $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; $links .= $this->buildLink($format, $query, $mime) . PHP_EOL;
} }

View File

@ -14,10 +14,10 @@ if (isset($argv)) {
} }
try { try {
$actionFac = new ActionFactory(); $actionFactory = new ActionFactory();
if (array_key_exists('action', $params)) { if (array_key_exists('action', $params)) {
$action = $actionFac->create($params['action']); $action = $actionFactory->create($params['action']);
$action->userData = $params; $action->userData = $params;
$action->execute(); $action->execute();
} else { } else {

View File

@ -405,9 +405,9 @@ abstract class BridgeAbstract implements BridgeInterface
*/ */
protected function loadCacheValue($key, $duration = 86400) protected function loadCacheValue($key, $duration = 86400)
{ {
$cacheFac = new CacheFactory(); $cacheFactory = new CacheFactory();
$cache = $cacheFac->create(); $cache = $cacheFactory->create();
$cache->setScope(get_called_class()); $cache->setScope(get_called_class());
$cache->setKey($key); $cache->setKey($key);
if ($cache->getTime() < time() - $duration) { if ($cache->getTime() < time() - $duration) {
@ -424,9 +424,9 @@ abstract class BridgeAbstract implements BridgeInterface
*/ */
protected function saveCacheValue($key, $value) protected function saveCacheValue($key, $value)
{ {
$cacheFac = new CacheFactory(); $cacheFactory = new CacheFactory();
$cache = $cacheFac->create(); $cache = $cacheFactory->create();
$cache->setScope(get_called_class()); $cache->setScope(get_called_class());
$cache->setKey($key); $cache->setKey($key);
$cache->saveData($value); $cache->saveData($value);

View File

@ -304,9 +304,9 @@ This bridge is not fetching its content through a secure connection</div>';
*/ */
public static function displayBridgeCard($bridgeName, $formats, $isActive = true) 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) { if ($bridge == false) {
return ''; return '';

View File

@ -65,16 +65,16 @@ EOD;
$totalActiveBridges = 0; $totalActiveBridges = 0;
$inactiveBridges = ''; $inactiveBridges = '';
$bridgeFac = new \BridgeFactory(); $bridgeFactory = new \BridgeFactory();
$bridgeList = $bridgeFac->getBridgeNames(); $bridgeNames = $bridgeFactory->getBridgeNames();
$formatFac = new FormatFactory(); $formatFactory = new FormatFactory();
$formats = $formatFac->getFormatNames(); $formats = $formatFactory->getFormatNames();
$totalBridges = count($bridgeList); $totalBridges = count($bridgeNames);
foreach ($bridgeList as $bridgeName) { foreach ($bridgeNames as $bridgeName) {
if ($bridgeFac->isWhitelisted($bridgeName)) { if ($bridgeFactory->isWhitelisted($bridgeName)) {
$body .= BridgeCard::displayBridgeCard($bridgeName, $formats); $body .= BridgeCard::displayBridgeCard($bridgeName, $formats);
$totalActiveBridges++; $totalActiveBridges++;
} elseif ($showInactive) { } elseif ($showInactive) {

View File

@ -317,9 +317,9 @@ function getSimpleHTMLDOMCached(
Debug::log('Caching url ' . $url . ', duration ' . $duration); Debug::log('Caching url ' . $url . ', duration ' . $duration);
// Initialize cache // Initialize cache
$cacheFac = new CacheFactory(); $cacheFactory = new CacheFactory();
$cache = $cacheFac->create(); $cache = $cacheFactory->create();
$cache->setScope('pages'); $cache->setScope('pages');
$cache->purgeCache(86400); // 24 hours (forced) $cache->purgeCache(86400); // 24 hours (forced)

View File

@ -56,9 +56,9 @@ function returnServerError($message)
*/ */
function logBridgeError($bridgeName, $code) function logBridgeError($bridgeName, $code)
{ {
$cacheFac = new CacheFactory(); $cacheFactory = new CacheFactory();
$cache = $cacheFac->create(); $cache = $cacheFactory->create();
$cache->setScope('error_reporting'); $cache->setScope('error_reporting');
$cache->setkey($bridgeName . '_' . $code); $cache->setkey($bridgeName . '_' . $code);
$cache->purgeCache(86400); // 24 hours $cache->purgeCache(86400); // 24 hours

View File

@ -46,10 +46,10 @@ class ListActionTest extends TestCase
'Item count doesn\'t match' 'Item count doesn\'t match'
); );
$bridgeFac = new BridgeFactory(); $bridgeFactory = new BridgeFactory();
$this->assertEquals( $this->assertEquals(
count($bridgeFac->getBridgeNames()), count($bridgeFactory->getBridgeNames()),
count($items['bridges']), count($items['bridges']),
'Number of bridges doesn\'t match' 'Number of bridges doesn\'t match'
); );
@ -80,9 +80,9 @@ class ListActionTest extends TestCase
private function initAction() private function initAction()
{ {
$actionFac = new ActionFactory(); $actionFactory = new ActionFactory();
$action = $actionFac->create('list'); $action = $actionFactory->create('list');
ob_start(); ob_start();
$action->execute(); $action->execute();

View File

@ -58,8 +58,8 @@ abstract class BaseFormatTest extends TestCase
protected function formatData(string $formatName, \stdClass $sample): string protected function formatData(string $formatName, \stdClass $sample): string
{ {
$formatFac = new FormatFactory(); $formatFactory = new FormatFactory();
$format = $formatFac->create($formatName); $format = $formatFactory->create($formatName);
$format->setItems($sample->items); $format->setItems($sample->items);
$format->setExtraInfos($sample->meta); $format->setExtraInfos($sample->meta);
$format->setLastModified(strtotime('2000-01-01 12:00:00 UTC')); $format->setLastModified(strtotime('2000-01-01 12:00:00 UTC'));