mirror of
https://github.com/PrivateBin/PrivateBin.git
synced 2026-01-23 02:35:23 +00:00
apply null coalescing operator
This commit is contained in:
parent
c8643f187e
commit
69e5fc1b05
7 changed files with 19 additions and 40 deletions
|
|
@ -370,10 +370,7 @@ class Filesystem extends AbstractData
|
|||
foreach ($files as $pasteid) {
|
||||
if ($this->exists($pasteid)) {
|
||||
$data = $this->read($pasteid);
|
||||
if (
|
||||
array_key_exists('expire_date', $data['meta']) &&
|
||||
$data['meta']['expire_date'] < $time
|
||||
) {
|
||||
if (($data['meta']['expire_date'] ?? $time) < $time) {
|
||||
$pastes[] = $pasteid;
|
||||
if (++$count >= $batchsize) {
|
||||
break;
|
||||
|
|
|
|||
|
|
@ -107,7 +107,7 @@ class GoogleCloudStorage extends AbstractData
|
|||
*/
|
||||
private function _upload($key, &$payload)
|
||||
{
|
||||
$metadata = array_key_exists('meta', $payload) ? $payload['meta'] : array();
|
||||
$metadata = $payload['meta'] ?? array();
|
||||
unset($metadata['salt']);
|
||||
foreach ($metadata as $k => $v) {
|
||||
$metadata[$k] = strval($v);
|
||||
|
|
|
|||
|
|
@ -165,7 +165,7 @@ class S3Storage extends AbstractData
|
|||
*/
|
||||
private function _upload($key, &$payload)
|
||||
{
|
||||
$metadata = array_key_exists('meta', $payload) ? $payload['meta'] : array();
|
||||
$metadata = $payload['meta'] ?? array();
|
||||
unset($metadata['salt']);
|
||||
foreach ($metadata as $k => $v) {
|
||||
$metadata[$k] = strval($v);
|
||||
|
|
|
|||
|
|
@ -73,10 +73,7 @@ class Paste extends AbstractModel
|
|||
}
|
||||
|
||||
// check if non-expired burn after reading paste needs to be deleted
|
||||
if (
|
||||
array_key_exists('adata', $data) &&
|
||||
$data['adata'][self::ADATA_BURN_AFTER_READING] === 1
|
||||
) {
|
||||
if (($data['adata'][self::ADATA_BURN_AFTER_READING] ?? 0) === 1) {
|
||||
$this->delete();
|
||||
}
|
||||
|
||||
|
|
@ -207,8 +204,7 @@ class Paste extends AbstractModel
|
|||
if (!array_key_exists('adata', $this->_data) && !array_key_exists('data', $this->_data)) {
|
||||
$this->get();
|
||||
}
|
||||
return array_key_exists('adata', $this->_data) &&
|
||||
$this->_data['adata'][self::ADATA_OPEN_DISCUSSION] === 1;
|
||||
return ($this->_data['adata'][self::ADATA_OPEN_DISCUSSION] ?? 0) === 1;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -222,12 +218,9 @@ class Paste extends AbstractModel
|
|||
$expiration = $data['meta']['expire'] ?? 0;
|
||||
unset($data['meta']['expire']);
|
||||
$expire_options = $this->_conf->getSection('expire_options');
|
||||
if (array_key_exists($expiration, $expire_options)) {
|
||||
$expire = $expire_options[$expiration];
|
||||
} else {
|
||||
// using getKey() to ensure a default value is present
|
||||
$expire = $this->_conf->getKey($this->_conf->getKey('default', 'expire'), 'expire_options');
|
||||
}
|
||||
// using getKey() to ensure a default value is present
|
||||
$expire = $expire_options[$expiration] ??
|
||||
$this->_conf->getKey($this->_conf->getKey('default', 'expire'), 'expire_options');
|
||||
if ($expire > 0) {
|
||||
$data['meta']['expire_date'] = time() + $expire;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -71,11 +71,6 @@ class ShlinkProxy extends AbstractProxy
|
|||
*/
|
||||
protected function _extractShortUrl(array $data): ?string
|
||||
{
|
||||
if (
|
||||
array_key_exists('shortUrl', $data)
|
||||
) {
|
||||
return $data['shortUrl'];
|
||||
}
|
||||
return null;
|
||||
return $data['shortUrl'] ?? null;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -65,12 +65,8 @@ class YourlsProxy extends AbstractProxy
|
|||
*/
|
||||
protected function _extractShortUrl(array $data): ?string
|
||||
{
|
||||
if (
|
||||
array_key_exists('statusCode', $data) &&
|
||||
$data['statusCode'] == 200 &&
|
||||
array_key_exists('shorturl', $data)
|
||||
) {
|
||||
return $data['shorturl'];
|
||||
if (($data['statusCode'] ?? 0) == 200) {
|
||||
return $data['shorturl'] ?? 0;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -104,7 +104,7 @@ class Request
|
|||
$this->_isJsonApi = $this->_detectJsonRequest();
|
||||
|
||||
// parse parameters, depending on request type
|
||||
switch (array_key_exists('REQUEST_METHOD', $_SERVER) ? $_SERVER['REQUEST_METHOD'] : 'GET') {
|
||||
switch ($_SERVER['REQUEST_METHOD'] ?? 'GET') {
|
||||
case 'DELETE':
|
||||
case 'PUT':
|
||||
case 'POST':
|
||||
|
|
@ -204,8 +204,7 @@ class Request
|
|||
*/
|
||||
public function getParam($param, $default = '')
|
||||
{
|
||||
return array_key_exists($param, $this->_params) ?
|
||||
$this->_params[$param] : $default;
|
||||
return $this->_params[$param] ?? $default;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -263,23 +262,22 @@ class Request
|
|||
*/
|
||||
private function _detectJsonRequest()
|
||||
{
|
||||
$hasAcceptHeader = array_key_exists('HTTP_ACCEPT', $_SERVER);
|
||||
$acceptHeader = $hasAcceptHeader ? $_SERVER['HTTP_ACCEPT'] : '';
|
||||
$acceptHeader = $_SERVER['HTTP_ACCEPT'] ?? '';
|
||||
|
||||
// simple cases
|
||||
if (
|
||||
(array_key_exists('HTTP_X_REQUESTED_WITH', $_SERVER) &&
|
||||
$_SERVER['HTTP_X_REQUESTED_WITH'] == 'JSONHttpRequest') ||
|
||||
($hasAcceptHeader &&
|
||||
($_SERVER['HTTP_X_REQUESTED_WITH'] ?? '' ) == 'JSONHttpRequest' ||
|
||||
(
|
||||
str_contains($acceptHeader, self::MIME_JSON) &&
|
||||
!str_contains($acceptHeader, self::MIME_HTML) &&
|
||||
!str_contains($acceptHeader, self::MIME_XHTML))
|
||||
!str_contains($acceptHeader, self::MIME_XHTML)
|
||||
)
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// advanced case: media type negotiation
|
||||
if ($hasAcceptHeader) {
|
||||
if (!empty($acceptHeader)) {
|
||||
$mediaTypes = array();
|
||||
foreach (explode(',', trim($acceptHeader)) as $mediaTypeRange) {
|
||||
if (preg_match(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue