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
17 changed files with 86 additions and 104 deletions

View File

@@ -160,7 +160,7 @@ class Configuration
$opts = '_options'; $opts = '_options';
foreach (self::getDefaults() as $section => $values) { foreach (self::getDefaults() as $section => $values) {
// fill missing sections with default values // fill missing sections with default values
if (!array_key_exists($section, $config) || count($config[$section]) == 0) { if (!array_key_exists($section, $config) || count($config[$section]) === 0) {
$this->_configuration[$section] = $values; $this->_configuration[$section] = $values;
if (array_key_exists('dir', $this->_configuration[$section])) { if (array_key_exists('dir', $this->_configuration[$section])) {
$this->_configuration[$section]['dir'] = PATH . $this->_configuration[$section]['dir']; $this->_configuration[$section]['dir'] = PATH . $this->_configuration[$section]['dir'];
@@ -169,7 +169,7 @@ class Configuration
} }
// provide different defaults for database model // provide different defaults for database model
elseif ( elseif (
$section == 'model_options' && $section === 'model_options' &&
$this->_configuration['model']['class'] === 'Database' $this->_configuration['model']['class'] === 'Database'
) { ) {
$values = array( $values = array(
@@ -180,7 +180,7 @@ class Configuration
'opt' => array(), 'opt' => array(),
); );
} elseif ( } elseif (
$section == 'model_options' && $section === 'model_options' &&
$this->_configuration['model']['class'] === 'GoogleCloudStorage' $this->_configuration['model']['class'] === 'GoogleCloudStorage'
) { ) {
$values = array( $values = array(
@@ -189,7 +189,7 @@ class Configuration
'uniformacl' => false, 'uniformacl' => false,
); );
} elseif ( } elseif (
$section == 'model_options' && $section === 'model_options' &&
$this->_configuration['model']['class'] === 'S3Storage' $this->_configuration['model']['class'] === 'S3Storage'
) { ) {
$values = array( $values = array(
@@ -218,11 +218,11 @@ class Configuration
// check for missing keys and set defaults if necessary // check for missing keys and set defaults if necessary
else { else {
// preserve configured SRI hashes // preserve configured SRI hashes
if ($section == 'sri' && array_key_exists($section, $config)) { if ($section === 'sri' && array_key_exists($section, $config)) {
$this->_configuration[$section] = $config[$section]; $this->_configuration[$section] = $config[$section];
} }
foreach ($values as $key => $val) { foreach ($values as $key => $val) {
if ($key == 'dir') { if ($key === 'dir') {
$val = PATH . $val; $val = PATH . $val;
} }
$result = $val; $result = $val;

View File

@@ -204,7 +204,7 @@ class Controller
$lang = $this->_conf->getKey('languagedefault'); $lang = $this->_conf->getKey('languagedefault');
I18n::setLanguageFallback($lang); I18n::setLanguageFallback($lang);
// force default language, if language selection is disabled and a default is set // force default language, if language selection is disabled and a default is set
if (!$this->_conf->getKey('languageselection') && strlen($lang) == 2) { if (!$this->_conf->getKey('languageselection') && strlen($lang) === 2) {
$_COOKIE['lang'] = $lang; $_COOKIE['lang'] = $lang;
setcookie('lang', $lang, array('SameSite' => 'Lax', 'Secure' => true)); setcookie('lang', $lang, array('SameSite' => 'Lax', 'Secure' => true));
} }
@@ -421,7 +421,7 @@ class Controller
// label all the expiration options // label all the expiration options
$expire = array(); $expire = array();
foreach ($this->_conf->getSection('expire_options') as $time => $seconds) { foreach ($this->_conf->getSection('expire_options') as $time => $seconds) {
$expire[$time] = ($seconds == 0) ? I18n::_(ucfirst($time)) : Filter::formatHumanReadableTime($time); $expire[$time] = ($seconds === 0) ? I18n::_(ucfirst($time)) : Filter::formatHumanReadableTime($time);
} }
// translate all the formatter options // translate all the formatter options

View File

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

View File

@@ -90,7 +90,7 @@ class GoogleCloudStorage extends AbstractData
*/ */
private function _getKey($pasteid) private function _getKey($pasteid)
{ {
if ($this->_prefix != '') { if (!empty($this->_prefix)) {
return $this->_prefix . '/' . $pasteid; return $this->_prefix . '/' . $pasteid;
} }
return $pasteid; return $pasteid;
@@ -258,15 +258,12 @@ class GoogleCloudStorage extends AbstractData
if (strlen($name) > strlen($path) && substr($name, strlen($path), 1) !== '/') { if (strlen($name) > strlen($path) && substr($name, strlen($path), 1) !== '/') {
continue; continue;
} }
$info = $object->info(); $value = $object->info()['metadata']['value'] ?? '';
if (key_exists('metadata', $info) && key_exists('value', $info['metadata'])) { if (is_numeric($value) && intval($value) < $time) {
$value = $info['metadata']['value']; try {
if (is_numeric($value) && intval($value) < $time) { $object->delete();
try { } catch (NotFoundException $e) {
$object->delete(); // deleted by another instance.
} catch (NotFoundException $e) {
// deleted by another instance.
}
} }
} }
} }
@@ -282,14 +279,14 @@ class GoogleCloudStorage extends AbstractData
*/ */
public function setValue($value, $namespace, $key = '') public function setValue($value, $namespace, $key = '')
{ {
if ($key === '') { if (empty($key)) {
$key = 'config/' . $namespace; $key = 'config/' . $namespace;
} else { } else {
$key = 'config/' . $namespace . '/' . $key; $key = 'config/' . $namespace . '/' . $key;
} }
$metadata = array('namespace' => $namespace); $metadata = array('namespace' => $namespace);
if ($namespace != 'salt') { if ($namespace !== 'salt') {
$metadata['value'] = strval($value); $metadata['value'] = strval($value);
} }
try { try {
@@ -340,17 +337,15 @@ class GoogleCloudStorage extends AbstractData
$now = time(); $now = time();
$prefix = $this->_prefix; $prefix = $this->_prefix;
if ($prefix != '') { if (!empty($prefix)) {
$prefix .= '/'; $prefix .= '/';
} }
try { try {
foreach ($this->_bucket->objects(array('prefix' => $prefix)) as $object) { foreach ($this->_bucket->objects(array('prefix' => $prefix)) as $object) {
$metadata = $object->info()['metadata']; $metadata = $object->info()['metadata'];
if ($metadata != null && array_key_exists('expire_date', $metadata)) { $expire_at = $metadata['expire_date'] ?? '';
$expire_at = intval($metadata['expire_date']); if (is_numeric($expire_at) && intval($expire_at) < $now) {
if ($expire_at != 0 && $expire_at < $now) { array_push($expired, basename($object->name()));
array_push($expired, basename($object->name()));
}
} }
if (count($expired) > $batchsize) { if (count($expired) > $batchsize) {
@@ -370,7 +365,7 @@ class GoogleCloudStorage extends AbstractData
{ {
$pastes = array(); $pastes = array();
$prefix = $this->_prefix; $prefix = $this->_prefix;
if ($prefix != '') { if (!empty($prefix)) {
$prefix .= '/'; $prefix .= '/';
} }

View File

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

View File

@@ -40,7 +40,7 @@ class FormatV2
} }
// Make sure no additionnal keys were added. // Make sure no additionnal keys were added.
if (count(array_keys($message)) != count($required_keys)) { if (count(array_keys($message)) !== count($required_keys)) {
return false; return false;
} }

View File

@@ -183,7 +183,7 @@ class I18n
} }
// load translations // load translations
if (self::$_language == 'en') { if (self::$_language === 'en') {
self::$_translations = array(); self::$_translations = array();
} else { } else {
$data = file_get_contents(self::_getPath(self::$_language . '.json')); $data = file_get_contents(self::_getPath(self::$_language . '.json'));
@@ -200,14 +200,14 @@ class I18n
*/ */
public static function getAvailableLanguages() public static function getAvailableLanguages()
{ {
if (count(self::$_availableLanguages) == 0) { if (count(self::$_availableLanguages) === 0) {
self::$_availableLanguages[] = 'en'; // en.json is not part of the release archive self::$_availableLanguages[] = 'en'; // en.json is not part of the release archive
$languageIterator = new AppendIterator(); $languageIterator = new AppendIterator();
$languageIterator->append(new GlobIterator(self::_getPath('??.json'))); $languageIterator->append(new GlobIterator(self::_getPath('??.json')));
$languageIterator->append(new GlobIterator(self::_getPath('???.json'))); // for jbo $languageIterator->append(new GlobIterator(self::_getPath('???.json'))); // for jbo
foreach ($languageIterator as $file) { foreach ($languageIterator as $file) {
$language = $file->getBasename('.json'); $language = $file->getBasename('.json');
if ($language != 'en') { if ($language !== 'en') {
self::$_availableLanguages[] = $language; self::$_availableLanguages[] = $language;
} }
} }
@@ -276,11 +276,11 @@ class I18n
public static function getLanguageLabels($languages = array()) public static function getLanguageLabels($languages = array())
{ {
$file = self::_getPath('languages.json'); $file = self::_getPath('languages.json');
if (count(self::$_languageLabels) == 0 && is_readable($file)) { if (count(self::$_languageLabels) === 0 && is_readable($file)) {
$data = file_get_contents($file); $data = file_get_contents($file);
self::$_languageLabels = Json::decode($data); self::$_languageLabels = Json::decode($data);
} }
if (count($languages) == 0) { if (count($languages) === 0) {
return self::$_languageLabels; return self::$_languageLabels;
} }
return array_intersect_key(self::$_languageLabels, array_flip($languages)); return array_intersect_key(self::$_languageLabels, array_flip($languages));
@@ -367,7 +367,7 @@ class I18n
return $n === 1 ? 0 : (($n === 0 || ($n % 100 > 0 && $n % 100 < 20)) ? 1 : 2); return $n === 1 ? 0 : (($n === 0 || ($n % 100 > 0 && $n % 100 < 20)) ? 1 : 2);
case 'ru': case 'ru':
case 'uk': case 'uk':
return $n % 10 === 1 && $n % 100 != 11 ? 0 : ($n % 10 >= 2 && $n % 10 <= 4 && ($n % 100 < 10 || $n % 100 >= 20) ? 1 : 2); return $n % 10 === 1 && $n % 100 !== 11 ? 0 : ($n % 10 >= 2 && $n % 10 <= 4 && ($n % 100 < 10 || $n % 100 >= 20) ? 1 : 2);
case 'sl': case 'sl':
return $n % 100 === 1 ? 1 : ($n % 100 === 2 ? 2 : ($n % 100 === 3 || $n % 100 === 4 ? 3 : 0)); return $n % 100 === 1 ? 1 : ($n % 100 === 2 ? 2 : ($n % 100 === 3 || $n % 100 === 4 ? 3 : 0));
default: default:

View File

@@ -148,13 +148,13 @@ class Comment extends AbstractModel
{ {
// we generate an icon based on a SHA512 HMAC of the users IP, if configured // we generate an icon based on a SHA512 HMAC of the users IP, if configured
$icon = $this->_conf->getKey('icon'); $icon = $this->_conf->getKey('icon');
if ($icon != 'none') { if ($icon !== 'none') {
$pngdata = ''; $pngdata = '';
$hmac = TrafficLimiter::getHash(); $hmac = TrafficLimiter::getHash();
if ($icon == 'identicon') { if ($icon === 'identicon') {
$identicon = new Identicon(); $identicon = new Identicon();
$pngdata = $identicon->getImageDataUri($hmac, 16); $pngdata = $identicon->getImageDataUri($hmac, 16);
} elseif ($icon == 'jdenticon') { } elseif ($icon === 'jdenticon') {
$jdenticon = new Jdenticon(array( $jdenticon = new Jdenticon(array(
'hash' => $hmac, 'hash' => $hmac,
'size' => 16, 'size' => 16,
@@ -164,13 +164,13 @@ class Comment extends AbstractModel
), ),
)); ));
$pngdata = $jdenticon->getImageDataUri('png'); $pngdata = $jdenticon->getImageDataUri('png');
} elseif ($icon == 'vizhash') { } elseif ($icon === 'vizhash') {
$vh = new Vizhash16x16(); $vh = new Vizhash16x16();
$pngdata = 'data:image/png;base64,' . base64_encode( $pngdata = 'data:image/png;base64,' . base64_encode(
$vh->generate($hmac) $vh->generate($hmac)
); );
} }
if ($pngdata != '') { if (!empty($pngdata)) {
if (!array_key_exists('meta', $data)) { if (!array_key_exists('meta', $data)) {
$data['meta'] = array(); $data['meta'] = array();
} }

View File

@@ -150,7 +150,7 @@ class Paste extends AbstractModel
$comment = new Comment($this->_conf, $this->_store); $comment = new Comment($this->_conf, $this->_store);
$comment->setPaste($this); $comment->setPaste($this);
$comment->setParentId($parentId); $comment->setParentId($parentId);
if ($commentId !== '') { if (!empty($commentId)) {
$comment->setId($commentId); $comment->setId($commentId);
} }
return $comment; return $comment;

View File

@@ -73,7 +73,7 @@ class TrafficLimiter extends AbstractPersistence
self::setExempted($conf->getKey('exempted', 'traffic')); self::setExempted($conf->getKey('exempted', 'traffic'));
self::setLimit($conf->getKey('limit', 'traffic')); self::setLimit($conf->getKey('limit', 'traffic'));
if (($option = $conf->getKey('header', 'traffic')) !== '') { if (!empty($option = $conf->getKey('header', 'traffic'))) {
$httpHeader = 'HTTP_' . $option; $httpHeader = 'HTTP_' . $option;
if (array_key_exists($httpHeader, $_SERVER) && !empty($_SERVER[$httpHeader])) { if (array_key_exists($httpHeader, $_SERVER) && !empty($_SERVER[$httpHeader])) {
self::$_ipKey = $httpHeader; self::$_ipKey = $httpHeader;

View File

@@ -55,7 +55,7 @@ abstract class AbstractProxy
} }
if (!str_starts_with($link, $conf->getKey('basepath') . '?') || if (!str_starts_with($link, $conf->getKey('basepath') . '?') ||
parse_url($link, PHP_URL_HOST) != parse_url($conf->getKey('basepath'), PHP_URL_HOST) parse_url($link, PHP_URL_HOST) !== parse_url($conf->getKey('basepath'), PHP_URL_HOST)
) { ) {
$this->_error = 'Trying to shorten a URL that isn\'t pointing at our instance.'; $this->_error = 'Trying to shorten a URL that isn\'t pointing at our instance.';
return; return;

View File

@@ -65,7 +65,7 @@ class YourlsProxy extends AbstractProxy
*/ */
protected function _extractShortUrl(array $data): ?string protected function _extractShortUrl(array $data): ?string
{ {
if (($data['statusCode'] ?? 0) == 200) { if (($data['statusCode'] ?? 0) === 200) {
return $data['shorturl'] ?? 0; return $data['shorturl'] ?? 0;
} }
return null; return null;

View File

@@ -141,7 +141,7 @@ class Request
if (array_key_exists('pasteid', $this->_params) && !empty($this->_params['pasteid'])) { if (array_key_exists('pasteid', $this->_params) && !empty($this->_params['pasteid'])) {
if (array_key_exists('deletetoken', $this->_params) && !empty($this->_params['deletetoken'])) { if (array_key_exists('deletetoken', $this->_params) && !empty($this->_params['deletetoken'])) {
$this->_operation = 'delete'; $this->_operation = 'delete';
} elseif ($this->_operation != 'create') { } elseif ($this->_operation !== 'create') {
$this->_operation = 'read'; $this->_operation = 'read';
} }
} elseif (array_key_exists('jsonld', $this->_params) && !empty($this->_params['jsonld'])) { } elseif (array_key_exists('jsonld', $this->_params) && !empty($this->_params['jsonld'])) {
@@ -187,7 +187,7 @@ class Request
$data['meta'] = $meta; $data['meta'] = $meta;
} }
foreach ($required_keys as $key) { foreach ($required_keys as $key) {
$data[$key] = $this->getParam($key, $key == 'v' ? 1 : ''); $data[$key] = $this->getParam($key, $key === 'v' ? 1 : '');
} }
// forcing a cast to int or float // forcing a cast to int or float
$data['v'] = $data['v'] + 0; $data['v'] = $data['v'] + 0;
@@ -266,7 +266,7 @@ class Request
// simple cases // simple cases
if ( if (
($_SERVER['HTTP_X_REQUESTED_WITH'] ?? '') == 'JSONHttpRequest' || ($_SERVER['HTTP_X_REQUESTED_WITH'] ?? '') === 'JSONHttpRequest' ||
( (
str_contains($acceptHeader, self::MIME_JSON) && str_contains($acceptHeader, self::MIME_JSON) &&
!str_contains($acceptHeader, self::MIME_HTML) && !str_contains($acceptHeader, self::MIME_HTML) &&

View File

@@ -103,7 +103,7 @@ class Vizhash16x16
// First, create an image with a specific gradient background. // First, create an image with a specific gradient background.
$op = 'v'; $op = 'v';
if (($this->getInt() % 2) == 0) { if (($this->getInt() % 2) === 0) {
$op = 'h'; $op = 'h';
} }
$image = $this->degrade($image, $op, array($r0, $g0, $b0), array(0, 0, 0)); $image = $this->degrade($image, $op, array($r0, $g0, $b0), array(0, 0, 0));
@@ -179,7 +179,7 @@ class Vizhash16x16
*/ */
private function degrade($img, $direction, $color1, $color2) private function degrade($img, $direction, $color1, $color2)
{ {
if ($direction == 'h') { if ($direction === 'h') {
$size = imagesx($img); $size = imagesx($img);
$sizeinv = imagesy($img); $sizeinv = imagesy($img);
} else { } else {
@@ -195,7 +195,7 @@ class Vizhash16x16
$r = $color1[0] + ((int) $diffs[0] * $i); $r = $color1[0] + ((int) $diffs[0] * $i);
$g = $color1[1] + ((int) $diffs[1] * $i); $g = $color1[1] + ((int) $diffs[1] * $i);
$b = $color1[2] + ((int) $diffs[2] * $i); $b = $color1[2] + ((int) $diffs[2] * $i);
if ($direction == 'h') { if ($direction === 'h') {
imageline($img, $i, 0, $i, $sizeinv, imagecolorallocate($img, $r, $g, $b)); imageline($img, $i, 0, $i, $sizeinv, imagecolorallocate($img, $r, $g, $b));
} else { } else {
imageline($img, 0, $i, $sizeinv, $i, imagecolorallocate($img, $r, $g, $b)); imageline($img, 0, $i, $sizeinv, $i, imagecolorallocate($img, $r, $g, $b));

View File

@@ -249,7 +249,7 @@ endif;
foreach ($EXPIRE as $key => $value) : foreach ($EXPIRE as $key => $value) :
?> ?>
<option value="<?php echo $key; ?>"<?php <option value="<?php echo $key; ?>"<?php
if ($key == $EXPIREDEFAULT) : if ($key === $EXPIREDEFAULT) :
?> selected="selected"<?php ?> selected="selected"<?php
endif; endif;
?>><?php echo $value; ?></option> ?>><?php echo $value; ?></option>
@@ -327,7 +327,7 @@ if ($isCpct) :
foreach ($FORMATTER as $key => $value) : foreach ($FORMATTER as $key => $value) :
?> ?>
<option value="<?php echo $key; ?>"<?php <option value="<?php echo $key; ?>"<?php
if ($key == $FORMATTERDEFAULT) : if ($key === $FORMATTERDEFAULT) :
?> selected="selected"<?php ?> selected="selected"<?php
endif; endif;
?>><?php echo $value; ?></option> ?>><?php echo $value; ?></option>
@@ -412,7 +412,7 @@ if (!$isCpct) :
foreach ($FORMATTER as $key => $value) : foreach ($FORMATTER as $key => $value) :
?> ?>
<option value="<?php echo $key; ?>"<?php <option value="<?php echo $key; ?>"<?php
if ($key == $FORMATTERDEFAULT) : if ($key === $FORMATTERDEFAULT) :
?> selected="selected"<?php ?> selected="selected"<?php
endif; endif;
?>><?php echo $value; ?></option> ?>><?php echo $value; ?></option>

View File

@@ -206,7 +206,7 @@ endif;
foreach ($EXPIRE as $key => $value) : foreach ($EXPIRE as $key => $value) :
?> ?>
<option value="<?php echo $key; ?>"<?php <option value="<?php echo $key; ?>"<?php
if ($key == $EXPIREDEFAULT) : if ($key === $EXPIREDEFAULT) :
?> selected="selected"<?php ?> selected="selected"<?php
endif; endif;
?>><?php echo $value; ?></option> ?>><?php echo $value; ?></option>
@@ -287,7 +287,7 @@ endif;
foreach ($FORMATTER as $key => $value) : foreach ($FORMATTER as $key => $value) :
?> ?>
<option value="<?php echo $key; ?>"<?php <option value="<?php echo $key; ?>"<?php
if ($key == $FORMATTERDEFAULT) : if ($key === $FORMATTERDEFAULT) :
?> selected="selected"<?php ?> selected="selected"<?php
endif; endif;
?>><?php echo $value; ?></option> ?>><?php echo $value; ?></option>

View File

@@ -212,20 +212,15 @@ class Helper
public static function rmDir($path): void public static function rmDir($path): void
{ {
if (is_dir($path)) { if (is_dir($path)) {
$path .= DIRECTORY_SEPARATOR; foreach (new DirectoryIterator($path) as $file) {
$dir = dir($path); if ($file->isFile()) {
while (false !== ($file = $dir->read())) { if (!unlink($file->getPathname())) {
if ($file != '.' && $file != '..') { throw new Exception('Error deleting file "' . $file->getPathname() . '".');
if (is_dir($path . $file)) {
self::rmDir($path . $file);
} elseif (is_file($path . $file)) {
if (!unlink($path . $file)) {
throw new Exception('Error deleting file "' . $path . $file . '".');
}
} }
} elseif ($file->isDir() && !$file->isDot()) {
self::rmDir($file->getPathname());
} }
} }
$dir->close();
if (!rmdir($path)) { if (!rmdir($path)) {
throw new Exception('Error deleting directory "' . $path . '".'); throw new Exception('Error deleting directory "' . $path . '".');
} }
@@ -361,7 +356,7 @@ class Helper
file_get_contents($file) file_get_contents($file)
); );
file_put_contents($file, $content); file_put_contents($file, $content);
if ($counter != count(self::$hashes)) { if ($counter !== count(self::$hashes)) {
throw new Exception('Mismatch between ' . count(self::$hashes) . ' found js files and ' . $counter . ' SRI hashes in lib/Configuration.php, please update lib/Configuration.php to match the list of js files.'); throw new Exception('Mismatch between ' . count(self::$hashes) . ' found js files and ' . $counter . ' SRI hashes in lib/Configuration.php, please update lib/Configuration.php to match the list of js files.');
} }
} }
@@ -404,7 +399,7 @@ class BucketStub extends Bucket
public function upload($data, array $options = array()) public function upload($data, array $options = array())
{ {
if (!is_string($data) || !key_exists('name', $options)) { if (!is_string($data) || !array_key_exists('name', $options)) {
throw new BadMethodCallException('not supported by this stub'); throw new BadMethodCallException('not supported by this stub');
} }
@@ -432,21 +427,17 @@ class BucketStub extends Bucket
public function object($name, array $options = array()) public function object($name, array $options = array())
{ {
if (key_exists($name, $this->_objects)) { return $this->_objects[$name] ?? new StorageObjectStub($this->_connection, $name, $this, null, $options);
return $this->_objects[$name];
} else {
return new StorageObjectStub($this->_connection, $name, $this, null, $options);
}
} }
public function objects(array $options = array()) public function objects(array $options = array())
{ {
$prefix = key_exists('prefix', $options) ? $options['prefix'] : ''; $prefix = $options['prefix'] ?? '';
return new CallbackFilterIterator( return new CallbackFilterIterator(
new ArrayIterator($this->_objects), new ArrayIterator($this->_objects),
function ($current, $key, $iterator) use ($prefix) { function ($current, $key, $iterator) use ($prefix) {
return substr($key, 0, strlen($prefix)) == $prefix; return substr($key, 0, strlen($prefix)) === $prefix;
} }
); );
} }
@@ -563,7 +554,7 @@ class StorageObjectStub extends StorageObject
public function exists(array $options = array()) public function exists(array $options = array())
{ {
return key_exists($this->_name, $this->_bucket->_objects); return array_key_exists($this->_name, $this->_bucket->_objects);
} }
/** /**
@@ -571,7 +562,7 @@ class StorageObjectStub extends StorageObject
*/ */
public function delete(array $options = array()) public function delete(array $options = array())
{ {
if (key_exists($this->_name, $this->_bucket->_objects)) { if (array_key_exists($this->_name, $this->_bucket->_objects)) {
unset($this->_bucket->_objects[$this->_name]); unset($this->_bucket->_objects[$this->_name]);
} else { } else {
throw new NotFoundException('key ' . $this->_name . ' not found.'); throw new NotFoundException('key ' . $this->_name . ' not found.');
@@ -647,7 +638,7 @@ class StorageObjectStub extends StorageObject
public function info(array $options = array()) public function info(array $options = array())
{ {
return key_exists('metadata',$this->_info) ? $this->_info['metadata'] : array(); return $this->_info['metadata'] ?? array();
} }
public function reload(array $options = array()) public function reload(array $options = array())
@@ -884,7 +875,7 @@ class StorageClientStub extends StorageClient
public function bucket($name, $userProject = false, array $config = array()) public function bucket($name, $userProject = false, array $config = array())
{ {
if (!key_exists($name, self::$_buckets)) { if (!array_key_exists($name, self::$_buckets)) {
self::$_buckets[$name] = new BucketStub($this->_connection, $name, array(), $this); self::$_buckets[$name] = new BucketStub($this->_connection, $name, array(), $this);
} }
return self::$_buckets[$name]; return self::$_buckets[$name];
@@ -895,7 +886,7 @@ class StorageClientStub extends StorageClient
*/ */
public function deleteBucket($name) public function deleteBucket($name)
{ {
if (key_exists($name, self::$_buckets)) { if (array_key_exists($name, self::$_buckets)) {
unset(self::$_buckets[$name]); unset(self::$_buckets[$name]);
} else { } else {
throw new NotFoundException(); throw new NotFoundException();
@@ -949,7 +940,7 @@ class StorageClientStub extends StorageClient
public function createBucket($name, array $options = array()) public function createBucket($name, array $options = array())
{ {
if (key_exists($name, self::$_buckets)) { if (array_key_exists($name, self::$_buckets)) {
throw new BadRequestException('already exists'); throw new BadRequestException('already exists');
} }
$b = new BucketStub($this->_connection, $name, array(), $this); $b = new BucketStub($this->_connection, $name, array(), $this);