From d64bbc8bd3a6a272dd5c550916a6b80222f19e13 Mon Sep 17 00:00:00 2001 From: Hamid Dehnavi Date: Fri, 7 Jul 2023 13:50:21 +0330 Subject: [PATCH] Convert isset ternary to null coalescing operator Signed-off-by: Hamid Dehnavi --- apps/dav/lib/Avatars/AvatarHome.php | 4 ++-- apps/dav/lib/DAV/Sharing/Xml/ShareRequest.php | 4 ++-- apps/encryption/lib/Hooks/UserHooks.php | 2 +- apps/federatedfilesharing/lib/Notifications.php | 2 +- apps/federation/lib/BackgroundJob/GetSharedSecret.php | 2 +- apps/federation/lib/BackgroundJob/RequestSharedSecret.php | 2 +- apps/federation/lib/SyncFederationAddressBooks.php | 2 +- apps/files/templates/appnavigation.php | 2 +- .../3rdparty/icewind/smb/src/Wrapped/Parser.php | 4 ++-- apps/files_external/lib/Command/Import.php | 4 ++-- apps/files_external/lib/MountConfig.php | 4 ++-- apps/files_sharing/lib/External/Manager.php | 2 +- apps/files_sharing/public.php | 2 +- .../tests/Controller/ShareesAPIControllerTest.php | 4 ++-- .../tests/Controller/GroupsControllerTest.php | 4 ++-- apps/user_ldap/ajax/wizard.php | 4 ++-- apps/user_ldap/lib/Access.php | 2 +- 17 files changed, 25 insertions(+), 25 deletions(-) diff --git a/apps/dav/lib/Avatars/AvatarHome.php b/apps/dav/lib/Avatars/AvatarHome.php index ba52daeb2b32f..097307f452f73 100644 --- a/apps/dav/lib/Avatars/AvatarHome.php +++ b/apps/dav/lib/Avatars/AvatarHome.php @@ -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'); } diff --git a/apps/dav/lib/DAV/Sharing/Xml/ShareRequest.php b/apps/dav/lib/DAV/Sharing/Xml/ShareRequest.php index eb5d7d4661d10..6a97cd30d9f77 100644 --- a/apps/dav/lib/DAV/Sharing/Xml/ShareRequest.php +++ b/apps/dav/lib/DAV/Sharing/Xml/ShareRequest.php @@ -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; diff --git a/apps/encryption/lib/Hooks/UserHooks.php b/apps/encryption/lib/Hooks/UserHooks.php index e9efc4c35c109..27eba0ad781e1 100644 --- a/apps/encryption/lib/Hooks/UserHooks.php +++ b/apps/encryption/lib/Hooks/UserHooks.php @@ -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); diff --git a/apps/federatedfilesharing/lib/Notifications.php b/apps/federatedfilesharing/lib/Notifications.php index f0d50a25abeff..b2da4cb3e2814 100644 --- a/apps/federatedfilesharing/lib/Notifications.php +++ b/apps/federatedfilesharing/lib/Notifications.php @@ -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, diff --git a/apps/federation/lib/BackgroundJob/GetSharedSecret.php b/apps/federation/lib/BackgroundJob/GetSharedSecret.php index 3ca3e0a906b70..1f81773cd4dc4 100644 --- a/apps/federation/lib/BackgroundJob/GetSharedSecret.php +++ b/apps/federation/lib/BackgroundJob/GetSharedSecret.php @@ -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, '/'); diff --git a/apps/federation/lib/BackgroundJob/RequestSharedSecret.php b/apps/federation/lib/BackgroundJob/RequestSharedSecret.php index d410af2a7f421..98eb81000f256 100644 --- a/apps/federation/lib/BackgroundJob/RequestSharedSecret.php +++ b/apps/federation/lib/BackgroundJob/RequestSharedSecret.php @@ -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, '/'); diff --git a/apps/federation/lib/SyncFederationAddressBooks.php b/apps/federation/lib/SyncFederationAddressBooks.php index 3c3c8c872c753..e718e1638de82 100644 --- a/apps/federation/lib/SyncFederationAddressBooks.php +++ b/apps/federation/lib/SyncFederationAddressBooks.php @@ -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)) { diff --git a/apps/files/templates/appnavigation.php b/apps/files/templates/appnavigation.php index 96df2b91a8496..17409bdb189b5 100644 --- a/apps/files/templates/appnavigation.php +++ b/apps/files/templates/appnavigation.php @@ -37,7 +37,7 @@ class="nav- open" folderposition="" > - diff --git a/apps/files_external/3rdparty/icewind/smb/src/Wrapped/Parser.php b/apps/files_external/3rdparty/icewind/smb/src/Wrapped/Parser.php index 00f01af7dd52d..28cd871145e6d 100644 --- a/apps/files_external/3rdparty/icewind/smb/src/Wrapped/Parser.php +++ b/apps/files_external/3rdparty/icewind/smb/src/Wrapped/Parser.php @@ -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])) { diff --git a/apps/files_external/lib/Command/Import.php b/apps/files_external/lib/Command/Import.php index eab7dd9a6bedb..afd8f2ac0fa32 100644 --- a/apps/files_external/lib/Command/Import.php +++ b/apps/files_external/lib/Command/Import.php @@ -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; } diff --git a/apps/files_external/lib/MountConfig.php b/apps/files_external/lib/MountConfig.php index ff631d82e26a9..98b34b0c9f253 100644 --- a/apps/files_external/lib/MountConfig.php +++ b/apps/files_external/lib/MountConfig.php @@ -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); diff --git a/apps/files_sharing/lib/External/Manager.php b/apps/files_sharing/lib/External/Manager.php index d2e113c8bb36e..86028602c5163 100644 --- a/apps/files_sharing/lib/External/Manager.php +++ b/apps/files_sharing/lib/External/Manager.php @@ -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]; diff --git a/apps/files_sharing/public.php b/apps/files_sharing/public.php index 8734042d87797..0213247b60489 100644 --- a/apps/files_sharing/public.php +++ b/apps/files_sharing/public.php @@ -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 !== '') { diff --git a/apps/files_sharing/tests/Controller/ShareesAPIControllerTest.php b/apps/files_sharing/tests/Controller/ShareesAPIControllerTest.php index 860d5796e56dc..b73b605f4102f 100644 --- a/apps/files_sharing/tests/Controller/ShareesAPIControllerTest.php +++ b/apps/files_sharing/tests/Controller/ShareesAPIControllerTest.php @@ -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); diff --git a/apps/provisioning_api/tests/Controller/GroupsControllerTest.php b/apps/provisioning_api/tests/Controller/GroupsControllerTest.php index 5d16d58fc0a2f..a60d01f68c34f 100644 --- a/apps/provisioning_api/tests/Controller/GroupsControllerTest.php +++ b/apps/provisioning_api/tests/Controller/GroupsControllerTest.php @@ -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); @@ -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); diff --git a/apps/user_ldap/ajax/wizard.php b/apps/user_ldap/ajax/wizard.php index dcfe9ff76b82d..8692251c7c047 100644 --- a/apps/user_ldap/ajax/wizard.php +++ b/apps/user_ldap/ajax/wizard.php @@ -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; diff --git a/apps/user_ldap/lib/Access.php b/apps/user_ldap/lib/Access.php index 0b115c42764cd..49e431820ac1a 100644 --- a/apps/user_ldap/lib/Access.php +++ b/apps/user_ldap/lib/Access.php @@ -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); if (!is_array($uuid) && $uuidOverride !== '' && $this->detectUuidAttribute($dn, $isUser, true, $ldapRecord)) {