mirror of
https://github.com/PrivateBin/PrivateBin.git
synced 2026-04-18 21:48:24 -04:00
apply null coalescing operator, strict equality, avoid aliases, prefer empty
This commit is contained in:
@@ -90,7 +90,7 @@ class GoogleCloudStorage extends AbstractData
|
||||
*/
|
||||
private function _getKey($pasteid)
|
||||
{
|
||||
if ($this->_prefix != '') {
|
||||
if (!empty($this->_prefix)) {
|
||||
return $this->_prefix . '/' . $pasteid;
|
||||
}
|
||||
return $pasteid;
|
||||
@@ -258,15 +258,12 @@ class GoogleCloudStorage extends AbstractData
|
||||
if (strlen($name) > strlen($path) && substr($name, strlen($path), 1) !== '/') {
|
||||
continue;
|
||||
}
|
||||
$info = $object->info();
|
||||
if (key_exists('metadata', $info) && key_exists('value', $info['metadata'])) {
|
||||
$value = $info['metadata']['value'];
|
||||
if (is_numeric($value) && intval($value) < $time) {
|
||||
try {
|
||||
$object->delete();
|
||||
} catch (NotFoundException $e) {
|
||||
// deleted by another instance.
|
||||
}
|
||||
$value = $object->info()['metadata']['value'] ?? '';
|
||||
if (is_numeric($value) && intval($value) < $time) {
|
||||
try {
|
||||
$object->delete();
|
||||
} catch (NotFoundException $e) {
|
||||
// deleted by another instance.
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -282,14 +279,14 @@ class GoogleCloudStorage extends AbstractData
|
||||
*/
|
||||
public function setValue($value, $namespace, $key = '')
|
||||
{
|
||||
if ($key === '') {
|
||||
if (empty($key)) {
|
||||
$key = 'config/' . $namespace;
|
||||
} else {
|
||||
$key = 'config/' . $namespace . '/' . $key;
|
||||
}
|
||||
|
||||
$metadata = array('namespace' => $namespace);
|
||||
if ($namespace != 'salt') {
|
||||
if ($namespace !== 'salt') {
|
||||
$metadata['value'] = strval($value);
|
||||
}
|
||||
try {
|
||||
@@ -340,17 +337,15 @@ class GoogleCloudStorage extends AbstractData
|
||||
|
||||
$now = time();
|
||||
$prefix = $this->_prefix;
|
||||
if ($prefix != '') {
|
||||
if (!empty($prefix)) {
|
||||
$prefix .= '/';
|
||||
}
|
||||
try {
|
||||
foreach ($this->_bucket->objects(array('prefix' => $prefix)) as $object) {
|
||||
$metadata = $object->info()['metadata'];
|
||||
if ($metadata != null && array_key_exists('expire_date', $metadata)) {
|
||||
$expire_at = intval($metadata['expire_date']);
|
||||
if ($expire_at != 0 && $expire_at < $now) {
|
||||
array_push($expired, basename($object->name()));
|
||||
}
|
||||
$expire_at = $metadata['expire_date'] ?? '';
|
||||
if (is_numeric($expire_at) && intval($expire_at) < $now) {
|
||||
array_push($expired, basename($object->name()));
|
||||
}
|
||||
|
||||
if (count($expired) > $batchsize) {
|
||||
@@ -370,7 +365,7 @@ class GoogleCloudStorage extends AbstractData
|
||||
{
|
||||
$pastes = array();
|
||||
$prefix = $this->_prefix;
|
||||
if ($prefix != '') {
|
||||
if (!empty($prefix)) {
|
||||
$prefix .= '/';
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user