Skip to content

Commit 0a7b4b5

Browse files
Merge pull request #48042 from nextcloud/refactor/elvis
refactor: Use the elvis operator + fix: Handle null checks with the ?? operator
2 parents 54b162f + c57e684 commit 0a7b4b5

File tree

8 files changed

+22
-23
lines changed

8 files changed

+22
-23
lines changed

apps/dav/lib/CalDAV/CalDavBackend.php

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -329,8 +329,8 @@ public function getCalendarsForUser($principalUri) {
329329
'id' => $row['id'],
330330
'uri' => $row['uri'],
331331
'principaluri' => $this->convertPrincipal($row['principaluri'], !$this->legacyEndpoint),
332-
'{' . Plugin::NS_CALENDARSERVER . '}getctag' => 'http://sabre.io/ns/sync/' . ($row['synctoken']?$row['synctoken']:'0'),
333-
'{http://sabredav.org/ns}sync-token' => $row['synctoken']?$row['synctoken']:'0',
332+
'{' . Plugin::NS_CALENDARSERVER . '}getctag' => 'http://sabre.io/ns/sync/' . ($row['synctoken'] ?: '0'),
333+
'{http://sabredav.org/ns}sync-token' => $row['synctoken'] ?: '0',
334334
'{' . Plugin::NS_CALDAV . '}supported-calendar-component-set' => new SupportedCalendarComponentSet($components),
335335
'{' . Plugin::NS_CALDAV . '}schedule-calendar-transp' => new ScheduleCalendarTransp($row['transparent']?'transparent':'opaque'),
336336
'{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}owner-principal' => $this->convertPrincipal($principalUri, !$this->legacyEndpoint),
@@ -411,8 +411,8 @@ public function getCalendarsForUser($principalUri) {
411411
'id' => $row['id'],
412412
'uri' => $uri,
413413
'principaluri' => $this->convertPrincipal($principalUri, !$this->legacyEndpoint),
414-
'{' . Plugin::NS_CALENDARSERVER . '}getctag' => 'http://sabre.io/ns/sync/' . ($row['synctoken']?$row['synctoken']:'0'),
415-
'{http://sabredav.org/ns}sync-token' => $row['synctoken']?$row['synctoken']:'0',
414+
'{' . Plugin::NS_CALENDARSERVER . '}getctag' => 'http://sabre.io/ns/sync/' . ($row['synctoken'] ?: '0'),
415+
'{http://sabredav.org/ns}sync-token' => $row['synctoken'] ?: '0',
416416
'{' . Plugin::NS_CALDAV . '}supported-calendar-component-set' => new SupportedCalendarComponentSet($components),
417417
'{' . Plugin::NS_CALDAV . '}schedule-calendar-transp' => new ScheduleCalendarTransp('transparent'),
418418
'{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}owner-principal' => $this->convertPrincipal($row['principaluri'], !$this->legacyEndpoint),
@@ -461,8 +461,8 @@ public function getUsersOwnCalendars($principalUri) {
461461
'id' => $row['id'],
462462
'uri' => $row['uri'],
463463
'principaluri' => $this->convertPrincipal($row['principaluri'], !$this->legacyEndpoint),
464-
'{' . Plugin::NS_CALENDARSERVER . '}getctag' => 'http://sabre.io/ns/sync/' . ($row['synctoken']?$row['synctoken']:'0'),
465-
'{http://sabredav.org/ns}sync-token' => $row['synctoken']?$row['synctoken']:'0',
464+
'{' . Plugin::NS_CALENDARSERVER . '}getctag' => 'http://sabre.io/ns/sync/' . ($row['synctoken'] ?: '0'),
465+
'{http://sabredav.org/ns}sync-token' => $row['synctoken'] ?: '0',
466466
'{' . Plugin::NS_CALDAV . '}supported-calendar-component-set' => new SupportedCalendarComponentSet($components),
467467
'{' . Plugin::NS_CALDAV . '}schedule-calendar-transp' => new ScheduleCalendarTransp($row['transparent']?'transparent':'opaque'),
468468
];
@@ -513,8 +513,8 @@ public function getPublicCalendars() {
513513
'id' => $row['id'],
514514
'uri' => $row['publicuri'],
515515
'principaluri' => $this->convertPrincipal($row['principaluri'], !$this->legacyEndpoint),
516-
'{' . Plugin::NS_CALENDARSERVER . '}getctag' => 'http://sabre.io/ns/sync/' . ($row['synctoken']?$row['synctoken']:'0'),
517-
'{http://sabredav.org/ns}sync-token' => $row['synctoken']?$row['synctoken']:'0',
516+
'{' . Plugin::NS_CALENDARSERVER . '}getctag' => 'http://sabre.io/ns/sync/' . ($row['synctoken'] ?: '0'),
517+
'{http://sabredav.org/ns}sync-token' => $row['synctoken'] ?: '0',
518518
'{' . Plugin::NS_CALDAV . '}supported-calendar-component-set' => new SupportedCalendarComponentSet($components),
519519
'{' . Plugin::NS_CALDAV . '}schedule-calendar-transp' => new ScheduleCalendarTransp($row['transparent']?'transparent':'opaque'),
520520
'{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}owner-principal' => $this->convertPrincipal($row['principaluri'], $this->legacyEndpoint),
@@ -578,8 +578,8 @@ public function getPublicCalendar($uri) {
578578
'id' => $row['id'],
579579
'uri' => $row['publicuri'],
580580
'principaluri' => $this->convertPrincipal($row['principaluri'], !$this->legacyEndpoint),
581-
'{' . Plugin::NS_CALENDARSERVER . '}getctag' => 'http://sabre.io/ns/sync/' . ($row['synctoken']?$row['synctoken']:'0'),
582-
'{http://sabredav.org/ns}sync-token' => $row['synctoken']?$row['synctoken']:'0',
581+
'{' . Plugin::NS_CALENDARSERVER . '}getctag' => 'http://sabre.io/ns/sync/' . ($row['synctoken'] ?: '0'),
582+
'{http://sabredav.org/ns}sync-token' => $row['synctoken'] ?: '0',
583583
'{' . Plugin::NS_CALDAV . '}supported-calendar-component-set' => new SupportedCalendarComponentSet($components),
584584
'{' . Plugin::NS_CALDAV . '}schedule-calendar-transp' => new ScheduleCalendarTransp($row['transparent']?'transparent':'opaque'),
585585
'{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}owner-principal' => $this->convertPrincipal($row['principaluri'], !$this->legacyEndpoint),
@@ -632,8 +632,8 @@ public function getCalendarByUri($principal, $uri) {
632632
'id' => $row['id'],
633633
'uri' => $row['uri'],
634634
'principaluri' => $this->convertPrincipal($row['principaluri'], !$this->legacyEndpoint),
635-
'{' . Plugin::NS_CALENDARSERVER . '}getctag' => 'http://sabre.io/ns/sync/' . ($row['synctoken']?$row['synctoken']:'0'),
636-
'{http://sabredav.org/ns}sync-token' => $row['synctoken']?$row['synctoken']:'0',
635+
'{' . Plugin::NS_CALENDARSERVER . '}getctag' => 'http://sabre.io/ns/sync/' . ($row['synctoken'] ?: '0'),
636+
'{http://sabredav.org/ns}sync-token' => $row['synctoken'] ?: '0',
637637
'{' . Plugin::NS_CALDAV . '}supported-calendar-component-set' => new SupportedCalendarComponentSet($components),
638638
'{' . Plugin::NS_CALDAV . '}schedule-calendar-transp' => new ScheduleCalendarTransp($row['transparent']?'transparent':'opaque'),
639639
];
@@ -680,7 +680,7 @@ public function getCalendarById(int $calendarId): ?array {
680680
'id' => $row['id'],
681681
'uri' => $row['uri'],
682682
'principaluri' => $this->convertPrincipal($row['principaluri'], !$this->legacyEndpoint),
683-
'{' . Plugin::NS_CALENDARSERVER . '}getctag' => 'http://sabre.io/ns/sync/' . ($row['synctoken']?$row['synctoken']:'0'),
683+
'{' . Plugin::NS_CALENDARSERVER . '}getctag' => 'http://sabre.io/ns/sync/' . ($row['synctoken'] ?: '0'),
684684
'{http://sabredav.org/ns}sync-token' => $row['synctoken'] ?? 0,
685685
'{' . Plugin::NS_CALDAV . '}supported-calendar-component-set' => new SupportedCalendarComponentSet($components),
686686
'{' . Plugin::NS_CALDAV . '}schedule-calendar-transp' => new ScheduleCalendarTransp($row['transparent']?'transparent':'opaque'),
@@ -726,7 +726,7 @@ public function getSubscriptionById($subscriptionId) {
726726
'source' => $row['source'],
727727
'lastmodified' => $row['lastmodified'],
728728
'{' . Plugin::NS_CALDAV . '}supported-calendar-component-set' => new SupportedCalendarComponentSet(['VTODO', 'VEVENT']),
729-
'{http://sabredav.org/ns}sync-token' => $row['synctoken']?$row['synctoken']:'0',
729+
'{http://sabredav.org/ns}sync-token' => $row['synctoken'] ?: '0',
730730
];
731731

732732
return $this->rowToSubscription($row, $subscription);
@@ -2560,7 +2560,7 @@ public function getSubscriptionsForUser($principalUri) {
25602560
'lastmodified' => $row['lastmodified'],
25612561

25622562
'{' . Plugin::NS_CALDAV . '}supported-calendar-component-set' => new SupportedCalendarComponentSet(['VTODO', 'VEVENT']),
2563-
'{http://sabredav.org/ns}sync-token' => $row['synctoken']?$row['synctoken']:'0',
2563+
'{http://sabredav.org/ns}sync-token' => $row['synctoken'] ?: '0',
25642564
];
25652565

25662566
$subscriptions[] = $this->rowToSubscription($row, $subscription);

apps/files_external/lib/Controller/StoragesController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ protected function updateStorageStatus(StorageConfig &$storage, $testOnly = true
228228
)
229229
);
230230
} catch (InsufficientDataForMeaningfulAnswerException $e) {
231-
$status = $e->getCode() ? $e->getCode() : StorageNotAvailableException::STATUS_INDETERMINATE;
231+
$status = $e->getCode() ?: StorageNotAvailableException::STATUS_INDETERMINATE;
232232
$storage->setStatus(
233233
(int)$status,
234234
$this->l10n->t('Insufficient data: %s', [$e->getMessage()])

apps/files_sharing/lib/External/Manager.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ public function __construct(
119119
* @throws \Doctrine\DBAL\Exception
120120
*/
121121
public function addShare($remote, $token, $password, $name, $owner, $shareType, $accepted = false, $user = null, $remoteId = '', $parent = -1) {
122-
$user = $user ? $user : $this->uid;
122+
$user = $user ?? $this->uid;
123123
$accepted = $accepted ? IShare::STATUS_ACCEPTED : IShare::STATUS_PENDING;
124124
$name = Filesystem::normalizePath('/' . $name);
125125

apps/updatenotification/tests/BackgroundJob/UpdateAvailableNotificationsTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ public function testCreateNotifications(string $app, string $version, $lastNotif
286286
$this->appConfig->expects($this->once())
287287
->method('getAppValueString')
288288
->with($app, '')
289-
->willReturn($lastNotification ? $lastNotification : '');
289+
->willReturn($lastNotification ?: '');
290290

291291
if ($lastNotification !== $version) {
292292
$this->appConfig->expects($this->once())

apps/user_ldap/lib/User/User.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -646,8 +646,7 @@ private function updateProfile(array $profileValues): void {
646646
try {
647647
$accountProperty = $account->getProperty($property);
648648
$currentValue = $accountProperty->getValue();
649-
$scope = ($accountProperty->getScope() ? $accountProperty->getScope()
650-
: $defaultScopes[$property]);
649+
$scope = ($accountProperty->getScope() ?: $defaultScopes[$property]);
651650
} catch (PropertyDoesNotExistException $e) { // thrown at getProperty
652651
$this->logger->error('property does not exist: '.$property
653652
.' for uid='.$this->uid.'', ['app' => 'user_ldap', 'exception' => $e]);

apps/weather_status/lib/Service/WeatherStatusService.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ public function setLocation(?string $address, ?float $lat, ?float $lon): array {
121121
$this->config->setUserValue($this->userId, Application::APP_ID, 'lon', strval($lon));
122122
// resolve and store formatted address
123123
$address = $this->resolveLocation($lat, $lon);
124-
$address = $address ? $address : $this->l10n->t('Unknown address');
124+
$address = $address ?: $this->l10n->t('Unknown address');
125125
$this->config->setUserValue($this->userId, Application::APP_ID, 'address', $address);
126126
// get and store altitude
127127
$altitude = $this->getAltitude($lat, $lon);

lib/private/Log/LogDetails.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public function logDetails(string $app, $message, int $level): array {
3737
$url = ($request->getRequestUri() !== '') ? $request->getRequestUri() : '--';
3838
$method = is_string($request->getMethod()) ? $request->getMethod() : '--';
3939
if ($this->config->getValue('installed', false)) {
40-
$user = \OC_User::getUser() ? \OC_User::getUser() : '--';
40+
$user = \OC_User::getUser() ?? '--';
4141
} else {
4242
$user = '--';
4343
}

lib/private/User/Database.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ class Database extends ABackend implements
6464
public function __construct($eventDispatcher = null, $table = 'users') {
6565
$this->cache = new CappedMemoryCache();
6666
$this->table = $table;
67-
$this->eventDispatcher = $eventDispatcher ? $eventDispatcher : \OCP\Server::get(IEventDispatcher::class);
67+
$this->eventDispatcher = $eventDispatcher ?? \OCP\Server::get(IEventDispatcher::class);
6868
}
6969

7070
/**

0 commit comments

Comments
 (0)