From: Carl Schwan Date: Thu, 5 May 2022 22:01:08 +0000 (+0200) Subject: Fix more psalm issues X-Git-Tag: v25.0.0beta1~394^2 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=f7be76125f885d66caac4a8d6697e121dce52708;p=nextcloud-server.git Fix more psalm issues Signed-off-by: Carl Schwan --- diff --git a/apps/dav/appinfo/v1/caldav.php b/apps/dav/appinfo/v1/caldav.php index 9036a30f95c..6a496a992e6 100644 --- a/apps/dav/appinfo/v1/caldav.php +++ b/apps/dav/appinfo/v1/caldav.php @@ -100,7 +100,7 @@ $server->setBaseUri($baseuri); // Add plugins $server->addPlugin(new MaintenancePlugin(\OC::$server->getConfig(), \OC::$server->getL10N('dav'))); -$server->addPlugin(new \Sabre\DAV\Auth\Plugin($authBackend, 'ownCloud')); +$server->addPlugin(new \Sabre\DAV\Auth\Plugin($authBackend)); $server->addPlugin(new \Sabre\CalDAV\Plugin()); $server->addPlugin(new LegacyDAVACL()); diff --git a/apps/dav/appinfo/v1/carddav.php b/apps/dav/appinfo/v1/carddav.php index 8dffad16d8d..a0306118781 100644 --- a/apps/dav/appinfo/v1/carddav.php +++ b/apps/dav/appinfo/v1/carddav.php @@ -38,7 +38,6 @@ use OCA\DAV\Connector\Sabre\Principal; use OCP\App\IAppManager; use Psr\Log\LoggerInterface; use Sabre\CardDAV\Plugin; -use Psr\Log\LoggerInterface; $authBackend = new Auth( \OC::$server->getSession(), diff --git a/apps/dav/lib/BackgroundJob/BuildReminderIndexBackgroundJob.php b/apps/dav/lib/BackgroundJob/BuildReminderIndexBackgroundJob.php index 7f1e78248d3..2ae47ee89ea 100644 --- a/apps/dav/lib/BackgroundJob/BuildReminderIndexBackgroundJob.php +++ b/apps/dav/lib/BackgroundJob/BuildReminderIndexBackgroundJob.php @@ -71,12 +71,9 @@ class BuildReminderIndexBackgroundJob extends QueuedJob { $this->timeFactory = $timeFactory; } - /** - * @param $arguments - */ - public function run($arguments) { - $offset = (int) $arguments['offset']; - $stopAt = (int) $arguments['stopAt']; + public function run($argument) { + $offset = (int) $argument['offset']; + $stopAt = (int) $argument['stopAt']; $this->logger->info('Building calendar reminder index (' . $offset .'/' . $stopAt . ')'); diff --git a/apps/dav/lib/BackgroundJob/EventReminderJob.php b/apps/dav/lib/BackgroundJob/EventReminderJob.php index ab7dadd8c0b..55cecf5519d 100644 --- a/apps/dav/lib/BackgroundJob/EventReminderJob.php +++ b/apps/dav/lib/BackgroundJob/EventReminderJob.php @@ -52,12 +52,11 @@ class EventReminderJob extends TimedJob { } /** - * @param $arg * @throws \OCA\DAV\CalDAV\Reminder\NotificationProvider\ProviderNotAvailableException * @throws \OCA\DAV\CalDAV\Reminder\NotificationTypeDoesNotExistException * @throws \OC\User\NoUserException */ - public function run($arg):void { + public function run($argument):void { if ($this->config->getAppValue('dav', 'sendEventReminders', 'yes') !== 'yes') { return; } diff --git a/apps/dav/lib/BackgroundJob/GenerateBirthdayCalendarBackgroundJob.php b/apps/dav/lib/BackgroundJob/GenerateBirthdayCalendarBackgroundJob.php index a338a172d66..8e72e8f076c 100644 --- a/apps/dav/lib/BackgroundJob/GenerateBirthdayCalendarBackgroundJob.php +++ b/apps/dav/lib/BackgroundJob/GenerateBirthdayCalendarBackgroundJob.php @@ -47,12 +47,9 @@ class GenerateBirthdayCalendarBackgroundJob extends QueuedJob { $this->config = $config; } - /** - * @param array $arguments - */ - public function run($arguments) { - $userId = $arguments['userId']; - $purgeBeforeGenerating = $arguments['purgeBeforeGenerating'] ?? false; + public function run($argument) { + $userId = $argument['userId']; + $purgeBeforeGenerating = $argument['purgeBeforeGenerating'] ?? false; // make sure admin didn't change his mind $isGloballyEnabled = $this->config->getAppValue('dav', 'generateBirthdayCalendar', 'yes'); diff --git a/apps/dav/lib/BackgroundJob/UploadCleanup.php b/apps/dav/lib/BackgroundJob/UploadCleanup.php index 76906becb54..f612f58cd7c 100644 --- a/apps/dav/lib/BackgroundJob/UploadCleanup.php +++ b/apps/dav/lib/BackgroundJob/UploadCleanup.php @@ -32,18 +32,15 @@ use OCP\AppFramework\Utility\ITimeFactory; use OCP\BackgroundJob\IJob; use OCP\BackgroundJob\IJobList; use OCP\BackgroundJob\TimedJob; +use OCP\Files\Node; use OCP\Files\File; use OCP\Files\Folder; use OCP\Files\IRootFolder; use OCP\Files\NotFoundException; class UploadCleanup extends TimedJob { - - /** @var IRootFolder */ - private $rootFolder; - - /** @var IJobList */ - private $jobList; + private IRootFolder $rootFolder; + private IJobList $jobList; public function __construct(ITimeFactory $time, IRootFolder $rootFolder, IJobList $jobList) { parent::__construct($time); @@ -71,6 +68,7 @@ class UploadCleanup extends TimedJob { return; } + /** @var File[] $files */ $files = $uploadFolder->getDirectoryListing(); // Remove if all files have an mtime of more than a day diff --git a/apps/dav/lib/CalDAV/BirthdayService.php b/apps/dav/lib/CalDAV/BirthdayService.php index bdcf0796283..1030768e26f 100644 --- a/apps/dav/lib/CalDAV/BirthdayService.php +++ b/apps/dav/lib/CalDAV/BirthdayService.php @@ -53,34 +53,15 @@ use Sabre\VObject\Reader; */ class BirthdayService { public const BIRTHDAY_CALENDAR_URI = 'contact_birthdays'; - - /** @var GroupPrincipalBackend */ - private $principalBackend; - - /** @var CalDavBackend */ - private $calDavBackEnd; - - /** @var CardDavBackend */ - private $cardDavBackEnd; - - /** @var IConfig */ - private $config; - - /** @var IDBConnection */ - private $dbConnection; - - /** @var IL10N */ - private $l10n; + private GroupPrincipalBackend $principalBackend; + private CalDavBackend $calDavBackEnd; + private CardDavBackend $cardDavBackEnd; + private IConfig $config; + private IDBConnection $dbConnection; + private IL10N $l10n; /** * BirthdayService constructor. - * - * @param CalDavBackend $calDavBackEnd - * @param CardDavBackend $cardDavBackEnd - * @param GroupPrincipalBackend $principalBackend - * @param IConfig $config - * @param IDBConnection $dbConnection - * @param IL10N $l10n */ public function __construct(CalDavBackend $calDavBackEnd, CardDavBackend $cardDavBackEnd, @@ -96,14 +77,9 @@ class BirthdayService { $this->l10n = $l10n; } - /** - * @param int $addressBookId - * @param string $cardUri - * @param string $cardData - */ public function onCardChanged(int $addressBookId, string $cardUri, - string $cardData) { + string $cardData): void { if (!$this->isGloballyEnabled()) { return; } @@ -129,12 +105,8 @@ class BirthdayService { } } - /** - * @param int $addressBookId - * @param string $cardUri - */ public function onCardDeleted(int $addressBookId, - string $cardUri) { + string $cardUri): void { if (!$this->isGloballyEnabled()) { return; } @@ -156,11 +128,9 @@ class BirthdayService { } /** - * @param string $principal - * @return array|null * @throws \Sabre\DAV\Exception\BadRequest */ - public function ensureCalendarExists(string $principal):?array { + public function ensureCalendarExists(string $principal): ?array { $calendar = $this->calDavBackEnd->getCalendarByUri($principal, self::BIRTHDAY_CALENDAR_URI); if (!is_null($calendar)) { return $calendar; diff --git a/apps/dav/lib/CalDAV/CachedSubscription.php b/apps/dav/lib/CalDAV/CachedSubscription.php index 18e61450ee9..f42b5f97f5d 100644 --- a/apps/dav/lib/CalDAV/CachedSubscription.php +++ b/apps/dav/lib/CalDAV/CachedSubscription.php @@ -31,6 +31,7 @@ use OCA\DAV\Exception\UnsupportedLimitOnInitialSyncException; use Sabre\CalDAV\Backend\BackendInterface; use Sabre\DAV\Exception\MethodNotAllowed; use Sabre\DAV\Exception\NotFound; +use Sabre\DAV\INode; use Sabre\DAV\PropPatch; /** @@ -51,7 +52,7 @@ class CachedSubscription extends \Sabre\CalDAV\Calendar { /** * @return array */ - public function getACL():array { + public function getACL() { return [ [ 'privilege' => '{DAV:}read', @@ -79,7 +80,7 @@ class CachedSubscription extends \Sabre\CalDAV\Calendar { /** * @return array */ - public function getChildACL():array { + public function getChildACL() { return [ [ 'privilege' => '{DAV:}read', @@ -139,9 +140,9 @@ class CachedSubscription extends \Sabre\CalDAV\Calendar { } /** - * @return array + * @return INode[] */ - public function getChildren():array { + public function getChildren(): array { $objs = $this->caldavBackend->getCalendarObjects($this->calendarInfo['id'], CalDavBackend::CALENDAR_TYPE_SUBSCRIPTION); $children = []; @@ -169,8 +170,8 @@ class CachedSubscription extends \Sabre\CalDAV\Calendar { /** * @param string $name - * @param null $calendarData - * @return null|string|void + * @param null|resource|string $calendarData + * @return null|string * @throws MethodNotAllowed */ public function createFile($name, $calendarData = null) { diff --git a/apps/dav/lib/CalDAV/CachedSubscriptionObject.php b/apps/dav/lib/CalDAV/CachedSubscriptionObject.php index db8c9fa8e80..3c1373763e1 100644 --- a/apps/dav/lib/CalDAV/CachedSubscriptionObject.php +++ b/apps/dav/lib/CalDAV/CachedSubscriptionObject.php @@ -50,7 +50,7 @@ class CachedSubscriptionObject extends \Sabre\CalDAV\CalendarObject { /** * @param resource|string $calendarData - * @return string|void + * @return string * @throws MethodNotAllowed */ public function put($calendarData) { diff --git a/apps/dav/lib/CalDAV/ICSExportPlugin/ICSExportPlugin.php b/apps/dav/lib/CalDAV/ICSExportPlugin/ICSExportPlugin.php index 2a5a6f1bae3..627959c90f6 100644 --- a/apps/dav/lib/CalDAV/ICSExportPlugin/ICSExportPlugin.php +++ b/apps/dav/lib/CalDAV/ICSExportPlugin/ICSExportPlugin.php @@ -23,11 +23,11 @@ namespace OCA\DAV\CalDAV\ICSExportPlugin; use OCP\IConfig; +use Psr\Log\LoggerInterface; use Sabre\HTTP\ResponseInterface; use Sabre\VObject\DateTimeParser; use Sabre\VObject\InvalidDataException; use Sabre\VObject\Property\ICalendar\Duration; -use Psr\Log\LoggerInterface; /** * Class ICSExportPlugin diff --git a/apps/dav/lib/CalDAV/InvitationResponse/InvitationResponseServer.php b/apps/dav/lib/CalDAV/InvitationResponse/InvitationResponseServer.php index 1a70f95aa5f..a85892443cc 100644 --- a/apps/dav/lib/CalDAV/InvitationResponse/InvitationResponseServer.php +++ b/apps/dav/lib/CalDAV/InvitationResponse/InvitationResponseServer.php @@ -37,7 +37,6 @@ use OCA\DAV\RootCollection; use OCP\EventDispatcher\IEventDispatcher; use Psr\Log\LoggerInterface; use Sabre\VObject\ITip\Message; -use Psr\Log\LoggerInterface; class InvitationResponseServer { diff --git a/apps/dav/lib/CalDAV/Publishing/PublishPlugin.php b/apps/dav/lib/CalDAV/Publishing/PublishPlugin.php index 97e942f9da2..aabf78da1aa 100644 --- a/apps/dav/lib/CalDAV/Publishing/PublishPlugin.php +++ b/apps/dav/lib/CalDAV/Publishing/PublishPlugin.php @@ -134,8 +134,8 @@ class PublishPlugin extends ServerPlugin { $canPublish = (!$node->isSubscription() && $node->canWrite()); if ($this->config->getAppValue('dav', 'limitAddressBookAndCalendarSharingToOwner', 'no') === 'yes') { - $canShare &= ($node->getOwner() === $node->getPrincipalURI()); - $canPublish &= ($node->getOwner() === $node->getPrincipalURI()); + $canShare = $canShare && ($node->getOwner() === $node->getPrincipalURI()); + $canPublish = $canPublish && ($node->getOwner() === $node->getPrincipalURI()); } return new AllowedSharingModes($canShare, $canPublish); diff --git a/apps/dav/lib/CalDAV/Reminder/NotificationProvider/EmailProvider.php b/apps/dav/lib/CalDAV/Reminder/NotificationProvider/EmailProvider.php index 7e0020b5f55..c147b47860e 100644 --- a/apps/dav/lib/CalDAV/Reminder/NotificationProvider/EmailProvider.php +++ b/apps/dav/lib/CalDAV/Reminder/NotificationProvider/EmailProvider.php @@ -38,6 +38,7 @@ use OCP\IURLGenerator; use OCP\L10N\IFactory as L10NFactory; use OCP\Mail\IEMailTemplate; use OCP\Mail\IMailer; +use OCP\IUser; use Psr\Log\LoggerInterface; use Sabre\VObject; use Sabre\VObject\Component\VEvent; @@ -54,8 +55,7 @@ class EmailProvider extends AbstractProvider { /** @var string */ public const NOTIFICATION_TYPE = 'EMAIL'; - /** @var IMailer */ - private $mailer; + private IMailer $mailer; public function __construct(IConfig $config, IMailer $mailer, @@ -168,10 +168,6 @@ class EmailProvider extends AbstractProvider { } } - /** - * @param string $path - * @return string - */ private function getAbsoluteImagePath(string $path):string { return $this->urlGenerator->getAbsoluteURL( $this->urlGenerator->imagePath('core', $path) @@ -207,9 +203,8 @@ class EmailProvider extends AbstractProvider { } /** - * @param array $emails - * @param string $defaultLanguage - * @return array + * @param array $emails + * @return array */ private function sortEMailAddressesByLanguage(array $emails, string $defaultLanguage):array { @@ -234,7 +229,7 @@ class EmailProvider extends AbstractProvider { /** * @param VEvent $vevent - * @return array + * @return array */ private function getAllEMailAddressesFromEvent(VEvent $vevent):array { $emailAddresses = []; @@ -277,7 +272,7 @@ class EmailProvider extends AbstractProvider { $properties = []; $langProp = $attendee->offsetGet('LANG'); - if ($langProp instanceof VObject\Parameter) { + if ($langProp instanceof VObject\Parameter && $langProp->getValue() !== null) { $properties['LANG'] = $langProp->getValue(); } @@ -287,18 +282,15 @@ class EmailProvider extends AbstractProvider { } if (isset($vevent->ORGANIZER) && $this->hasAttendeeMailURI($vevent->ORGANIZER)) { - $emailAddresses[$this->getEMailAddressOfAttendee($vevent->ORGANIZER)] = []; + $organizerEmailAddress = $this->getEMailAddressOfAttendee($vevent->ORGANIZER); + if ($organizerEmailAddress !== null) { + $emailAddresses[$organizerEmailAddress] = []; + } } return $emailAddresses; } - - - /** - * @param VObject\Property $attendee - * @return string - */ private function getCUTypeOfAttendee(VObject\Property $attendee):string { $cuType = $attendee->offsetGet('CUTYPE'); if ($cuType instanceof VObject\Parameter) { @@ -308,10 +300,6 @@ class EmailProvider extends AbstractProvider { return 'INDIVIDUAL'; } - /** - * @param VObject\Property $attendee - * @return string - */ private function getPartstatOfAttendee(VObject\Property $attendee):string { $partstat = $attendee->offsetGet('PARTSTAT'); if ($partstat instanceof VObject\Parameter) { @@ -321,19 +309,11 @@ class EmailProvider extends AbstractProvider { return 'NEEDS-ACTION'; } - /** - * @param VObject\Property $attendee - * @return bool - */ - private function hasAttendeeMailURI(VObject\Property $attendee):bool { + private function hasAttendeeMailURI(VObject\Property $attendee): bool { return stripos($attendee->getValue(), 'mailto:') === 0; } - /** - * @param VObject\Property $attendee - * @return string|null - */ - private function getEMailAddressOfAttendee(VObject\Property $attendee):?string { + private function getEMailAddressOfAttendee(VObject\Property $attendee): ?string { if (!$this->hasAttendeeMailURI($attendee)) { return null; } @@ -342,8 +322,8 @@ class EmailProvider extends AbstractProvider { } /** - * @param array $users - * @return array + * @param IUser[] $users + * @return array */ private function getEMailAddressesOfAllUsersWithWriteAccessToCalendar(array $users):array { $emailAddresses = []; @@ -366,12 +346,9 @@ class EmailProvider extends AbstractProvider { } /** - * @param IL10N $l10n - * @param VEvent $vevent - * @return string * @throws \Exception */ - private function generateDateString(IL10N $l10n, VEvent $vevent):string { + private function generateDateString(IL10N $l10n, VEvent $vevent): string { $isAllDay = $vevent->DTSTART instanceof Property\ICalendar\Date; /** @var Property\ICalendar\Date | Property\ICalendar\DateTime $dtstart */ @@ -437,57 +414,27 @@ class EmailProvider extends AbstractProvider { . ' (' . $startTimezone . ')'; } - /** - * @param DateTime $dtStart - * @param DateTime $dtEnd - * @return bool - */ private function isDayEqual(DateTime $dtStart, DateTime $dtEnd):bool { return $dtStart->format('Y-m-d') === $dtEnd->format('Y-m-d'); } - /** - * @param IL10N $l10n - * @param DateTime $dt - * @return string - */ private function getWeekDayName(IL10N $l10n, DateTime $dt):string { - return $l10n->l('weekdayName', $dt, ['width' => 'abbreviated']); + return (string)$l10n->l('weekdayName', $dt, ['width' => 'abbreviated']); } - /** - * @param IL10N $l10n - * @param DateTime $dt - * @return string - */ private function getDateString(IL10N $l10n, DateTime $dt):string { - return $l10n->l('date', $dt, ['width' => 'medium']); + return (string)$l10n->l('date', $dt, ['width' => 'medium']); } - /** - * @param IL10N $l10n - * @param DateTime $dt - * @return string - */ private function getDateTimeString(IL10N $l10n, DateTime $dt):string { - return $l10n->l('datetime', $dt, ['width' => 'medium|short']); + return (string)$l10n->l('datetime', $dt, ['width' => 'medium|short']); } - /** - * @param IL10N $l10n - * @param DateTime $dt - * @return string - */ private function getTimeString(IL10N $l10n, DateTime $dt):string { - return $l10n->l('time', $dt, ['width' => 'short']); + return (string)$l10n->l('time', $dt, ['width' => 'short']); } - /** - * @param VEvent $vevent - * @param IL10N $l10n - * @return string - */ private function getTitleFromVEvent(VEvent $vevent, IL10N $l10n):string { if (isset($vevent->SUMMARY)) { return (string)$vevent->SUMMARY; diff --git a/apps/dav/lib/CalDAV/Reminder/NotificationProvider/PushProvider.php b/apps/dav/lib/CalDAV/Reminder/NotificationProvider/PushProvider.php index 298297fdc38..cb873020c38 100644 --- a/apps/dav/lib/CalDAV/Reminder/NotificationProvider/PushProvider.php +++ b/apps/dav/lib/CalDAV/Reminder/NotificationProvider/PushProvider.php @@ -109,8 +109,6 @@ class PushProvider extends AbstractProvider { } /** - * @var VEvent $vevent - * @return array * @throws \Exception */ protected function extractEventDetails(VEvent $vevent):array { diff --git a/apps/dav/lib/CalDAV/Reminder/Notifier.php b/apps/dav/lib/CalDAV/Reminder/Notifier.php index 8535c55054a..c658ef2ff01 100644 --- a/apps/dav/lib/CalDAV/Reminder/Notifier.php +++ b/apps/dav/lib/CalDAV/Reminder/Notifier.php @@ -298,7 +298,7 @@ class Notifier implements INotifier { * @return string */ private function getWeekDayName(DateTime $dt):string { - return $this->l10n->l('weekdayName', $dt, ['width' => 'abbreviated']); + return (string)$this->l10n->l('weekdayName', $dt, ['width' => 'abbreviated']); } /** @@ -306,7 +306,7 @@ class Notifier implements INotifier { * @return string */ private function getDateString(DateTime $dt):string { - return $this->l10n->l('date', $dt, ['width' => 'medium']); + return (string)$this->l10n->l('date', $dt, ['width' => 'medium']); } /** @@ -314,7 +314,7 @@ class Notifier implements INotifier { * @return string */ private function getDateTimeString(DateTime $dt):string { - return $this->l10n->l('datetime', $dt, ['width' => 'medium|short']); + return (string)$this->l10n->l('datetime', $dt, ['width' => 'medium|short']); } /** @@ -322,6 +322,6 @@ class Notifier implements INotifier { * @return string */ private function getTimeString(DateTime $dt):string { - return $this->l10n->l('time', $dt, ['width' => 'short']); + return (string)$this->l10n->l('time', $dt, ['width' => 'short']); } } diff --git a/apps/dav/lib/CardDAV/CardDavBackend.php b/apps/dav/lib/CardDAV/CardDavBackend.php index 1c1754ff752..35df5c0b8ca 100644 --- a/apps/dav/lib/CardDAV/CardDavBackend.php +++ b/apps/dav/lib/CardDAV/CardDavBackend.php @@ -291,16 +291,15 @@ class CardDavBackend implements BackendInterface, SyncSupport { /** * @param int $addressBookId */ - public function getAddressBookById($addressBookId) { + public function getAddressBookById(int $addressBookId): ?array { $query = $this->db->getQueryBuilder(); $result = $query->select(['id', 'uri', 'displayname', 'principaluri', 'description', 'synctoken']) ->from('addressbooks') - ->where($query->expr()->eq('id', $query->createNamedParameter($addressBookId))) - ->execute(); - + ->where($query->expr()->eq('id', $query->createNamedParameter($addressBookId, IQueryBuilder::PARAM_INT))) + ->executeQuery(); $row = $result->fetch(); $result->closeCursor(); - if ($row === false) { + if (!$row) { return null; } @@ -457,7 +456,7 @@ class CardDavBackend implements BackendInterface, SyncSupport { $addressBookId = $query->getLastInsertId(); $addressBookRow = $this->getAddressBookById($addressBookId); - $this->dispatcher->dispatchTyped(new AddressBookCreatedEvent((int)$addressBookId, $addressBookRow)); + $this->dispatcher->dispatchTyped(new AddressBookCreatedEvent($addressBookId, $addressBookRow)); return $addressBookId; } @@ -495,7 +494,7 @@ class CardDavBackend implements BackendInterface, SyncSupport { ->execute(); if ($addressBookData) { - $this->dispatcher->dispatchTyped(new AddressBookDeletedEvent((int) $addressBookId, $addressBookData, $shares)); + $this->dispatcher->dispatchTyped(new AddressBookDeletedEvent($addressBookId, $addressBookData, $shares)); } } @@ -515,14 +514,14 @@ class CardDavBackend implements BackendInterface, SyncSupport { * calculating them. If they are specified, you can also ommit carddata. * This may speed up certain requests, especially with large cards. * - * @param mixed $addressBookId + * @param mixed $addressbookId * @return array */ - public function getCards($addressBookId) { + public function getCards($addressbookId) { $query = $this->db->getQueryBuilder(); $query->select(['id', 'uri', 'lastmodified', 'etag', 'size', 'carddata', 'uid']) ->from($this->dbCardsTable) - ->where($query->expr()->eq('addressbookid', $query->createNamedParameter($addressBookId))); + ->where($query->expr()->eq('addressbookid', $query->createNamedParameter($addressbookId))); $cards = []; @@ -588,7 +587,7 @@ class CardDavBackend implements BackendInterface, SyncSupport { * If the backend supports this, it may allow for some speed-ups. * * @param mixed $addressBookId - * @param string[] $uris + * @param array $uris * @return array */ public function getMultipleCards($addressBookId, array $uris) { @@ -689,7 +688,7 @@ class CardDavBackend implements BackendInterface, SyncSupport { $addressBookData = $this->getAddressBookById($addressBookId); $shares = $this->getShares($addressBookId); $objectRow = $this->getCard($addressBookId, $cardUri); - $this->dispatcher->dispatchTyped(new CardCreatedEvent((int)$addressBookId, $addressBookData, $shares, $objectRow)); + $this->dispatcher->dispatchTyped(new CardCreatedEvent($addressBookId, $addressBookData, $shares, $objectRow)); $this->legacyDispatcher->dispatch('\OCA\DAV\CardDAV\CardDavBackend::createCard', new GenericEvent(null, [ 'addressBookId' => $addressBookId, @@ -753,7 +752,7 @@ class CardDavBackend implements BackendInterface, SyncSupport { $addressBookData = $this->getAddressBookById($addressBookId); $shares = $this->getShares($addressBookId); $objectRow = $this->getCard($addressBookId, $cardUri); - $this->dispatcher->dispatchTyped(new CardUpdatedEvent((int)$addressBookId, $addressBookData, $shares, $objectRow)); + $this->dispatcher->dispatchTyped(new CardUpdatedEvent($addressBookId, $addressBookData, $shares, $objectRow)); $this->legacyDispatcher->dispatch('\OCA\DAV\CardDAV\CardDavBackend::updateCard', new GenericEvent(null, [ 'addressBookId' => $addressBookId, @@ -784,13 +783,13 @@ class CardDavBackend implements BackendInterface, SyncSupport { $ret = $query->delete($this->dbCardsTable) ->where($query->expr()->eq('addressbookid', $query->createNamedParameter($addressBookId))) ->andWhere($query->expr()->eq('uri', $query->createNamedParameter($cardUri))) - ->execute(); + ->executeStatement(); $this->addChange($addressBookId, $cardUri, 3); if ($ret === 1) { if ($cardId !== null) { - $this->dispatcher->dispatchTyped(new CardDeletedEvent((int)$addressBookId, $addressBookData, $shares, $objectRow)); + $this->dispatcher->dispatchTyped(new CardDeletedEvent($addressBookId, $addressBookData, $shares, $objectRow)); $this->legacyDispatcher->dispatch('\OCA\DAV\CardDAV\CardDavBackend::deleteCard', new GenericEvent(null, [ 'addressBookId' => $addressBookId, @@ -868,12 +867,12 @@ class CardDavBackend implements BackendInterface, SyncSupport { ->where( $qb->expr()->eq('id', $qb->createNamedParameter($addressBookId)) ); - $stmt = $qb->execute(); + $stmt = $qb->executeQuery(); $currentToken = $stmt->fetchOne(); $stmt->closeCursor(); if (is_null($currentToken)) { - return null; + return []; } $result = [ @@ -900,7 +899,7 @@ class CardDavBackend implements BackendInterface, SyncSupport { } // Fetching all changes - $stmt = $qb->execute(); + $stmt = $qb->executeQuery(); $changes = []; @@ -932,7 +931,7 @@ class CardDavBackend implements BackendInterface, SyncSupport { $qb->expr()->eq('addressbookid', $qb->createNamedParameter($addressBookId)) ); // No synctoken supplied, this is the initial sync. - $stmt = $qb->execute(); + $stmt = $qb->executeQuery(); $result['added'] = $stmt->fetchAll(\PDO::FETCH_COLUMN); $stmt->closeCursor(); } diff --git a/apps/dav/lib/CardDAV/PhotoCache.php b/apps/dav/lib/CardDAV/PhotoCache.php index 3051d2d48ba..777a0b0e169 100644 --- a/apps/dav/lib/CardDAV/PhotoCache.php +++ b/apps/dav/lib/CardDAV/PhotoCache.php @@ -63,15 +63,9 @@ class PhotoCache { } /** - * @param int $addressBookId - * @param string $cardUri - * @param int $size - * @param Card $card - * - * @return ISimpleFile * @throws NotFoundException */ - public function get($addressBookId, $cardUri, $size, Card $card) { + public function get(int $addressBookId, string $cardUri, int $size, Card $card): ISimpleFile { $folder = $this->getFolder($addressBookId, $cardUri); if ($this->isEmpty($folder)) { @@ -120,7 +114,10 @@ class PhotoCache { return !$folder->fileExists('nophoto'); } - private function getFile(ISimpleFolder $folder, int $size): ISimpleFile { + /** + * @param float|-1 $size + */ + private function getFile(ISimpleFolder $folder, $size): ISimpleFile { $ext = $this->getExtension($folder); if ($size === -1) { diff --git a/apps/dav/lib/CardDAV/SyncService.php b/apps/dav/lib/CardDAV/SyncService.php index b93fd94f741..95fdf1d21da 100644 --- a/apps/dav/lib/CardDAV/SyncService.php +++ b/apps/dav/lib/CardDAV/SyncService.php @@ -86,7 +86,7 @@ class SyncService { */ public function syncRemoteAddressBook($url, $userName, $addressBookUrl, $sharedSecret, $syncToken, $targetBookId, $targetPrincipal, $targetProperties) { // 1. create addressbook - $book = $this->ensureSystemAddressBookExists($targetPrincipal, $targetBookId, $targetProperties); + $book = $this->ensureSystemAddressBookExists($targetPrincipal, (string)$targetBookId, $targetProperties); $addressBookId = $book['id']; // 2. query changes diff --git a/apps/dav/lib/Connector/PublicAuth.php b/apps/dav/lib/Connector/PublicAuth.php index ba5e635e5f3..cc51a249e75 100644 --- a/apps/dav/lib/Connector/PublicAuth.php +++ b/apps/dav/lib/Connector/PublicAuth.php @@ -44,7 +44,7 @@ use Sabre\DAV\Auth\Backend\AbstractBasic; */ class PublicAuth extends AbstractBasic { private const BRUTEFORCE_ACTION = 'public_webdav_auth'; - private IShare $share; + private ?IShare $share = null; private IManager $shareManager; private ISession $session; private IRequest $request; @@ -121,6 +121,7 @@ class PublicAuth extends AbstractBasic { } public function getShare(): IShare { + assert($this->share !== null); return $this->share; } } diff --git a/apps/dav/lib/Connector/Sabre/Auth.php b/apps/dav/lib/Connector/Sabre/Auth.php index 1588e5a2e6c..1610c554b9b 100644 --- a/apps/dav/lib/Connector/Sabre/Auth.php +++ b/apps/dav/lib/Connector/Sabre/Auth.php @@ -54,7 +54,7 @@ class Auth extends AbstractBasic { private ISession $session; private Session $userSession; private IRequest $request; - private string $currentUser; + private ?string $currentUser = null; private Manager $twoFactorManager; private Throttler $throttler; diff --git a/apps/dav/lib/Connector/Sabre/BlockLegacyClientPlugin.php b/apps/dav/lib/Connector/Sabre/BlockLegacyClientPlugin.php index 830c92d2c30..2d2be631416 100644 --- a/apps/dav/lib/Connector/Sabre/BlockLegacyClientPlugin.php +++ b/apps/dav/lib/Connector/Sabre/BlockLegacyClientPlugin.php @@ -37,7 +37,7 @@ use Sabre\DAV\Server; * @package OCA\DAV\Connector\Sabre */ class BlockLegacyClientPlugin extends ServerPlugin { - protected Server $server; + protected ?Server $server = null; protected IConfig $config; public function __construct(IConfig $config) { diff --git a/apps/dav/lib/Connector/Sabre/ChecksumUpdatePlugin.php b/apps/dav/lib/Connector/Sabre/ChecksumUpdatePlugin.php index c023d918c42..c222923bc8e 100644 --- a/apps/dav/lib/Connector/Sabre/ChecksumUpdatePlugin.php +++ b/apps/dav/lib/Connector/Sabre/ChecksumUpdatePlugin.php @@ -29,7 +29,7 @@ use Sabre\HTTP\ResponseInterface; use Sabre\DAV\Server; class ChecksumUpdatePlugin extends ServerPlugin { - protected Server $server; + protected ?Server $server = null; public function initialize(Server $server) { $this->server = $server; diff --git a/apps/dav/lib/Connector/Sabre/CommentPropertiesPlugin.php b/apps/dav/lib/Connector/Sabre/CommentPropertiesPlugin.php index f9a087daeb0..4a1205e8606 100644 --- a/apps/dav/lib/Connector/Sabre/CommentPropertiesPlugin.php +++ b/apps/dav/lib/Connector/Sabre/CommentPropertiesPlugin.php @@ -36,7 +36,7 @@ class CommentPropertiesPlugin extends ServerPlugin { public const PROPERTY_NAME_COUNT = '{http://owncloud.org/ns}comments-count'; public const PROPERTY_NAME_UNREAD = '{http://owncloud.org/ns}comments-unread'; - protected Server $server; + protected ?Server $server = null; private ICommentsManager $commentsManager; private IUserSession $userSession; private array $cachedUnreadCount = []; diff --git a/apps/dav/lib/Connector/Sabre/CopyEtagHeaderPlugin.php b/apps/dav/lib/Connector/Sabre/CopyEtagHeaderPlugin.php index 5dd0dc6f231..f3ea94be3b6 100644 --- a/apps/dav/lib/Connector/Sabre/CopyEtagHeaderPlugin.php +++ b/apps/dav/lib/Connector/Sabre/CopyEtagHeaderPlugin.php @@ -35,7 +35,7 @@ use Sabre\DAV\Server; * or mangle Etag headers. */ class CopyEtagHeaderPlugin extends \Sabre\DAV\ServerPlugin { - private Server $server; + private ?Server $server = null; /** * This initializes the plugin. diff --git a/apps/dav/lib/Connector/Sabre/DummyGetResponsePlugin.php b/apps/dav/lib/Connector/Sabre/DummyGetResponsePlugin.php index bc6c6f5c25f..8e35afe2e7c 100644 --- a/apps/dav/lib/Connector/Sabre/DummyGetResponsePlugin.php +++ b/apps/dav/lib/Connector/Sabre/DummyGetResponsePlugin.php @@ -44,7 +44,7 @@ use Sabre\DAV\Server; * @package OCA\DAV\Connector\Sabre */ class DummyGetResponsePlugin extends \Sabre\DAV\ServerPlugin { - protected Server $server; + protected ?Server $server = null; /** * @param \Sabre\DAV\Server $server diff --git a/apps/dav/lib/Connector/Sabre/ExceptionLoggerPlugin.php b/apps/dav/lib/Connector/Sabre/ExceptionLoggerPlugin.php index c803358ede1..ea94b5c8933 100644 --- a/apps/dav/lib/Connector/Sabre/ExceptionLoggerPlugin.php +++ b/apps/dav/lib/Connector/Sabre/ExceptionLoggerPlugin.php @@ -112,7 +112,7 @@ class ExceptionLoggerPlugin extends \Sabre\DAV\ServerPlugin { /** * Log exception */ - public function logException(\Throwable $ex): void { + public function logException(\Throwable $ex) { $exceptionClass = get_class($ex); if (isset($this->nonFatalExceptions[$exceptionClass]) || ( diff --git a/apps/dav/lib/Connector/Sabre/FilesPlugin.php b/apps/dav/lib/Connector/Sabre/FilesPlugin.php index 9474ed91f85..b784764f8fe 100644 --- a/apps/dav/lib/Connector/Sabre/FilesPlugin.php +++ b/apps/dav/lib/Connector/Sabre/FilesPlugin.php @@ -86,7 +86,7 @@ class FilesPlugin extends ServerPlugin { public const FILE_METADATA_SIZE = '{http://nextcloud.org/ns}file-metadata-size'; /** Reference to main server object */ - private Server $server; + private ?Server $server = null; private Tree $tree; private IUserSession $userSession; @@ -345,7 +345,7 @@ class FilesPlugin extends ServerPlugin { $propFind->handle(self::HAS_PREVIEW_PROPERTYNAME, function () use ($node) { return json_encode($this->previewManager->isAvailable($node->getFileInfo())); }); - $propFind->handle(self::SIZE_PROPERTYNAME, function () use ($node): int { + $propFind->handle(self::SIZE_PROPERTYNAME, function () use ($node): ?int { return $node->getSize(); }); $propFind->handle(self::MOUNT_TYPE_PROPERTYNAME, function () use ($node) { diff --git a/apps/dav/tests/unit/Files/FileSearchBackendTest.php b/apps/dav/tests/unit/Files/FileSearchBackendTest.php index dec5db1b1b0..da682a5fb21 100644 --- a/apps/dav/tests/unit/Files/FileSearchBackendTest.php +++ b/apps/dav/tests/unit/Files/FileSearchBackendTest.php @@ -29,7 +29,7 @@ namespace OCA\DAV\Tests\Files; use OC\Files\Search\SearchComparison; use OC\Files\Search\SearchQuery; use OC\Files\View; -use OCA\DAV\Connector\Sabre\CachingTree; +use OCA\DAV\Connector\Sabre\ObjectTree; use OCA\DAV\Connector\Sabre\Directory; use OCA\DAV\Connector\Sabre\File; use OCA\DAV\Connector\Sabre\FilesPlugin; @@ -48,7 +48,7 @@ use SearchDAV\Query\Query; use Test\TestCase; class FileSearchBackendTest extends TestCase { - /** @var CachingTree|\PHPUnit\Framework\MockObject\MockObject */ + /** @var ObjectTree|\PHPUnit\Framework\MockObject\MockObject */ private $tree; /** @var IUser */ @@ -80,7 +80,7 @@ class FileSearchBackendTest extends TestCase { ->method('getUID') ->willReturn('test'); - $this->tree = $this->getMockBuilder(CachingTree::class) + $this->tree = $this->getMockBuilder(ObjectTree::class) ->disableOriginalConstructor() ->getMock(); diff --git a/build/psalm-baseline.xml b/build/psalm-baseline.xml index d3d497e7e3c..cc644443d51 100644 --- a/build/psalm-baseline.xml +++ b/build/psalm-baseline.xml @@ -55,9 +55,6 @@ - - new \Sabre\DAV\Auth\Plugin($authBackend, 'ownCloud') - $baseuri @@ -122,26 +119,6 @@ Uri\split($this->principalInfo['uri']) - - - $arguments - - - - - $arg - - - - - $arguments - - - - - File - - setDateTime @@ -155,20 +132,11 @@ - - array - - - $calendarData - $calendarData - - string|void - $this->objectData['calendardata'] @@ -263,16 +231,6 @@ $paths - - - $canPublish - $canShare - - - $canPublish - $canShare - - hasTime @@ -281,60 +239,17 @@ - - $l10n->l('date', $dt, ['width' => 'medium']) - $l10n->l('datetime', $dt, ['width' => 'medium|short']) - $l10n->l('time', $dt, ['width' => 'short']) - $l10n->l('weekdayName', $dt, ['width' => 'abbreviated']) - - - $l10n->l('date', $dt, ['width' => 'medium']) - $l10n->l('datetime', $dt, ['width' => 'medium|short']) - $l10n->l('time', $dt, ['width' => 'short']) - $l10n->l('weekdayName', $dt, ['width' => 'abbreviated']) - - - string - string - string - string - getDateTime getDateTime isFloating - - - @var VEvent $vevent - - $provider::NOTIFICATION_TYPE - - - $this->l10n->l('date', $dt, ['width' => 'medium']) - $this->l10n->l('datetime', $dt, ['width' => 'medium|short']) - $this->l10n->l('time', $dt, ['width' => 'short']) - $this->l10n->l('weekdayName', $dt, ['width' => 'abbreviated']) - - - $this->l10n->l('date', $dt, ['width' => 'medium']) - $this->l10n->l('datetime', $dt, ['width' => 'medium|short']) - $this->l10n->l('time', $dt, ['width' => 'short']) - $this->l10n->l('weekdayName', $dt, ['width' => 'abbreviated']) - - - string - string - string - string - - getDateInterval @@ -457,21 +372,6 @@ '\OCA\DAV\CardDAV\CardDavBackend::deleteCard' '\OCA\DAV\CardDAV\CardDavBackend::updateCard' - - array - - - $uris - - - null - - - $addressBookId - - - (int)$addressBookId - dispatch dispatch @@ -511,11 +411,6 @@ \Sabre\Uri\split($principal) - - - $targetBookId - - $this->principalUri