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)
{
$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);

View file

@ -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;

View file

@ -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();

View file

@ -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,

View file

@ -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();

View file

@ -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();

View file

@ -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']);
}

View file

@ -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']);

View file

@ -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();

View file

@ -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;
}

View file

@ -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 {

View file

@ -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);

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)
{
$bridgeFac = new \BridgeFactory();
$bridgeFactory = new \BridgeFactory();
$bridge = $bridgeFac->create($bridgeName);
$bridge = $bridgeFactory->create($bridgeName);
if ($bridge == false) {
return '';

View file

@ -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) {

View file

@ -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)

View file

@ -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

View file

@ -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();

View file

@ -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'));