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

View File

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

View File

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

View File

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