Skip to content

Commit

Permalink
Convert isset ternary to null coalescing operator
Browse files Browse the repository at this point in the history
Signed-off-by: Hamid Dehnavi <[email protected]>
  • Loading branch information
shdehnavi committed Jul 7, 2023
1 parent 9bf6911 commit 3f7ae91
Show file tree
Hide file tree
Showing 18 changed files with 30 additions and 34 deletions.
4 changes: 2 additions & 2 deletions lib/private/App/AppStore/Version/VersionParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ public function getVersion($versionSpec) {
// 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.
$versionElements = explode(' ', $versionSpec);
$firstVersion = isset($versionElements[0]) ? $versionElements[0] : '';
$firstVersion = $versionElements[0] ?? '';
$firstVersionNumber = substr($firstVersion, 2);
$secondVersion = isset($versionElements[1]) ? $versionElements[1] : '';
$secondVersion = $versionElements[1] ?? '';
$secondVersionNumber = substr($secondVersion, 2);

switch (count($versionElements)) {
Expand Down
2 changes: 1 addition & 1 deletion lib/private/AppConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ public function getValues($app, $key) {
} else {
$appIds = $this->getApps();
$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);
$result = array_combine($appIds, $values);

Expand Down
8 changes: 2 additions & 6 deletions lib/private/AppFramework/Http/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -193,9 +193,7 @@ public function offsetExists($offset): bool {
*/
#[\ReturnTypeWillChange]
public function offsetGet($offset) {
return isset($this->items['parameters'][$offset])
? $this->items['parameters'][$offset]
: null;
return $this->items['parameters'][$offset] ?? null;
}

/**
Expand Down Expand Up @@ -255,9 +253,7 @@ public function __get($name) {
case 'cookies':
case 'urlParams':
case 'method':
return isset($this->items[$name])
? $this->items[$name]
: null;
return $this->items[$name] ?? null;
case 'parameters':
case 'params':
if ($this->isPutStreamContent()) {
Expand Down
2 changes: 1 addition & 1 deletion lib/private/Collaboration/Collaborators/LookupPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public function search($search, $limit, $offset, ISearchResult $searchResult) {
if ($this->currentUserRemote === $remote) {
continue;
}
$name = isset($lookup['name']['value']) ? $lookup['name']['value'] : '';
$name = $lookup['name']['value'] ?? '';
$label = empty($name) ? $lookup['federationId'] : $name . ' (' . $lookup['federationId'] . ')';
$result[] = [
'label' => $label,
Expand Down
2 changes: 1 addition & 1 deletion lib/private/DB/ConnectionFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ public function getConnection($type, $additionalConnectionParams) {
$additionalConnectionParams = array_merge($additionalConnectionParams, $additionalConnectionParams['driverOptions']);
}
$host = $additionalConnectionParams['host'];
$port = isset($additionalConnectionParams['port']) ? $additionalConnectionParams['port'] : null;
$port = $additionalConnectionParams['port'] ?? null;
$dbName = $additionalConnectionParams['dbname'];

// we set the connect string as dbname and unset the host to coerce doctrine into using it as connect string
Expand Down
4 changes: 2 additions & 2 deletions lib/private/Files/Cache/Scanner.php
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ private function handleChildren($path, $recursive, $reuse, $folderId, $lock, &$s
$childQueue = [];
$newChildNames = [];
foreach ($newChildren as $fileMeta) {
$permissions = isset($fileMeta['scan_permissions']) ? $fileMeta['scan_permissions'] : $fileMeta['permissions'];
$permissions = $fileMeta['scan_permissions'] ?? $fileMeta['permissions'];
if ($permissions === 0) {
continue;
}
Expand All @@ -453,7 +453,7 @@ private function handleChildren($path, $recursive, $reuse, $folderId, $lock, &$s
$newChildNames[] = $file;
$child = $path ? $path . '/' . $file : $file;
try {
$existingData = isset($existingChildren[$file]) ? $existingChildren[$file] : false;
$existingData = $existingChildren[$file] ?? false;
$data = $this->scanFile($child, $reuse, $folderId, $existingData, $lock, $fileMeta);
if ($data) {
if ($data['mimetype'] === 'httpd/unix-directory' && $recursive === self::SCAN_RECURSIVE) {
Expand Down
2 changes: 1 addition & 1 deletion lib/private/Files/Config/UserMountCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ private function dbRowToMountInfo(array $row) {
$row['mount_point'],
$row['mount_provider_class'] ?? '',
$mount_id,
isset($row['path']) ? $row['path'] : '',
$row['path'] ?? '',
);
}

Expand Down
2 changes: 1 addition & 1 deletion lib/private/Files/Mount/MountPoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ public function wrapStorage($wrapper) {
* @return mixed
*/
public function getOption($name, $default) {
return isset($this->mountOptions[$name]) ? $this->mountOptions[$name] : $default;
return $this->mountOptions[$name] ?? $default;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/private/Files/Mount/ObjectHomeMountProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ private function getMultiBucketObjectStoreConfig(IUser $user) {
$config['arguments']['bucket'] = '';
}
$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);

$this->config->setUserValue($user->getUID(), 'homeobjectstore', 'bucket', $config['arguments']['bucket']);
Expand Down
2 changes: 1 addition & 1 deletion lib/private/Files/ObjectStore/S3ConnectionTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ public function getConnection() {
);

$options = [
'version' => isset($this->params['version']) ? $this->params['version'] : 'latest',
'version' => $this->params['version'] ?? 'latest',
'credentials' => $provider,
'endpoint' => $base_url,
'region' => $this->params['region'],
Expand Down
2 changes: 1 addition & 1 deletion lib/private/Files/Storage/Common.php
Original file line number Diff line number Diff line change
Expand Up @@ -601,7 +601,7 @@ public function setMountOptions(array $options) {
* @return mixed
*/
public function getMountOption($name, $default = null) {
return isset($this->mountOptions[$name]) ? $this->mountOptions[$name] : $default;
return $this->mountOptions[$name] ?? $default;
}

/**
Expand Down
4 changes: 2 additions & 2 deletions lib/private/Files/Storage/Wrapper/PermissionsMask.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ public function getMetaData($path) {
$data = parent::getMetaData($path);

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;
}
return $data;
Expand All @@ -155,7 +155,7 @@ public function getScanner($path = '', $storage = null) {

public function getDirectoryContent($directory): \Traversable {
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;

yield $data;
Expand Down
8 changes: 4 additions & 4 deletions lib/private/NavigationManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public function add($entry) {
}

$id = $entry['id'];
$entry['unread'] = isset($this->unreadCounters[$id]) ? $this->unreadCounters[$id] : 0;
$entry['unread'] = $this->unreadCounters[$id] ?? 0;

$this->entries[$id] = $entry;
}
Expand Down Expand Up @@ -309,16 +309,16 @@ private function init() {
if (!isset($nav['route']) && $nav['type'] !== 'settings') {
continue;
}
$role = isset($nav['@attributes']['role']) ? $nav['@attributes']['role'] : 'all';
$role = $nav['@attributes']['role'] ?? 'all';
if ($role === 'admin' && !$this->isAdmin()) {
continue;
}
$l = $this->l10nFac->get($app);
$id = $nav['id'] ?? $app . ($key === 0 ? '' : $key);
$order = isset($nav['order']) ? $nav['order'] : 100;
$order = $nav['order'] ?? 100;
$type = $nav['type'];
$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) {
try {
$icon = $this->urlGenerator->imagePath($app, $i);
Expand Down
2 changes: 1 addition & 1 deletion lib/private/Remote/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public function getWebsite() {
* @return string
*/
public function getTwitter() {
return isset($this->data['twitter']) ? $this->data['twitter'] : '';
return $this->data['twitter'] ?? '';
}

/**
Expand Down
8 changes: 4 additions & 4 deletions lib/private/Security/Certificate.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,12 @@ public function __construct(string $data, string $name) {
throw new \Exception('Certificate could not get parsed.');
}

$this->commonName = isset($info['subject']['CN']) ? $info['subject']['CN'] : null;
$this->organization = isset($info['subject']['O']) ? $info['subject']['O'] : null;
$this->commonName = $info['subject']['CN'] ?? null;
$this->organization = $info['subject']['O'] ?? null;
$this->issueDate = new \DateTime('@' . $info['validFrom_time_t'], $gmt);
$this->expireDate = new \DateTime('@' . $info['validTo_time_t'], $gmt);
$this->issuerName = isset($info['issuer']['CN']) ? $info['issuer']['CN'] : null;
$this->issuerOrganization = isset($info['issuer']['O']) ? $info['issuer']['O'] : null;
$this->issuerName = $info['issuer']['CN'] ?? null;
$this->issuerOrganization = $info['issuer']['O'] ?? null;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/private/Setup/AbstractDatabase.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public function initialize($config) {
$dbName = $config['dbname'];
$dbHost = !empty($config['dbhost']) ? $config['dbhost'] : 'localhost';
$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);
// accept `false` both as bool and string, since setting config values from env will result in a string
Expand Down
6 changes: 3 additions & 3 deletions lib/private/Share20/DefaultShareProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -1374,7 +1374,7 @@ public function getAccessList($nodes, $currentAccess) {
$type = (int)$row['share_type'];
if ($type === IShare::TYPE_USER) {
$uid = $row['share_with'];
$users[$uid] = isset($users[$uid]) ? $users[$uid] : [];
$users[$uid] = $users[$uid] ?? [];
$users[$uid][$row['id']] = $row;
} elseif ($type === IShare::TYPE_GROUP) {
$gid = $row['share_with'];
Expand All @@ -1387,14 +1387,14 @@ public function getAccessList($nodes, $currentAccess) {
$userList = $group->getUsers();
foreach ($userList as $user) {
$uid = $user->getUID();
$users[$uid] = isset($users[$uid]) ? $users[$uid] : [];
$users[$uid] = $users[$uid] ?? [];
$users[$uid][$row['id']] = $row;
}
} elseif ($type === IShare::TYPE_LINK) {
$link = true;
} elseif ($type === IShare::TYPE_USERGROUP && $currentAccess === true) {
$uid = $row['share_with'];
$users[$uid] = isset($users[$uid]) ? $users[$uid] : [];
$users[$uid] = $users[$uid] ?? [];
$users[$uid][$row['id']] = $row;
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/private/legacy/OC_App.php
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ public static function getAppWebPath(string $appId) {
public static function getAppVersionByPath(string $path): string {
$infoFile = $path . '/appinfo/info.xml';
$appData = \OC::$server->getAppManager()->getAppInfo($infoFile, true);
return isset($appData['version']) ? $appData['version'] : '';
return $appData['version'] ?? '';
}

/**
Expand Down

0 comments on commit 3f7ae91

Please sign in to comment.