Convert isset ternary to null coalescing operator

Signed-off-by: Hamid Dehnavi <hamid.dev.pro@gmail.com>
pull/39224/head
Hamid Dehnavi 11 months ago
parent 45cac16432
commit ea06cf2f39

@ -54,9 +54,9 @@ class VersionParser {
// Count the amount of =, if it is one then it's either maximum or minimum // Count the amount of =, if it is one then it's either maximum or minimum
// version. If it is two then it is maximum and minimum. // version. If it is two then it is maximum and minimum.
$versionElements = explode(' ', $versionSpec); $versionElements = explode(' ', $versionSpec);
$firstVersion = isset($versionElements[0]) ? $versionElements[0] : ''; $firstVersion = $versionElements[0] ?? '';
$firstVersionNumber = substr($firstVersion, 2); $firstVersionNumber = substr($firstVersion, 2);
$secondVersion = isset($versionElements[1]) ? $versionElements[1] : ''; $secondVersion = $versionElements[1] ?? '';
$secondVersionNumber = substr($secondVersion, 2); $secondVersionNumber = substr($secondVersion, 2);
switch (count($versionElements)) { switch (count($versionElements)) {

@ -373,7 +373,7 @@ class AppConfig implements IAppConfig {
} else { } else {
$appIds = $this->getApps(); $appIds = $this->getApps();
$values = array_map(function ($appId) use ($key) { $values = array_map(function ($appId) use ($key) {
return isset($this->cache[$appId][$key]) ? $this->cache[$appId][$key] : null; return $this->cache[$appId][$key] ?? null;
}, $appIds); }, $appIds);
$result = array_combine($appIds, $values); $result = array_combine($appIds, $values);

@ -193,9 +193,7 @@ class Request implements \ArrayAccess, \Countable, IRequest {
*/ */
#[\ReturnTypeWillChange] #[\ReturnTypeWillChange]
public function offsetGet($offset) { public function offsetGet($offset) {
return isset($this->items['parameters'][$offset]) return $this->items['parameters'][$offset] ?? null;
? $this->items['parameters'][$offset]
: null;
} }
/** /**
@ -255,9 +253,7 @@ class Request implements \ArrayAccess, \Countable, IRequest {
case 'cookies': case 'cookies':
case 'urlParams': case 'urlParams':
case 'method': case 'method':
return isset($this->items[$name]) return $this->items[$name] ?? null;
? $this->items[$name]
: null;
case 'parameters': case 'parameters':
case 'params': case 'params':
if ($this->isPutStreamContent()) { if ($this->isPutStreamContent()) {

@ -139,7 +139,7 @@ class ConnectionFactory {
$additionalConnectionParams = array_merge($additionalConnectionParams, $additionalConnectionParams['driverOptions']); $additionalConnectionParams = array_merge($additionalConnectionParams, $additionalConnectionParams['driverOptions']);
} }
$host = $additionalConnectionParams['host']; $host = $additionalConnectionParams['host'];
$port = isset($additionalConnectionParams['port']) ? $additionalConnectionParams['port'] : null; $port = $additionalConnectionParams['port'] ?? null;
$dbName = $additionalConnectionParams['dbname']; $dbName = $additionalConnectionParams['dbname'];
// we set the connect string as dbname and unset the host to coerce doctrine into using it as connect string // we set the connect string as dbname and unset the host to coerce doctrine into using it as connect string

@ -439,7 +439,7 @@ class Scanner extends BasicEmitter implements IScanner {
$childQueue = []; $childQueue = [];
$newChildNames = []; $newChildNames = [];
foreach ($newChildren as $fileMeta) { foreach ($newChildren as $fileMeta) {
$permissions = isset($fileMeta['scan_permissions']) ? $fileMeta['scan_permissions'] : $fileMeta['permissions']; $permissions = $fileMeta['scan_permissions'] ?? $fileMeta['permissions'];
if ($permissions === 0) { if ($permissions === 0) {
continue; continue;
} }
@ -456,7 +456,7 @@ class Scanner extends BasicEmitter implements IScanner {
$newChildNames[] = $file; $newChildNames[] = $file;
$child = $path ? $path . '/' . $file : $file; $child = $path ? $path . '/' . $file : $file;
try { try {
$existingData = isset($existingChildren[$file]) ? $existingChildren[$file] : false; $existingData = $existingChildren[$file] ?? false;
$data = $this->scanFile($child, $reuse, $folderId, $existingData, $lock, $fileMeta); $data = $this->scanFile($child, $reuse, $folderId, $existingData, $lock, $fileMeta);
if ($data) { if ($data) {
if ($data['mimetype'] === 'httpd/unix-directory' && $recursive === self::SCAN_RECURSIVE) { if ($data['mimetype'] === 'httpd/unix-directory' && $recursive === self::SCAN_RECURSIVE) {

@ -238,7 +238,7 @@ class UserMountCache implements IUserMountCache {
$row['mount_point'], $row['mount_point'],
$row['mount_provider_class'] ?? '', $row['mount_provider_class'] ?? '',
$mount_id, $mount_id,
isset($row['path']) ? $row['path'] : '', $row['path'] ?? '',
); );
} }

@ -272,7 +272,7 @@ class MountPoint implements IMountPoint {
* @return mixed * @return mixed
*/ */
public function getOption($name, $default) { public function getOption($name, $default) {
return isset($this->mountOptions[$name]) ? $this->mountOptions[$name] : $default; return $this->mountOptions[$name] ?? $default;
} }
/** /**

@ -122,7 +122,7 @@ class ObjectHomeMountProvider implements IHomeMountProvider {
$config['arguments']['bucket'] = ''; $config['arguments']['bucket'] = '';
} }
$mapper = new \OC\Files\ObjectStore\Mapper($user, $this->config); $mapper = new \OC\Files\ObjectStore\Mapper($user, $this->config);
$numBuckets = isset($config['arguments']['num_buckets']) ? $config['arguments']['num_buckets'] : 64; $numBuckets = $config['arguments']['num_buckets'] ?? 64;
$config['arguments']['bucket'] .= $mapper->getBucket($numBuckets); $config['arguments']['bucket'] .= $mapper->getBucket($numBuckets);
$this->config->setUserValue($user->getUID(), 'homeobjectstore', 'bucket', $config['arguments']['bucket']); $this->config->setUserValue($user->getUID(), 'homeobjectstore', 'bucket', $config['arguments']['bucket']);

@ -128,7 +128,7 @@ trait S3ConnectionTrait {
); );
$options = [ $options = [
'version' => isset($this->params['version']) ? $this->params['version'] : 'latest', 'version' => $this->params['version'] ?? 'latest',
'credentials' => $provider, 'credentials' => $provider,
'endpoint' => $base_url, 'endpoint' => $base_url,
'region' => $this->params['region'], 'region' => $this->params['region'],

@ -601,7 +601,7 @@ abstract class Common implements Storage, ILockingStorage, IWriteStreamStorage {
* @return mixed * @return mixed
*/ */
public function getMountOption($name, $default = null) { public function getMountOption($name, $default = null) {
return isset($this->mountOptions[$name]) ? $this->mountOptions[$name] : $default; return $this->mountOptions[$name] ?? $default;
} }
/** /**

@ -140,7 +140,7 @@ class PermissionsMask extends Wrapper {
$data = parent::getMetaData($path); $data = parent::getMetaData($path);
if ($data && isset($data['permissions'])) { if ($data && isset($data['permissions'])) {
$data['scan_permissions'] = isset($data['scan_permissions']) ? $data['scan_permissions'] : $data['permissions']; $data['scan_permissions'] = $data['scan_permissions'] ?? $data['permissions'];
$data['permissions'] &= $this->mask; $data['permissions'] &= $this->mask;
} }
return $data; return $data;
@ -155,7 +155,7 @@ class PermissionsMask extends Wrapper {
public function getDirectoryContent($directory): \Traversable { public function getDirectoryContent($directory): \Traversable {
foreach ($this->getWrapperStorage()->getDirectoryContent($directory) as $data) { foreach ($this->getWrapperStorage()->getDirectoryContent($directory) as $data) {
$data['scan_permissions'] = isset($data['scan_permissions']) ? $data['scan_permissions'] : $data['permissions']; $data['scan_permissions'] = $data['scan_permissions'] ?? $data['permissions'];
$data['permissions'] &= $this->mask; $data['permissions'] &= $this->mask;
yield $data; yield $data;

@ -101,7 +101,7 @@ class NavigationManager implements INavigationManager {
} }
$id = $entry['id']; $id = $entry['id'];
$entry['unread'] = isset($this->unreadCounters[$id]) ? $this->unreadCounters[$id] : 0; $entry['unread'] = $this->unreadCounters[$id] ?? 0;
$this->entries[$id] = $entry; $this->entries[$id] = $entry;
} }
@ -313,7 +313,7 @@ class NavigationManager implements INavigationManager {
if (!isset($nav['route']) && $nav['type'] !== 'settings') { if (!isset($nav['route']) && $nav['type'] !== 'settings') {
continue; continue;
} }
$role = isset($nav['@attributes']['role']) ? $nav['@attributes']['role'] : 'all'; $role = $nav['@attributes']['role'] ?? 'all';
if ($role === 'admin' && !$this->isAdmin()) { if ($role === 'admin' && !$this->isAdmin()) {
continue; continue;
} }
@ -322,7 +322,7 @@ class NavigationManager implements INavigationManager {
$order = $customOrders[$app][$key] ?? $nav['order'] ?? 100; $order = $customOrders[$app][$key] ?? $nav['order'] ?? 100;
$type = $nav['type']; $type = $nav['type'];
$route = !empty($nav['route']) ? $this->urlGenerator->linkToRoute($nav['route']) : ''; $route = !empty($nav['route']) ? $this->urlGenerator->linkToRoute($nav['route']) : '';
$icon = isset($nav['icon']) ? $nav['icon'] : 'app.svg'; $icon = $nav['icon'] ?? 'app.svg';
foreach ([$icon, "$app.svg"] as $i) { foreach ([$icon, "$app.svg"] as $i) {
try { try {
$icon = $this->urlGenerator->imagePath($app, $i); $icon = $this->urlGenerator->imagePath($app, $i);

@ -92,7 +92,7 @@ class User implements IUser {
* @return string * @return string
*/ */
public function getTwitter() { public function getTwitter() {
return isset($this->data['twitter']) ? $this->data['twitter'] : ''; return $this->data['twitter'] ?? '';
} }
/** /**

@ -88,7 +88,7 @@ abstract class AbstractDatabase {
$dbName = $config['dbname']; $dbName = $config['dbname'];
$dbHost = !empty($config['dbhost']) ? $config['dbhost'] : 'localhost'; $dbHost = !empty($config['dbhost']) ? $config['dbhost'] : 'localhost';
$dbPort = !empty($config['dbport']) ? $config['dbport'] : ''; $dbPort = !empty($config['dbport']) ? $config['dbport'] : '';
$dbTablePrefix = isset($config['dbtableprefix']) ? $config['dbtableprefix'] : 'oc_'; $dbTablePrefix = $config['dbtableprefix'] ?? 'oc_';
$createUserConfig = $this->config->getValue("setup_create_db_user", true); $createUserConfig = $this->config->getValue("setup_create_db_user", true);
// accept `false` both as bool and string, since setting config values from env will result in a string // accept `false` both as bool and string, since setting config values from env will result in a string

@ -1364,7 +1364,7 @@ class DefaultShareProvider implements IShareProvider {
$type = (int)$row['share_type']; $type = (int)$row['share_type'];
if ($type === IShare::TYPE_USER) { if ($type === IShare::TYPE_USER) {
$uid = $row['share_with']; $uid = $row['share_with'];
$users[$uid] = isset($users[$uid]) ? $users[$uid] : []; $users[$uid] = $users[$uid] ?? [];
$users[$uid][$row['id']] = $row; $users[$uid][$row['id']] = $row;
} elseif ($type === IShare::TYPE_GROUP) { } elseif ($type === IShare::TYPE_GROUP) {
$gid = $row['share_with']; $gid = $row['share_with'];
@ -1377,14 +1377,14 @@ class DefaultShareProvider implements IShareProvider {
$userList = $group->getUsers(); $userList = $group->getUsers();
foreach ($userList as $user) { foreach ($userList as $user) {
$uid = $user->getUID(); $uid = $user->getUID();
$users[$uid] = isset($users[$uid]) ? $users[$uid] : []; $users[$uid] = $users[$uid] ?? [];
$users[$uid][$row['id']] = $row; $users[$uid][$row['id']] = $row;
} }
} elseif ($type === IShare::TYPE_LINK) { } elseif ($type === IShare::TYPE_LINK) {
$link = true; $link = true;
} elseif ($type === IShare::TYPE_USERGROUP && $currentAccess === true) { } elseif ($type === IShare::TYPE_USERGROUP && $currentAccess === true) {
$uid = $row['share_with']; $uid = $row['share_with'];
$users[$uid] = isset($users[$uid]) ? $users[$uid] : []; $users[$uid] = $users[$uid] ?? [];
$users[$uid][$row['id']] = $row; $users[$uid][$row['id']] = $row;
} }
} }

@ -390,7 +390,7 @@ class OC_App {
public static function getAppVersionByPath(string $path): string { public static function getAppVersionByPath(string $path): string {
$infoFile = $path . '/appinfo/info.xml'; $infoFile = $path . '/appinfo/info.xml';
$appData = \OC::$server->getAppManager()->getAppInfo($infoFile, true); $appData = \OC::$server->getAppManager()->getAppInfo($infoFile, true);
return isset($appData['version']) ? $appData['version'] : ''; return $appData['version'] ?? '';
} }
/** /**

Loading…
Cancel
Save