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

chore: adjust code to adhere to coding standard #47789

Merged
merged 2 commits into from
Sep 5, 2024
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
1 change: 1 addition & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ aa5f037af71c915424c6dcfd5ad2dc82797dc0d6
# Update to coding-standard 1.2.3
af6de04e9e141466dc229e444ff3f146f4a34765
0bd284cb81b6866338aaaa67aa1d81ef9bfbb2ab
8af7ecb2576071f170ecbb0aa2311b26581e40e2
12 changes: 6 additions & 6 deletions apps/dav/lib/BackgroundJob/UserStatusAutomation.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,14 @@ protected function run($argument) {

$userId = $argument['userId'];
$user = $this->userManager->get($userId);
if($user === null) {
if ($user === null) {
return;
}

$ooo = $this->coordinator->getCurrentOutOfOfficeData($user);

$continue = $this->processOutOfOfficeData($user, $ooo);
if($continue === false) {
if ($continue === false) {
return;
}

Expand Down Expand Up @@ -196,7 +196,7 @@ private function processAvailability(string $property, string $userId, bool $has
return;
}

if(!$hasDndForOfficeHours) {
if (!$hasDndForOfficeHours) {
// Office hours are not set to DND, so there is nothing to do.
return;
}
Expand All @@ -207,20 +207,20 @@ private function processAvailability(string $property, string $userId, bool $has
}

private function processOutOfOfficeData(IUser $user, ?IOutOfOfficeData $ooo): bool {
if(empty($ooo)) {
if (empty($ooo)) {
// Reset the user status if the absence doesn't exist
$this->logger->debug('User has no OOO period in effect, reverting DND status if applicable');
$this->manager->revertUserStatus($user->getUID(), IUserStatus::MESSAGE_OUT_OF_OFFICE, IUserStatus::DND);
// We need to also run the availability automation
return true;
}

if(!$this->coordinator->isInEffect($ooo)) {
if (!$this->coordinator->isInEffect($ooo)) {
// Reset the user status if the absence is (no longer) in effect
$this->logger->debug('User has no OOO period in effect, reverting DND status if applicable');
$this->manager->revertUserStatus($user->getUID(), IUserStatus::MESSAGE_OUT_OF_OFFICE, IUserStatus::DND);

if($ooo->getStartDate() > $this->time->getTime()) {
if ($ooo->getStartDate() > $this->time->getTime()) {
// Set the next run to take place at the start of the ooo period if it is in the future
// This might be overwritten if there is an availability setting, but we can't determine
// if this is the case here
Expand Down
2 changes: 1 addition & 1 deletion apps/dav/lib/CalDAV/BirthdayCalendar/EnablePlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public function httpPost(RequestInterface $request, ResponseInterface $response)
}

$owner = substr($node->getOwner(), 17);
if($owner !== $this->user->getUID()) {
if ($owner !== $this->user->getUID()) {
$this->server->httpResponse->setStatus(403);
return false;
}
Expand Down
8 changes: 4 additions & 4 deletions apps/dav/lib/CalDAV/CalDavBackend.php
Original file line number Diff line number Diff line change
Expand Up @@ -2815,7 +2815,7 @@ public function deleteOutdatedSchedulingObjects(int $modifiedBefore, int $limit)
->setMaxResults($limit);
$result = $query->executeQuery();
$count = $result->rowCount();
if($count === 0) {
if ($count === 0) {
return;
}
$ids = array_map(static function (array $id) {
Expand All @@ -2827,12 +2827,12 @@ public function deleteOutdatedSchedulingObjects(int $modifiedBefore, int $limit)
$deleteQuery = $this->db->getQueryBuilder();
$deleteQuery->delete('schedulingobjects')
->where($deleteQuery->expr()->in('id', $deleteQuery->createParameter('ids'), IQueryBuilder::PARAM_INT_ARRAY));
foreach(array_chunk($ids, 1000) as $chunk) {
foreach (array_chunk($ids, 1000) as $chunk) {
$deleteQuery->setParameter('ids', $chunk, IQueryBuilder::PARAM_INT_ARRAY);
$numDeleted += $deleteQuery->executeStatement();
}

if($numDeleted === $limit) {
if ($numDeleted === $limit) {
$this->logger->info("Deleted $limit scheduling objects, continuing with next batch");
$this->deleteOutdatedSchedulingObjects($modifiedBefore, $limit);
}
Expand Down Expand Up @@ -3307,7 +3307,7 @@ public function purgeAllCachedEventsForSubscription($subscriptionId) {
* @param array<string> $calendarObjectUris
*/
public function purgeCachedEventsForSubscription(int $subscriptionId, array $calendarObjectIds, array $calendarObjectUris): void {
if(empty($calendarObjectUris)) {
if (empty($calendarObjectUris)) {
return;
}

Expand Down
4 changes: 2 additions & 2 deletions apps/dav/lib/CalDAV/CalendarHome.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,9 @@

// Calendar - this covers all "regular" calendars, but not shared
// only check if the method is available
if($this->caldavBackend instanceof CalDavBackend) {
if ($this->caldavBackend instanceof CalDavBackend) {
$calendar = $this->caldavBackend->getCalendarByUri($this->principalInfo['uri'], $name);
if(!empty($calendar)) {
if (!empty($calendar)) {

Check notice

Code scanning / Psalm

RiskyTruthyFalsyComparison Note

Operand of type array<array-key, mixed>|null contains type array<array-key, mixed>, which can be falsy and truthy. This can cause possibly unexpected behavior. Use strict comparison instead.
return new Calendar($this->caldavBackend, $calendar, $this->l10n, $this->config, $this->logger);
}
}
Expand Down
2 changes: 1 addition & 1 deletion apps/dav/lib/CalDAV/CalendarImpl.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public function getSchedulingTimezone(): ?VTimeZone {
/** @var VCalendar $vobj */
$vobj = Reader::read($timezoneProp);
$components = $vobj->getComponents();
if(empty($components)) {
if (empty($components)) {
return null;
}
/** @var VTimeZone $vtimezone */
Expand Down
14 changes: 7 additions & 7 deletions apps/dav/lib/CalDAV/EventComparisonService.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,14 @@
*/
private function removeIfUnchanged(VEvent $filterEvent, array &$eventsToFilter): bool {
$filterEventData = [];
foreach(self::EVENT_DIFF as $eventDiff) {
foreach (self::EVENT_DIFF as $eventDiff) {
$filterEventData[] = IMipService::readPropertyWithDefault($filterEvent, $eventDiff, '');
}

/** @var VEvent $component */
foreach ($eventsToFilter as $k => $eventToFilter) {
$eventToFilterData = [];
foreach(self::EVENT_DIFF as $eventDiff) {
foreach (self::EVENT_DIFF as $eventDiff) {
$eventToFilterData[] = IMipService::readPropertyWithDefault($eventToFilter, $eventDiff, '');
}
// events are identical and can be removed
Expand Down Expand Up @@ -73,23 +73,23 @@
$newEventComponents = $new->getComponents();

foreach ($newEventComponents as $k => $event) {
if(!$event instanceof VEvent) {
if (!$event instanceof VEvent) {
unset($newEventComponents[$k]);
}
}

if(empty($old)) {
if (empty($old)) {
return ['old' => null, 'new' => $newEventComponents];
}

$oldEventComponents = $old->getComponents();
if(is_array($oldEventComponents) && !empty($oldEventComponents)) {
if (is_array($oldEventComponents) && !empty($oldEventComponents)) {

Check notice

Code scanning / Psalm

RedundantConditionGivenDocblockType Note

Docblock-defined type array<array-key, mixed> for $oldEventComponents is always array<array-key, mixed>
foreach ($oldEventComponents as $k => $event) {
if(!$event instanceof VEvent) {
if (!$event instanceof VEvent) {
unset($oldEventComponents[$k]);
continue;
}
if($this->removeIfUnchanged($event, $newEventComponents)) {
if ($this->removeIfUnchanged($event, $newEventComponents)) {
unset($oldEventComponents[$k]);
}
}
Expand Down
2 changes: 1 addition & 1 deletion apps/dav/lib/CalDAV/Reminder/ReminderService.php
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ private function writeRemindersToDatabase(array $reminders): void {
$uniqueReminders = [];
foreach ($reminders as $reminder) {
$key = $reminder['notification_date']. $reminder['event_hash'].$reminder['type'];
if(!isset($uniqueReminders[$key])) {
if (!isset($uniqueReminders[$key])) {
$uniqueReminders[$key] = $reminder;
}
}
Expand Down
8 changes: 4 additions & 4 deletions apps/dav/lib/CalDAV/Schedule/IMipPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@
* @param bool $modified modified
*/
public function beforeWriteContent($uri, INode $node, $data, $modified): void {
if(!$node instanceof CalendarObject) {
if (!$node instanceof CalendarObject) {
return;
}
/** @var VCalendar $vCalendar */
Expand Down Expand Up @@ -151,7 +151,7 @@

// No changed events after all - this shouldn't happen if there is significant change yet here we are
// The scheduling status is debatable
if(empty($vEvent)) {
if (empty($vEvent)) {

Check notice

Code scanning / Psalm

DocblockTypeContradiction Note

Operand of type false is always falsy

Check notice

Code scanning / Psalm

DocblockTypeContradiction Note

Docblock-defined type Sabre\VObject\Component\VEvent for $vEvent is never falsy
$this->logger->warning('iTip message said the change was significant but comparison did not detect any updated VEvents');
$iTipMessage->scheduleStatus = '1.0;We got the message, but it\'s not significant enough to warrant an email';
return;
Expand All @@ -163,14 +163,14 @@
// we also might not have an old event as this could be a new
// invitation, or a new recurrence exception
$attendee = $this->imipService->getCurrentAttendee($iTipMessage);
if($attendee === null) {
if ($attendee === null) {
$uid = $vEvent->UID ?? 'no UID found';
$this->logger->debug('Could not find recipient ' . $recipient . ' as attendee for event with UID ' . $uid);
$iTipMessage->scheduleStatus = '5.0; EMail delivery failed';
return;
}
// Don't send emails to things
if($this->imipService->isRoomOrResource($attendee)) {
if ($this->imipService->isRoomOrResource($attendee)) {
$this->logger->debug('No invitation sent as recipient is room or resource', [
'attendee' => $recipient,
]);
Expand Down
20 changes: 10 additions & 10 deletions apps/dav/lib/CalDAV/Schedule/IMipService.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
return $default;
}
$newstring = $vevent->$property->getValue();
if(isset($oldVEvent->$property) && $oldVEvent->$property->getValue() !== $newstring) {
if (isset($oldVEvent->$property) && $oldVEvent->$property->getValue() !== $newstring) {
$oldstring = $oldVEvent->$property->getValue();
return sprintf($strikethrough, $oldstring, $newstring);
}
Expand Down Expand Up @@ -143,7 +143,7 @@
$data = [];
$data['meeting_when'] = $this->generateWhenString($eventReaderCurrent);

foreach(self::STRING_DIFF as $key => $property) {
foreach (self::STRING_DIFF as $key => $property) {
$data[$key] = self::readPropertyWithDefault($vEvent, $property, $defaultVal);
}

Expand All @@ -153,7 +153,7 @@
$data['meeting_location_html'] = $locationHtml;
}

if(!empty($oldVEvent)) {
if (!empty($oldVEvent)) {
$oldMeetingWhen = $this->generateWhenString($eventReaderPrevious);
$data['meeting_title_html'] = $this->generateDiffString($vEvent, $oldVEvent, 'SUMMARY', $data['meeting_title']);
$data['meeting_description_html'] = $this->generateDiffString($vEvent, $oldVEvent, 'DESCRIPTION', $data['meeting_description']);
Expand Down Expand Up @@ -638,15 +638,15 @@
return $dtEnd->getDateTime()->getTimeStamp();
}

if(isset($component->DURATION)) {
if (isset($component->DURATION)) {
/** @var \DateTime $endDate */
$endDate = clone $dtStart->getDateTime();
// $component->DTEND->getDateTime() returns DateTimeImmutable
$endDate = $endDate->add(DateTimeParser::parse($component->DURATION->getValue()));
return $endDate->getTimestamp();
}

if(!$dtStart->hasTime()) {
if (!$dtStart->hasTime()) {
/** @var \DateTime $endDate */
// $component->DTSTART->getDateTime() returns DateTimeImmutable
$endDate = clone $dtStart->getDateTime();
Expand All @@ -662,7 +662,7 @@
* @param Property|null $attendee
*/
public function setL10n(?Property $attendee = null) {
if($attendee === null) {
if ($attendee === null) {
return;
}

Expand All @@ -678,7 +678,7 @@
* @return bool
*/
public function getAttendeeRsvpOrReqForParticipant(?Property $attendee = null) {
if($attendee === null) {
if ($attendee === null) {
return false;
}

Expand Down Expand Up @@ -786,10 +786,10 @@
htmlspecialchars($organizer->getNormalizedValue()),
htmlspecialchars($organizerName ?: $organizerEmail));
$organizerText = sprintf('%s <%s>', $organizerName, $organizerEmail);
if(isset($organizer['PARTSTAT'])) {
if (isset($organizer['PARTSTAT'])) {
/** @var Parameter $partstat */
$partstat = $organizer['PARTSTAT'];
if(strcasecmp($partstat->getValue(), 'ACCEPTED') === 0) {
if (strcasecmp($partstat->getValue(), 'ACCEPTED') === 0) {

Check notice

Code scanning / Psalm

PossiblyNullArgument Note

Argument 1 of strcasecmp cannot be null, possibly null value provided
$organizerHTML .= ' ✔︎';
$organizerText .= ' ✔︎';
}
Expand Down Expand Up @@ -961,7 +961,7 @@

public function isRoomOrResource(Property $attendee): bool {
$cuType = $attendee->offsetGet('CUTYPE');
if(!$cuType instanceof Parameter) {
if (!$cuType instanceof Parameter) {
return false;
}
$type = $cuType->getValue() ?? 'INDIVIDUAL';
Expand Down
20 changes: 10 additions & 10 deletions apps/dav/lib/CalDAV/Status/StatusService.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,23 +39,23 @@

public function processCalendarStatus(string $userId): void {
$user = $this->userManager->get($userId);
if($user === null) {
if ($user === null) {
return;
}

$availability = $this->availabilityCoordinator->getCurrentOutOfOfficeData($user);
if($availability !== null && $this->availabilityCoordinator->isInEffect($availability)) {
if ($availability !== null && $this->availabilityCoordinator->isInEffect($availability)) {
$this->logger->debug('An Absence is in effect, skipping calendar status check', ['user' => $userId]);
return;
}

$calendarEvents = $this->cache->get($userId);
if($calendarEvents === null) {
if ($calendarEvents === null) {
$calendarEvents = $this->getCalendarEvents($user);
$this->cache->set($userId, $calendarEvents, 300);
}

if(empty($calendarEvents)) {
if (empty($calendarEvents)) {
try {
$this->userStatusService->revertUserStatus($userId, IUserStatus::MESSAGE_CALENDAR_BUSY);
} catch (Exception $e) {
Expand All @@ -81,7 +81,7 @@
$currentStatus = null;
}

if(($currentStatus !== null && $currentStatus->getMessageId() === IUserStatus::MESSAGE_CALL)
if (($currentStatus !== null && $currentStatus->getMessageId() === IUserStatus::MESSAGE_CALL)
|| ($currentStatus !== null && $currentStatus->getStatus() === IUserStatus::DND)
|| ($currentStatus !== null && $currentStatus->getStatus() === IUserStatus::INVISIBLE)) {
// We don't overwrite the call status, DND status or Invisible status
Expand All @@ -101,7 +101,7 @@
if (isset($component['DTSTART']) && $userStatusTimestamp !== null) {
/** @var DateTimeImmutable $dateTime */
$dateTime = $component['DTSTART'][0];
if($dateTime instanceof DateTimeImmutable && $userStatusTimestamp > $dateTime->getTimestamp()) {
if ($dateTime instanceof DateTimeImmutable && $userStatusTimestamp > $dateTime->getTimestamp()) {

Check notice

Code scanning / Psalm

RedundantConditionGivenDocblockType Note

Docblock-defined type DateTimeImmutable for $dateTime is always DateTimeImmutable
return false;
}
}
Expand All @@ -112,7 +112,7 @@
return true;
});

if(empty($applicableEvents)) {
if (empty($applicableEvents)) {
try {
$this->userStatusService->revertUserStatus($userId, IUserStatus::MESSAGE_CALENDAR_BUSY);
} catch (Exception $e) {
Expand All @@ -130,7 +130,7 @@
}

// Only update the status if it's neccesary otherwise we mess up the timestamp
if($currentStatus === null || $currentStatus->getMessageId() !== IUserStatus::MESSAGE_CALENDAR_BUSY) {
if ($currentStatus === null || $currentStatus->getMessageId() !== IUserStatus::MESSAGE_CALENDAR_BUSY) {
// One event that fulfills all status conditions is enough
// 1. Not an OOO event
// 2. Current user status (that is not a calendar status) was not set after the start of this event
Expand All @@ -148,7 +148,7 @@

private function getCalendarEvents(User $user): array {
$calendars = $this->calendarManager->getCalendarsForPrincipal('principals/users/' . $user->getUID());
if(empty($calendars)) {
if (empty($calendars)) {
return [];
}

Expand All @@ -172,7 +172,7 @@
$dtEnd = DateTimeImmutable::createFromMutable($this->timeFactory->getDateTime('+5 minutes'));

// Only query the calendars when there's any to search
if($query instanceof CalendarQuery && !empty($query->getCalendarUris())) {
if ($query instanceof CalendarQuery && !empty($query->getCalendarUris())) {
// Query the next hour
$query->setTimerangeStart($dtStart);
$query->setTimerangeEnd($dtEnd);
Expand Down
6 changes: 3 additions & 3 deletions apps/dav/lib/CalDAV/WebcalCaching/RefreshWebcalService.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,12 @@ public function refreshSubscription(string $principalUri, string $uri) {
}

// Check the refresh rate if there is any
if(!empty($subscription['{http://apple.com/ns/ical/}refreshrate'])) {
if (!empty($subscription['{http://apple.com/ns/ical/}refreshrate'])) {
// add the refresh interval to the lastmodified timestamp
$refreshInterval = new \DateInterval($subscription['{http://apple.com/ns/ical/}refreshrate']);
$updateTime = $this->time->getDateTime();
$updateTime->setTimestamp($subscription['lastmodified'])->add($refreshInterval);
if($updateTime->getTimestamp() > $this->time->getTime()) {
if ($updateTime->getTimestamp() > $this->time->getTime()) {
return;
}
}
Expand Down Expand Up @@ -136,7 +136,7 @@ public function refreshSubscription(string $principalUri, string $uri) {
return $dataSet['uri'];
}, $localData);

if(!empty($ids) && !empty($uris)) {
if (!empty($ids) && !empty($uris)) {
// Clean up on aisle 5
// The only events left over in the $localData array should be those that don't exist upstream
// All deleted VObjects from upstream are removed
Expand Down
Loading
Loading