Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert isset ternary to null coalescing operator #39225

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions apps/dav/lib/Avatars/AvatarHome.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ public function createDirectory($name) {

public function getChild($name) {
$elements = pathinfo($name);
$ext = isset($elements['extension']) ? $elements['extension'] : '';
$size = (int)(isset($elements['filename']) ? $elements['filename'] : '64');
$ext = $elements['extension'] ?? '';
$size = (int)($elements['filename'] ?? '64');
if (!in_array($ext, ['jpeg', 'png'], true)) {
throw new MethodNotAllowed('File format not allowed');
}
Expand Down
4 changes: 2 additions & 2 deletions apps/dav/lib/DAV/Sharing/Xml/ShareRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ public static function xmlDeserialize(Reader $reader) {

$set[] = [
'href' => $sharee['{DAV:}href'],
'commonName' => isset($sharee[$commonName]) ? $sharee[$commonName] : null,
'summary' => isset($sharee[$sumElem]) ? $sharee[$sumElem] : null,
'commonName' => $sharee[$commonName] ?? null,
'summary' => $sharee[$sumElem] ?? null,
'readOnly' => !array_key_exists('{' . Plugin::NS_OWNCLOUD . '}read-write', $sharee),
];
break;
Expand Down
2 changes: 1 addition & 1 deletion apps/encryption/lib/Hooks/UserHooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ public function setPassphrase($params) {
} else { // admin changed the password for a different user, create new keys and re-encrypt file keys
$userId = $params['uid'];
$this->initMountPoints($userId);
$recoveryPassword = isset($params['recoveryPassword']) ? $params['recoveryPassword'] : null;
$recoveryPassword = $params['recoveryPassword'] ?? null;

$recoveryKeyId = $this->keyManager->getRecoveryKeyId();
$recoveryKey = $this->keyManager->getSystemPrivateKey($recoveryKeyId);
Expand Down
2 changes: 1 addition & 1 deletion apps/federatedfilesharing/lib/Notifications.php
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ protected function tryLegacyEndPoint($remoteDomain, $urlSuffix, array $fields) {
// Fall back to old API
$client = $this->httpClientService->newClient();
$federationEndpoints = $this->discoveryService->discover($remoteDomain, 'FEDERATED_SHARING');
$endpoint = isset($federationEndpoints['share']) ? $federationEndpoints['share'] : '/ocs/v2.php/cloud/shares';
$endpoint = $federationEndpoints['share'] ?? '/ocs/v2.php/cloud/shares';
try {
$response = $client->post($remoteDomain . $endpoint . $urlSuffix . '?format=' . self::RESPONSE_FORMAT, [
'body' => $fields,
Expand Down
2 changes: 1 addition & 1 deletion apps/federation/lib/BackgroundJob/GetSharedSecret.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ protected function run($argument) {
}

$endPoints = $this->ocsDiscoveryService->discover($target, 'FEDERATED_SHARING');
$endPoint = isset($endPoints['shared-secret']) ? $endPoints['shared-secret'] : $this->defaultEndPoint;
$endPoint = $endPoints['shared-secret'] ?? $this->defaultEndPoint;

// make sure that we have a well formatted url
$url = rtrim($target, '/') . '/' . trim($endPoint, '/');
Expand Down
2 changes: 1 addition & 1 deletion apps/federation/lib/BackgroundJob/RequestSharedSecret.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ protected function run($argument) {
}

$endPoints = $this->ocsDiscoveryService->discover($target, 'FEDERATED_SHARING');
$endPoint = isset($endPoints['shared-secret']) ? $endPoints['shared-secret'] : $this->defaultEndPoint;
$endPoint = $endPoints['shared-secret'] ?? $this->defaultEndPoint;

// make sure that we have a well formatted url
$url = rtrim($target, '/') . '/' . trim($endPoint, '/');
Expand Down
2 changes: 1 addition & 1 deletion apps/federation/lib/SyncFederationAddressBooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public function syncThemAll(\Closure $callback) {
$syncToken = $trustedServer['sync_token'];

$endPoints = $this->ocsDiscoveryService->discover($url, 'FEDERATED_SHARING');
$cardDavUser = isset($endPoints['carddav-user']) ? $endPoints['carddav-user'] : 'system';
$cardDavUser = $endPoints['carddav-user'] ?? 'system';
$addressBookUrl = isset($endPoints['system-address-book']) ? trim($endPoints['system-address-book'], '/') : 'remote.php/dav/addressbooks/system/system/system';

if (is_null($sharedSecret)) {
Expand Down
2 changes: 1 addition & 1 deletion apps/files/templates/appnavigation.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class="nav-<?php p($item['id']) ?>
<?php if (isset($item['defaultExpandedState']) && $item['defaultExpandedState']) { ?> open<?php } ?>"
<?php if (isset($item['folderPosition'])) { ?> folderposition="<?php p($item['folderPosition']); ?>" <?php } ?>>

<a href="<?php p(isset($item['href']) ? $item['href'] : '#') ?>"
<a href="<?php p($item['href'] ?? '#') ?>"
class="nav-icon-<?php p(isset($item['icon']) && $item['icon'] !== '' ? $item['icon'] : $item['id']) ?> svg"><?php p($item['name']); ?></a>


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,8 @@ public function parseStat(array $output): array {
// A line = explode statement may not fill all array elements
// properly. May happen when accessing non Windows Fileservers
$words = explode(':', $line, 2);
$name = isset($words[0]) ? $words[0] : '';
$value = isset($words[1]) ? $words[1] : '';
$name = $words[0] ?? '';
$value = $words[1] ?? '';
$value = trim($value);

if (!isset($data[$name])) {
Expand Down
4 changes: 2 additions & 2 deletions apps/files_external/lib/Command/Import.php
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,8 @@ private function parseData(array $data): StorageConfig {
$mount->setAuthMechanism($authBackend);
$mount->setBackendOptions($data['configuration']);
$mount->setMountOptions($data['options']);
$mount->setApplicableUsers(isset($data['applicable_users']) ? $data['applicable_users'] : []);
$mount->setApplicableGroups(isset($data['applicable_groups']) ? $data['applicable_groups'] : []);
$mount->setApplicableUsers($data['applicable_users'] ?? []);
$mount->setApplicableGroups($data['applicable_groups'] ?? []);
return $mount;
}

Expand Down
4 changes: 2 additions & 2 deletions apps/files_external/lib/MountConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -276,8 +276,8 @@ public static function makeConfigHash($config) {
'a' => $config['authMechanism'],
'm' => $config['mountpoint'],
'o' => $config['options'],
'p' => isset($config['priority']) ? $config['priority'] : -1,
'mo' => isset($config['mountOptions']) ? $config['mountOptions'] : [],
'p' => $config['priority'] ?? -1,
'mo' => $config['mountOptions'] ?? [],
]
);
return hash('md5', $data);
Expand Down
2 changes: 1 addition & 1 deletion apps/files_sharing/lib/External/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,7 @@ private function sendFeedbackToRemote($remote, $token, $remoteId, $feedback) {
}

$federationEndpoints = $this->discoveryService->discover($remote, 'FEDERATED_SHARING');
$endpoint = isset($federationEndpoints['share']) ? $federationEndpoints['share'] : '/ocs/v2.php/cloud/shares';
$endpoint = $federationEndpoints['share'] ?? '/ocs/v2.php/cloud/shares';

$url = rtrim($remote, '/') . $endpoint . '/' . $remoteId . '/' . $feedback . '?format=' . Share::RESPONSE_FORMAT;
$fields = ['token' => $token];
Expand Down
2 changes: 1 addition & 1 deletion apps/files_sharing/public.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
// This file is just used to redirect the legacy sharing URLs (< ownCloud 8) to the new ones

$urlGenerator = \OC::$server->getURLGenerator();
$token = isset($_GET['t']) ? $_GET['t'] : '';
$token = $_GET['t'] ?? '';
$route = isset($_GET['download']) ? 'files_sharing.sharecontroller.downloadShare' : 'files_sharing.sharecontroller.showShare';

if ($token !== '') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -340,8 +340,8 @@ public function dataSearchInvalid(): array {
* @param string $message
*/
public function testSearchInvalid($getData, $message) {
$page = isset($getData['page']) ? $getData['page'] : 1;
$perPage = isset($getData['perPage']) ? $getData['perPage'] : 200;
$page = $getData['page'] ?? 1;
$perPage = $getData['perPage'] ?? 200;

/** @var IConfig|MockObject $config */
$config = $this->createMock(IConfig::class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,7 @@ public function testGetGroupUsersDetails() {
$this->userManager->expects($this->any())
->method('get')
->willReturnCallback(function (string $uid) use ($users) {
return isset($users[$uid]) ? $users[$uid] : null;
return $users[$uid] ?? null;
});

$group = $this->createGroup($gid);
Expand Down Expand Up @@ -552,7 +552,7 @@ public function testGetGroupUsersDetailsEncoded() {
$this->userManager->expects($this->any())
->method('get')
->willReturnCallback(function (string $uid) use ($users) {
return isset($users[$uid]) ? $users[$uid] : null;
return $users[$uid] ?? null;
});

$group = $this->createGroup($gid);
Expand Down
4 changes: 2 additions & 2 deletions apps/user_ldap/ajax/wizard.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@
}

case 'save':
$key = isset($_POST['cfgkey']) ? $_POST['cfgkey'] : false;
$val = isset($_POST['cfgval']) ? $_POST['cfgval'] : null;
$key = $_POST['cfgkey'] ?? false;
$val = $_POST['cfgval'] ?? null;
if ($key === false || is_null($val)) {
\OC_JSON::error(['message' => $l->t('No data specified')]);
exit;
Expand Down
2 changes: 1 addition & 1 deletion apps/user_ldap/lib/Access.php
Original file line number Diff line number Diff line change
Expand Up @@ -1746,7 +1746,7 @@ public function getUUID(string $dn, bool $isUser = true, array $ldapRecord = nul
$uuid = false;
if ($this->detectUuidAttribute($dn, $isUser, false, $ldapRecord)) {
$attr = $this->connection->$uuidAttr;
$uuid = isset($ldapRecord[$attr]) ? $ldapRecord[$attr] : $this->readAttribute($dn, $attr);
$uuid = $ldapRecord[$attr] ?? $this->readAttribute($dn, $attr);
shdehnavi marked this conversation as resolved.
Show resolved Hide resolved
if (!is_array($uuid)
&& $uuidOverride !== ''
&& $this->detectUuidAttribute($dn, $isUser, true, $ldapRecord)) {
Expand Down
Loading