address Codacy issues

This commit is contained in:
El RIDO 2021-06-13 10:53:01 +02:00
parent 93135e0abf
commit 1f2dddd9d8
No known key found for this signature in database
GPG key ID: 0F5C940A6BD81F92
4 changed files with 15 additions and 24 deletions

View file

@ -35,7 +35,7 @@ abstract class AbstractData
* @static * @static
* @var array * @var array
*/ */
protected static $_traffic_limiter_cache = array(); protected static $_last_cache = array();
/** /**
* Enforce singleton, disable constructor * Enforce singleton, disable constructor
@ -150,9 +150,9 @@ abstract class AbstractData
public function purgeValues($namespace, $time) public function purgeValues($namespace, $time)
{ {
if ($namespace === 'traffic_limiter') { if ($namespace === 'traffic_limiter') {
foreach (self::$_traffic_limiter_cache as $key => $last_access) { foreach (self::$_last_cache as $key => $last_submission) {
if ($last_access <= $time) { if ($last_submission <= $time) {
unset(self::$_traffic_limiter_cache[$key]); unset(self::$_last_cache[$key]);
} }
} }
} }

View file

@ -447,9 +447,9 @@ class Database extends AbstractData
public function setValue($value, $namespace, $key = '') public function setValue($value, $namespace, $key = '')
{ {
if ($namespace === 'traffic_limiter') { if ($namespace === 'traffic_limiter') {
self::$_traffic_limiter_cache[$key] = $value; self::$_last_cache[$key] = $value;
try { try {
$value = Json::encode(self::$_traffic_limiter_cache); $value = Json::encode(self::$_last_cache);
} catch (Exception $e) { } catch (Exception $e) {
return false; return false;
} }
@ -492,12 +492,12 @@ class Database extends AbstractData
} }
if ($value && $namespace === 'traffic_limiter') { if ($value && $namespace === 'traffic_limiter') {
try { try {
self::$_traffic_limiter_cache = Json::decode($value); self::$_last_cache = Json::decode($value);
} catch (Exception $e) { } catch (Exception $e) {
self::$_traffic_limiter_cache = array(); self::$_last_cache = array();
} }
if (array_key_exists($key, self::$_traffic_limiter_cache)) { if (array_key_exists($key, self::$_last_cache)) {
return self::$_traffic_limiter_cache[$key]; return self::$_last_cache[$key];
} }
} }
return (string) $value; return (string) $value;

View file

@ -263,10 +263,10 @@ class Filesystem extends AbstractData
'<?php # |' . $value . '|' '<?php # |' . $value . '|'
); );
case 'traffic_limiter': case 'traffic_limiter':
self::$_traffic_limiter_cache[$key] = $value; self::$_last_cache[$key] = $value;
return self::_storeString( return self::_storeString(
self::$_path . DIRECTORY_SEPARATOR . 'traffic_limiter.php', self::$_path . DIRECTORY_SEPARATOR . 'traffic_limiter.php',
'<?php' . PHP_EOL . '$GLOBALS[\'traffic_limiter\'] = ' . var_export(self::$_traffic_limiter_cache, true) . ';' '<?php' . PHP_EOL . '$GLOBALS[\'traffic_limiter\'] = ' . var_export(self::$_last_cache, true) . ';'
); );
} }
return false; return false;
@ -303,9 +303,9 @@ class Filesystem extends AbstractData
$file = self::$_path . DIRECTORY_SEPARATOR . 'traffic_limiter.php'; $file = self::$_path . DIRECTORY_SEPARATOR . 'traffic_limiter.php';
if (is_readable($file)) { if (is_readable($file)) {
require $file; require $file;
self::$_traffic_limiter_cache = $GLOBALS['traffic_limiter']; self::$_last_cache = $GLOBALS['traffic_limiter'];
if (array_key_exists($key, self::$_traffic_limiter_cache)) { if (array_key_exists($key, self::$_last_cache)) {
return self::$_traffic_limiter_cache[$key]; return self::$_last_cache[$key];
} }
} }
break; break;

View file

@ -26,15 +26,6 @@ use PrivateBin\Data\AbstractData;
*/ */
class ServerSalt extends AbstractPersistence class ServerSalt extends AbstractPersistence
{ {
/**
* file where salt is saved to
*
* @access private
* @static
* @var string
*/
private static $_file = 'salt.php';
/** /**
* generated salt * generated salt
* *