apply null coalescing operator, strict equality, avoid aliases, prefer empty

This commit is contained in:
El RIDO 2025-11-20 08:19:14 +01:00
parent fc4a92e6a4
commit b4db5f8e57
No known key found for this signature in database
GPG key ID: 0F5C940A6BD81F92
17 changed files with 86 additions and 104 deletions

View file

@ -309,7 +309,7 @@ class Filesystem extends AbstractData
$file = $this->_path . DIRECTORY_SEPARATOR . 'salt.php';
if (is_readable($file)) {
$items = explode('|', file_get_contents($file));
if (count($items) == 3) {
if (count($items) === 3) {
return $items[1];
}
}

View file

@ -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 .= '/';
}

View file

@ -148,7 +148,7 @@ class S3Storage extends AbstractData
*/
private function _getKey($pasteid)
{
if ($this->_prefix != '') {
if (!empty($this->_prefix)) {
return $this->_prefix . '/' . $pasteid;
}
return $pasteid;
@ -317,7 +317,7 @@ class S3Storage extends AbstractData
public function purgeValues($namespace, $time)
{
$path = $this->_prefix;
if ($path != '') {
if (!empty($path)) {
$path .= '/';
}
$path .= 'config/' . $namespace;
@ -332,17 +332,15 @@ class S3Storage extends AbstractData
'Bucket' => $this->_bucket,
'Key' => $name,
));
if ($head->get('Metadata') != null && array_key_exists('value', $head->get('Metadata'))) {
$value = $head->get('Metadata')['value'];
if (is_numeric($value) && intval($value) < $time) {
try {
$this->_client->deleteObject(array(
'Bucket' => $this->_bucket,
'Key' => $name,
));
} catch (S3Exception $e) {
// deleted by another instance.
}
$value = $head->get('Metadata')['value'] ?? '';
if (is_numeric($value) && intval($value) < $time) {
try {
$this->_client->deleteObject(array(
'Bucket' => $this->_bucket,
'Key' => $name,
));
} catch (S3Exception $e) {
// deleted by another instance.
}
}
}
@ -359,7 +357,7 @@ class S3Storage extends AbstractData
public function setValue($value, $namespace, $key = '')
{
$prefix = $this->_prefix;
if ($prefix != '') {
if (!empty($prefix)) {
$prefix .= '/';
}
@ -370,7 +368,7 @@ class S3Storage extends AbstractData
}
$metadata = array('namespace' => $namespace);
if ($namespace != 'salt') {
if ($namespace !== 'salt') {
$metadata['value'] = strval($value);
}
try {
@ -395,7 +393,7 @@ class S3Storage extends AbstractData
public function getValue($namespace, $key = '')
{
$prefix = $this->_prefix;
if ($prefix != '') {
if (!empty($prefix)) {
$prefix .= '/';
}
@ -424,7 +422,7 @@ class S3Storage extends AbstractData
$expired = array();
$now = time();
$prefix = $this->_prefix;
if ($prefix != '') {
if (!empty($prefix)) {
$prefix .= '/';
}
@ -434,11 +432,9 @@ class S3Storage extends AbstractData
'Bucket' => $this->_bucket,
'Key' => $object['Key'],
));
if ($head->get('Metadata') != null && array_key_exists('expire_date', $head->get('Metadata'))) {
$expire_at = intval($head->get('Metadata')['expire_date']);
if ($expire_at != 0 && $expire_at < $now) {
array_push($expired, $object['Key']);
}
$expire_at = $metadata['expire_date'] ?? '';
if (is_numeric($expire_at) && intval($expire_at) < $now) {
array_push($expired, $object['Key']);
}
if (count($expired) > $batchsize) {
@ -458,7 +454,7 @@ class S3Storage extends AbstractData
{
$pastes = array();
$prefix = $this->_prefix;
if ($prefix != '') {
if (!empty($prefix)) {
$prefix .= '/';
}