From 829490ab7a02579c6b31573c3f53428e86cbf2e0 Mon Sep 17 00:00:00 2001 From: Carl Schwan Date: Tue, 12 Apr 2022 14:01:13 +0200 Subject: [PATCH 1/2] Cleanup dav - Remove unused class AppEnabledPlugin - Add more type hinting when possible Signed-off-by: Carl Schwan --- apps/dav/appinfo/v1/carddav.php | 1 + apps/dav/appinfo/v1/publicwebdav.php | 5 +- apps/dav/appinfo/v1/webdav.php | 4 +- .../composer/composer/autoload_classmap.php | 1 - .../dav/composer/composer/autoload_static.php | 1 - .../ICSExportPlugin/ICSExportPlugin.php | 7 +- .../InvitationResponseServer.php | 3 +- apps/dav/lib/CardDAV/PhotoCache.php | 31 ++----- apps/dav/lib/Connector/PublicAuth.php | 35 ++------ .../lib/Connector/Sabre/AppEnabledPlugin.php | 88 ------------------- apps/dav/lib/Connector/Sabre/Auth.php | 47 +++------- apps/dav/lib/Connector/Sabre/BearerAuth.php | 20 ++--- .../Sabre/BlockLegacyClientPlugin.php | 13 +-- apps/dav/lib/Connector/Sabre/CachingTree.php | 9 +- apps/dav/lib/Connector/Sabre/ChecksumList.php | 7 +- .../Connector/Sabre/ChecksumUpdatePlugin.php | 10 +-- .../Sabre/CommentPropertiesPlugin.php | 40 +++------ .../Connector/Sabre/CopyEtagHeaderPlugin.php | 4 +- apps/dav/lib/Connector/Sabre/Directory.php | 25 ++---- .../Sabre/DummyGetResponsePlugin.php | 4 +- .../Connector/Sabre/ExceptionLoggerPlugin.php | 21 ++--- apps/dav/lib/Connector/Sabre/FilesPlugin.php | 81 +++++------------ .../dav/lib/Connector/Sabre/ServerFactory.php | 37 +++----- apps/dav/lib/Connector/Sabre/SharesPlugin.php | 50 ++++------- apps/dav/lib/Server.php | 3 +- build/psalm-baseline.xml | 5 -- 26 files changed, 145 insertions(+), 407 deletions(-) delete mode 100644 apps/dav/lib/Connector/Sabre/AppEnabledPlugin.php diff --git a/apps/dav/appinfo/v1/carddav.php b/apps/dav/appinfo/v1/carddav.php index a0306118781ef..8dffad16d8d78 100644 --- a/apps/dav/appinfo/v1/carddav.php +++ b/apps/dav/appinfo/v1/carddav.php @@ -38,6 +38,7 @@ 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/appinfo/v1/publicwebdav.php b/apps/dav/appinfo/v1/publicwebdav.php index 43b472c107b08..389461f94b1ea 100644 --- a/apps/dav/appinfo/v1/publicwebdav.php +++ b/apps/dav/appinfo/v1/publicwebdav.php @@ -29,6 +29,9 @@ * along with this program. If not, see * */ + +use Psr\Log\LoggerInterface; + // load needed apps $RUNTIME_APPTYPES = ['filesystem', 'authentication', 'logging']; @@ -48,7 +51,7 @@ $serverFactory = new OCA\DAV\Connector\Sabre\ServerFactory( \OC::$server->getConfig(), - \OC::$server->get(Psr\Log\LoggerInterface::class), + \OC::$server->get(LoggerInterface::class), \OC::$server->getDatabaseConnection(), \OC::$server->getUserSession(), \OC::$server->getMountManager(), diff --git a/apps/dav/appinfo/v1/webdav.php b/apps/dav/appinfo/v1/webdav.php index e39a6b48d570f..8dbe846f3ffbd 100644 --- a/apps/dav/appinfo/v1/webdav.php +++ b/apps/dav/appinfo/v1/webdav.php @@ -28,6 +28,8 @@ * along with this program. If not, see * */ +use Psr\Log\LoggerInterface; + // no php execution timeout for webdav if (strpos(@ini_get('disable_functions'), 'set_time_limit') === false) { @set_time_limit(0); @@ -39,7 +41,7 @@ $serverFactory = new \OCA\DAV\Connector\Sabre\ServerFactory( \OC::$server->getConfig(), - \OC::$server->get(Psr\Log\LoggerInterface::class), + \OC::$server->get(LoggerInterface::class), \OC::$server->getDatabaseConnection(), \OC::$server->getUserSession(), \OC::$server->getMountManager(), diff --git a/apps/dav/composer/composer/autoload_classmap.php b/apps/dav/composer/composer/autoload_classmap.php index 5f7815a9bfc8b..0583b94a86c37 100644 --- a/apps/dav/composer/composer/autoload_classmap.php +++ b/apps/dav/composer/composer/autoload_classmap.php @@ -139,7 +139,6 @@ 'OCA\\DAV\\Connector\\LegacyDAVACL' => $baseDir . '/../lib/Connector/LegacyDAVACL.php', 'OCA\\DAV\\Connector\\PublicAuth' => $baseDir . '/../lib/Connector/PublicAuth.php', 'OCA\\DAV\\Connector\\Sabre\\AnonymousOptionsPlugin' => $baseDir . '/../lib/Connector/Sabre/AnonymousOptionsPlugin.php', - 'OCA\\DAV\\Connector\\Sabre\\AppEnabledPlugin' => $baseDir . '/../lib/Connector/Sabre/AppEnabledPlugin.php', 'OCA\\DAV\\Connector\\Sabre\\Auth' => $baseDir . '/../lib/Connector/Sabre/Auth.php', 'OCA\\DAV\\Connector\\Sabre\\BearerAuth' => $baseDir . '/../lib/Connector/Sabre/BearerAuth.php', 'OCA\\DAV\\Connector\\Sabre\\BlockLegacyClientPlugin' => $baseDir . '/../lib/Connector/Sabre/BlockLegacyClientPlugin.php', diff --git a/apps/dav/composer/composer/autoload_static.php b/apps/dav/composer/composer/autoload_static.php index 1f57b8b043afc..301be38246a37 100644 --- a/apps/dav/composer/composer/autoload_static.php +++ b/apps/dav/composer/composer/autoload_static.php @@ -154,7 +154,6 @@ class ComposerStaticInitDAV 'OCA\\DAV\\Connector\\LegacyDAVACL' => __DIR__ . '/..' . '/../lib/Connector/LegacyDAVACL.php', 'OCA\\DAV\\Connector\\PublicAuth' => __DIR__ . '/..' . '/../lib/Connector/PublicAuth.php', 'OCA\\DAV\\Connector\\Sabre\\AnonymousOptionsPlugin' => __DIR__ . '/..' . '/../lib/Connector/Sabre/AnonymousOptionsPlugin.php', - 'OCA\\DAV\\Connector\\Sabre\\AppEnabledPlugin' => __DIR__ . '/..' . '/../lib/Connector/Sabre/AppEnabledPlugin.php', 'OCA\\DAV\\Connector\\Sabre\\Auth' => __DIR__ . '/..' . '/../lib/Connector/Sabre/Auth.php', 'OCA\\DAV\\Connector\\Sabre\\BearerAuth' => __DIR__ . '/..' . '/../lib/Connector/Sabre/BearerAuth.php', 'OCA\\DAV\\Connector\\Sabre\\BlockLegacyClientPlugin' => __DIR__ . '/..' . '/../lib/Connector/Sabre/BlockLegacyClientPlugin.php', diff --git a/apps/dav/lib/CalDAV/ICSExportPlugin/ICSExportPlugin.php b/apps/dav/lib/CalDAV/ICSExportPlugin/ICSExportPlugin.php index 0c76e4f5e10f6..2a5a6f1bae395 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 @@ -35,10 +35,7 @@ * @package OCA\DAV\CalDAV\ICSExportPlugin */ class ICSExportPlugin extends \Sabre\CalDAV\ICSExportPlugin { - - /** @var IConfig */ - private $config; - + private IConfig $config; private LoggerInterface $logger; /** @var string */ diff --git a/apps/dav/lib/CalDAV/InvitationResponse/InvitationResponseServer.php b/apps/dav/lib/CalDAV/InvitationResponse/InvitationResponseServer.php index c8da92c827792..1a70f95aa5f69 100644 --- a/apps/dav/lib/CalDAV/InvitationResponse/InvitationResponseServer.php +++ b/apps/dav/lib/CalDAV/InvitationResponse/InvitationResponseServer.php @@ -37,6 +37,7 @@ use OCP\EventDispatcher\IEventDispatcher; use Psr\Log\LoggerInterface; use Sabre\VObject\ITip\Message; +use Psr\Log\LoggerInterface; class InvitationResponseServer { @@ -100,7 +101,7 @@ public function __construct(bool $public = true) { )); // wait with registering these until auth is handled and the filesystem is setup - $this->server->on('beforeMethod:*', function () use ($root) { + $this->server->on('beforeMethod:*', function () use ($root): void { // register plugins from apps $pluginManager = new PluginManager( \OC::$server, diff --git a/apps/dav/lib/CardDAV/PhotoCache.php b/apps/dav/lib/CardDAV/PhotoCache.php index 66391b268a632..3051d2d48ba96 100644 --- a/apps/dav/lib/CardDAV/PhotoCache.php +++ b/apps/dav/lib/CardDAV/PhotoCache.php @@ -34,12 +34,12 @@ use OCP\Files\NotPermittedException; use OCP\Files\SimpleFS\ISimpleFile; use OCP\Files\SimpleFS\ISimpleFolder; -use Psr\Log\LoggerInterface; use Sabre\CardDAV\Card; use Sabre\VObject\Document; use Sabre\VObject\Parameter; use Sabre\VObject\Property\Binary; use Sabre\VObject\Reader; +use Psr\Log\LoggerInterface; class PhotoCache { @@ -51,9 +51,7 @@ class PhotoCache { 'image/vnd.microsoft.icon' => 'ico', ]; - /** @var IAppData */ - protected $appData; - + protected IAppData $appData; protected LoggerInterface $logger; /** @@ -91,17 +89,11 @@ public function get($addressBookId, $cardUri, $size, Card $card) { return $this->getFile($folder, $size); } - /** - * @param ISimpleFolder $folder - * @return bool - */ - private function isEmpty(ISimpleFolder $folder) { + private function isEmpty(ISimpleFolder $folder): bool { return $folder->getDirectoryListing() === []; } /** - * @param ISimpleFolder $folder - * @param Card $card * @throws NotPermittedException */ private function init(ISimpleFolder $folder, Card $card): void { @@ -124,11 +116,11 @@ private function init(ISimpleFolder $folder, Card $card): void { $file->putContent($data['body']); } - private function hasPhoto(ISimpleFolder $folder) { + private function hasPhoto(ISimpleFolder $folder): bool { return !$folder->fileExists('nophoto'); } - private function getFile(ISimpleFolder $folder, $size) { + private function getFile(ISimpleFolder $folder, int $size): ISimpleFile { $ext = $this->getExtension($folder); if ($size === -1) { @@ -189,8 +181,6 @@ private function getFolder(int $addressBookId, string $cardUri, bool $createIfNo /** * Get the extension of the avatar. If there is no avatar throw Exception * - * @param ISimpleFolder $folder - * @return string * @throws NotFoundException */ private function getExtension(ISimpleFolder $folder): string { @@ -205,7 +195,7 @@ private function getExtension(ISimpleFolder $folder): string { /** * @param Card $node - * @return bool|array{body: string, Content-Type: string} + * @return false|array{body: string, Content-Type: string} */ private function getPhoto(Card $node) { try { @@ -220,8 +210,7 @@ private function getPhoto(Card $node) { } /** - * @param Document $vObject - * @return bool|array{body: string, Content-Type: string} + * @return false|array{body: string, Content-Type: string} */ public function getPhotoFromVObject(Document $vObject) { try { @@ -265,11 +254,7 @@ public function getPhotoFromVObject(Document $vObject) { return false; } - /** - * @param string $cardData - * @return \Sabre\VObject\Document - */ - private function readCard($cardData) { + private function readCard(string $cardData): Document { return Reader::read($cardData); } diff --git a/apps/dav/lib/Connector/PublicAuth.php b/apps/dav/lib/Connector/PublicAuth.php index 426cbf871d71c..ba5e635e5f353 100644 --- a/apps/dav/lib/Connector/PublicAuth.php +++ b/apps/dav/lib/Connector/PublicAuth.php @@ -44,28 +44,12 @@ */ class PublicAuth extends AbstractBasic { private const BRUTEFORCE_ACTION = 'public_webdav_auth'; + private IShare $share; + private IManager $shareManager; + private ISession $session; + private IRequest $request; + private Throttler $throttler; - /** @var \OCP\Share\IShare */ - private $share; - - /** @var IManager */ - private $shareManager; - - /** @var ISession */ - private $session; - - /** @var IRequest */ - private $request; - - /** @var Throttler */ - private $throttler; - - /** - * @param IRequest $request - * @param IManager $shareManager - * @param ISession $session - * @param Throttler $throttler - */ public function __construct(IRequest $request, IManager $shareManager, ISession $session, @@ -88,7 +72,6 @@ public function __construct(IRequest $request, * * @param string $username * @param string $password - * * @return bool * @throws \Sabre\DAV\Exception\NotAuthenticated */ @@ -133,15 +116,11 @@ protected function validateUserPass($username, $password) { $this->throttler->registerAttempt(self::BRUTEFORCE_ACTION, $this->request->getRemoteAddress()); return false; } - } else { - return true; } + return true; } - /** - * @return \OCP\Share\IShare - */ - public function getShare() { + public function getShare(): IShare { return $this->share; } } diff --git a/apps/dav/lib/Connector/Sabre/AppEnabledPlugin.php b/apps/dav/lib/Connector/Sabre/AppEnabledPlugin.php deleted file mode 100644 index 244e5de0683ea..0000000000000 --- a/apps/dav/lib/Connector/Sabre/AppEnabledPlugin.php +++ /dev/null @@ -1,88 +0,0 @@ - - * @author Robin Appelman - * @author Thomas Müller - * - * @license AGPL-3.0 - * - * This code is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License, version 3, - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License, version 3, - * along with this program. If not, see - * - */ -namespace OCA\DAV\Connector\Sabre; - -use OCP\App\IAppManager; -use Sabre\DAV\Exception\Forbidden; -use Sabre\DAV\ServerPlugin; - -/** - * Plugin to check if an app is enabled for the current user - */ -class AppEnabledPlugin extends ServerPlugin { - - /** - * Reference to main server object - * - * @var \Sabre\DAV\Server - */ - private $server; - - /** - * @var string - */ - private $app; - - /** - * @var \OCP\App\IAppManager - */ - private $appManager; - - /** - * @param string $app - * @param \OCP\App\IAppManager $appManager - */ - public function __construct($app, IAppManager $appManager) { - $this->app = $app; - $this->appManager = $appManager; - } - - /** - * This initializes the plugin. - * - * This function is called by \Sabre\DAV\Server, after - * addPlugin is called. - * - * This method should set up the required event subscriptions. - * - * @param \Sabre\DAV\Server $server - * @return void - */ - public function initialize(\Sabre\DAV\Server $server) { - $this->server = $server; - $this->server->on('beforeMethod:*', [$this, 'checkAppEnabled'], 30); - } - - /** - * This method is called before any HTTP after auth and checks if the user has access to the app - * - * @throws \Sabre\DAV\Exception\Forbidden - * @return bool - */ - public function checkAppEnabled() { - if (!$this->appManager->isEnabledForUser($this->app)) { - throw new Forbidden(); - } - } -} diff --git a/apps/dav/lib/Connector/Sabre/Auth.php b/apps/dav/lib/Connector/Sabre/Auth.php index d81a3f9d6673c..1588e5a2e6c79 100644 --- a/apps/dav/lib/Connector/Sabre/Auth.php +++ b/apps/dav/lib/Connector/Sabre/Auth.php @@ -51,33 +51,19 @@ class Auth extends AbstractBasic { public const DAV_AUTHENTICATED = 'AUTHENTICATED_TO_DAV_BACKEND'; - /** @var ISession */ - private $session; - /** @var Session */ - private $userSession; - /** @var IRequest */ - private $request; - /** @var string */ - private $currentUser; - /** @var Manager */ - private $twoFactorManager; - /** @var Throttler */ - private $throttler; + private ISession $session; + private Session $userSession; + private IRequest $request; + private string $currentUser; + private Manager $twoFactorManager; + private Throttler $throttler; - /** - * @param ISession $session - * @param Session $userSession - * @param IRequest $request - * @param Manager $twoFactorManager - * @param Throttler $throttler - * @param string $principalPrefix - */ public function __construct(ISession $session, Session $userSession, IRequest $request, Manager $twoFactorManager, Throttler $throttler, - $principalPrefix = 'principals/users/') { + string $principalPrefix = 'principals/users/') { $this->session = $session; $this->userSession = $userSession; $this->twoFactorManager = $twoFactorManager; @@ -97,11 +83,8 @@ public function __construct(ISession $session, * account was changed. * * @see https://github.com/owncloud/core/issues/13245 - * - * @param string $username - * @return bool */ - public function isDavAuthenticated($username) { + public function isDavAuthenticated(string $username): bool { return !is_null($this->session->get(self::DAV_AUTHENTICATED)) && $this->session->get(self::DAV_AUTHENTICATED) === $username; } @@ -144,9 +127,7 @@ protected function validateUserPass($username, $password) { } /** - * @param RequestInterface $request - * @param ResponseInterface $response - * @return array + * @return array{bool, string} * @throws NotAuthenticated * @throws ServiceUnavailable */ @@ -165,10 +146,8 @@ public function check(RequestInterface $request, ResponseInterface $response) { /** * Checks whether a CSRF check is required on the request - * - * @return bool */ - private function requiresCSRFCheck() { + private function requiresCSRFCheck(): bool { // GET requires no check at all if ($this->request->getMethod() === 'GET') { return false; @@ -203,12 +182,10 @@ private function requiresCSRFCheck() { } /** - * @param RequestInterface $request - * @param ResponseInterface $response - * @return array + * @return array{bool, string} * @throws NotAuthenticated */ - private function auth(RequestInterface $request, ResponseInterface $response) { + private function auth(RequestInterface $request, ResponseInterface $response): array { $forcedLogout = false; if (!$this->request->passesCSRFCheck() && diff --git a/apps/dav/lib/Connector/Sabre/BearerAuth.php b/apps/dav/lib/Connector/Sabre/BearerAuth.php index d28a9cfdb84db..5a69d07b0026d 100644 --- a/apps/dav/lib/Connector/Sabre/BearerAuth.php +++ b/apps/dav/lib/Connector/Sabre/BearerAuth.php @@ -31,21 +31,11 @@ use Sabre\HTTP\ResponseInterface; class BearerAuth extends AbstractBearer { - /** @var IUserSession */ - private $userSession; - /** @var ISession */ - private $session; - /** @var IRequest */ - private $request; - /** @var string */ - private $principalPrefix; + private IUserSession $userSession; + private ISession $session; + private IRequest $request; + private string $principalPrefix; - /** - * @param IUserSession $userSession - * @param ISession $session - * @param string $principalPrefix - * @param IRequest $request - */ public function __construct(IUserSession $userSession, ISession $session, IRequest $request, @@ -90,7 +80,7 @@ public function validateBearerToken($bearerToken) { * @param RequestInterface $request * @param ResponseInterface $response */ - public function challenge(RequestInterface $request, ResponseInterface $response) { + public function challenge(RequestInterface $request, ResponseInterface $response): void { $response->setStatus(401); } } diff --git a/apps/dav/lib/Connector/Sabre/BlockLegacyClientPlugin.php b/apps/dav/lib/Connector/Sabre/BlockLegacyClientPlugin.php index 8e2ea4d4e161b..830c92d2c3061 100644 --- a/apps/dav/lib/Connector/Sabre/BlockLegacyClientPlugin.php +++ b/apps/dav/lib/Connector/Sabre/BlockLegacyClientPlugin.php @@ -28,6 +28,7 @@ use OCP\IConfig; use Sabre\DAV\ServerPlugin; use Sabre\HTTP\RequestInterface; +use Sabre\DAV\Server; /** * Class BlockLegacyClientPlugin is used to detect old legacy sync clients and @@ -36,23 +37,17 @@ * @package OCA\DAV\Connector\Sabre */ class BlockLegacyClientPlugin extends ServerPlugin { - /** @var \Sabre\DAV\Server */ - protected $server; - /** @var IConfig */ - protected $config; + protected Server $server; + protected IConfig $config; - /** - * @param IConfig $config - */ public function __construct(IConfig $config) { $this->config = $config; } /** - * @param \Sabre\DAV\Server $server * @return void */ - public function initialize(\Sabre\DAV\Server $server) { + public function initialize(Server $server) { $this->server = $server; $this->server->on('beforeMethod:*', [$this, 'beforeHandler'], 200); } diff --git a/apps/dav/lib/Connector/Sabre/CachingTree.php b/apps/dav/lib/Connector/Sabre/CachingTree.php index eb1233d35408b..81ffd47a977ea 100644 --- a/apps/dav/lib/Connector/Sabre/CachingTree.php +++ b/apps/dav/lib/Connector/Sabre/CachingTree.php @@ -28,17 +28,18 @@ class CachingTree extends Tree { /** * Store a node in the cache - * - * @param Node $node - * @param null|string $path */ - public function cacheNode(Node $node, $path = null) { + public function cacheNode(Node $node, ?string $path = null): void { if (is_null($path)) { $path = $node->getPath(); } $this->cache[trim($path, '/')] = $node; } + /** + * @param string $path + * @return void + */ public function markDirty($path) { // We don't care enough about sub-paths // flushing the entire cache diff --git a/apps/dav/lib/Connector/Sabre/ChecksumList.php b/apps/dav/lib/Connector/Sabre/ChecksumList.php index 74cdc98ef4f91..344e6a4ab3cb5 100644 --- a/apps/dav/lib/Connector/Sabre/ChecksumList.php +++ b/apps/dav/lib/Connector/Sabre/ChecksumList.php @@ -35,12 +35,9 @@ class ChecksumList implements XmlSerializable { public const NS_OWNCLOUD = 'http://owncloud.org/ns'; /** @var string[] of TYPE:CHECKSUM */ - private $checksums; + private array $checksums; - /** - * @param string $checksum - */ - public function __construct($checksum) { + public function __construct(string $checksum) { $this->checksums = explode(',', $checksum); } diff --git a/apps/dav/lib/Connector/Sabre/ChecksumUpdatePlugin.php b/apps/dav/lib/Connector/Sabre/ChecksumUpdatePlugin.php index 3247259357f59..c023d918c42a2 100644 --- a/apps/dav/lib/Connector/Sabre/ChecksumUpdatePlugin.php +++ b/apps/dav/lib/Connector/Sabre/ChecksumUpdatePlugin.php @@ -26,14 +26,12 @@ use Sabre\DAV\ServerPlugin; use Sabre\HTTP\RequestInterface; use Sabre\HTTP\ResponseInterface; +use Sabre\DAV\Server; class ChecksumUpdatePlugin extends ServerPlugin { - /** - * @var \Sabre\DAV\Server - */ - protected $server; + protected Server $server; - public function initialize(\Sabre\DAV\Server $server) { + public function initialize(Server $server) { $this->server = $server; $server->on('method:PATCH', [$this, 'httpPatch']); } @@ -42,6 +40,7 @@ public function getPluginName(): string { return 'checksumupdate'; } + /** @return string[] */ public function getHTTPMethods($path): array { $tree = $this->server->tree; @@ -55,6 +54,7 @@ public function getHTTPMethods($path): array { return []; } + /** @return string[] */ public function getFeatures(): array { return ['nextcloud-checksum-update']; } diff --git a/apps/dav/lib/Connector/Sabre/CommentPropertiesPlugin.php b/apps/dav/lib/Connector/Sabre/CommentPropertiesPlugin.php index 82980553fa8f1..f9a087daeb082 100644 --- a/apps/dav/lib/Connector/Sabre/CommentPropertiesPlugin.php +++ b/apps/dav/lib/Connector/Sabre/CommentPropertiesPlugin.php @@ -29,22 +29,17 @@ use OCP\IUserSession; use Sabre\DAV\PropFind; use Sabre\DAV\ServerPlugin; +use Sabre\DAV\Server; class CommentPropertiesPlugin extends ServerPlugin { public const PROPERTY_NAME_HREF = '{http://owncloud.org/ns}comments-href'; public const PROPERTY_NAME_COUNT = '{http://owncloud.org/ns}comments-count'; public const PROPERTY_NAME_UNREAD = '{http://owncloud.org/ns}comments-unread'; - /** @var \Sabre\DAV\Server */ - protected $server; - - /** @var ICommentsManager */ - private $commentsManager; - - /** @var IUserSession */ - private $userSession; - - private $cachedUnreadCount = []; + protected Server $server; + private ICommentsManager $commentsManager; + private IUserSession $userSession; + private array $cachedUnreadCount = []; public function __construct(ICommentsManager $commentsManager, IUserSession $userSession) { $this->commentsManager = $commentsManager; @@ -67,7 +62,7 @@ public function initialize(\Sabre\DAV\Server $server) { $this->server->on('propFind', [$this, 'handleGetProperties']); } - private function cacheDirectory(Directory $directory) { + private function cacheDirectory(Directory $directory): void { $children = $directory->getChildren(); $ids = []; @@ -109,14 +104,14 @@ public function handleGetProperties( } // need prefetch ? - if ($node instanceof \OCA\DAV\Connector\Sabre\Directory + if ($node instanceof Directory && $propFind->getDepth() !== 0 && !is_null($propFind->getStatus(self::PROPERTY_NAME_UNREAD)) ) { $this->cacheDirectory($node); } - $propFind->handle(self::PROPERTY_NAME_COUNT, function () use ($node) { + $propFind->handle(self::PROPERTY_NAME_COUNT, function () use ($node): int { return $this->commentsManager->getNumberOfCommentsForObject('files', (string)$node->getId()); }); @@ -124,19 +119,15 @@ public function handleGetProperties( return $this->getCommentsLink($node); }); - $propFind->handle(self::PROPERTY_NAME_UNREAD, function () use ($node) { - if (isset($this->cachedUnreadCount[$node->getId()])) { - return $this->cachedUnreadCount[$node->getId()]; - } - return $this->getUnreadCount($node); + $propFind->handle(self::PROPERTY_NAME_UNREAD, function () use ($node): ?bool { + return $this->cachedUnreadCount[$node->getId()] ?? $this->getUnreadCount($node); }); } /** - * returns a reference to the comments node + * Returns a reference to the comments node * - * @param Node $node - * @return mixed|string + * @return array|string|null */ public function getCommentsLink(Node $node) { $href = $this->server->getBaseUri(); @@ -151,13 +142,10 @@ public function getCommentsLink(Node $node) { } /** - * returns the number of unread comments for the currently logged in user + * Returns the number of unread comments for the currently logged in user * on the given file or directory node - * - * @param Node $node - * @return Int|null */ - public function getUnreadCount(Node $node) { + public function getUnreadCount(Node $node): ?int { $user = $this->userSession->getUser(); if (is_null($user)) { return null; diff --git a/apps/dav/lib/Connector/Sabre/CopyEtagHeaderPlugin.php b/apps/dav/lib/Connector/Sabre/CopyEtagHeaderPlugin.php index 029e631f4d90e..5dd0dc6f23177 100644 --- a/apps/dav/lib/Connector/Sabre/CopyEtagHeaderPlugin.php +++ b/apps/dav/lib/Connector/Sabre/CopyEtagHeaderPlugin.php @@ -27,6 +27,7 @@ use Sabre\DAV\Exception\NotFound; use Sabre\HTTP\RequestInterface; use Sabre\HTTP\ResponseInterface; +use Sabre\DAV\Server; /** * Copies the "Etag" header to "OC-Etag" after any request. @@ -34,9 +35,8 @@ * or mangle Etag headers. */ class CopyEtagHeaderPlugin extends \Sabre\DAV\ServerPlugin { + private Server $server; - /** @var \Sabre\DAV\Server */ - private $server; /** * This initializes the plugin. * diff --git a/apps/dav/lib/Connector/Sabre/Directory.php b/apps/dav/lib/Connector/Sabre/Directory.php index ed98b5050f811..5280511d5be66 100644 --- a/apps/dav/lib/Connector/Sabre/Directory.php +++ b/apps/dav/lib/Connector/Sabre/Directory.php @@ -54,40 +54,27 @@ use Sabre\DAV\Exception\ServiceUnavailable; use Sabre\DAV\IFile; use Sabre\DAV\INode; +use OCP\Share\IManager as IShareManager; class Directory extends \OCA\DAV\Connector\Sabre\Node implements \Sabre\DAV\ICollection, \Sabre\DAV\IQuota, \Sabre\DAV\IMoveTarget, \Sabre\DAV\ICopyTarget { /** * Cached directory content - * * @var \OCP\Files\FileInfo[] */ - private $dirContent; + private ?array $dirContent = null; - /** - * Cached quota info - * - * @var array - */ - private $quotaInfo; - - /** - * @var ObjectTree|null - */ - private $tree; + /** Cached quota info */ + private ?array $quotaInfo = null; + private ?ObjectTree $tree = null; /** @var array> */ private array $metadata = []; /** * Sets up the node, expects a full path name - * - * @param \OC\Files\View $view - * @param \OCP\Files\FileInfo $info - * @param ObjectTree|null $tree - * @param \OCP\Share\IManager $shareManager */ - public function __construct(View $view, FileInfo $info, $tree = null, $shareManager = null) { + public function __construct(View $view, FileInfo $info, ?ObjectTree $tree = null, IShareManager $shareManager = null) { parent::__construct($view, $info, $shareManager); $this->tree = $tree; } diff --git a/apps/dav/lib/Connector/Sabre/DummyGetResponsePlugin.php b/apps/dav/lib/Connector/Sabre/DummyGetResponsePlugin.php index 3a8469e99b423..bc6c6f5c25fbe 100644 --- a/apps/dav/lib/Connector/Sabre/DummyGetResponsePlugin.php +++ b/apps/dav/lib/Connector/Sabre/DummyGetResponsePlugin.php @@ -28,6 +28,7 @@ use Sabre\HTTP\RequestInterface; use Sabre\HTTP\ResponseInterface; +use Sabre\DAV\Server; /** * Class DummyGetResponsePlugin is a plugin used to not show a "Not implemented" @@ -43,8 +44,7 @@ * @package OCA\DAV\Connector\Sabre */ class DummyGetResponsePlugin extends \Sabre\DAV\ServerPlugin { - /** @var \Sabre\DAV\Server */ - protected $server; + protected Server $server; /** * @param \Sabre\DAV\Server $server diff --git a/apps/dav/lib/Connector/Sabre/ExceptionLoggerPlugin.php b/apps/dav/lib/Connector/Sabre/ExceptionLoggerPlugin.php index e89ce3a8037cb..c803358ede10f 100644 --- a/apps/dav/lib/Connector/Sabre/ExceptionLoggerPlugin.php +++ b/apps/dav/lib/Connector/Sabre/ExceptionLoggerPlugin.php @@ -83,16 +83,13 @@ class ExceptionLoggerPlugin extends \Sabre\DAV\ServerPlugin { RequestedRangeNotSatisfiable::class => true, ]; - /** @var string */ - private $appName; - + private string $appName; private LoggerInterface $logger; /** * @param string $loggerAppName app name to use when logging - * @param LoggerInterface $logger */ - public function __construct($loggerAppName, LoggerInterface $logger) { + public function __construct(string $loggerAppName, LoggerInterface $logger) { $this->appName = $loggerAppName; $this->logger = $logger; } @@ -114,9 +111,8 @@ public function initialize(\Sabre\DAV\Server $server) { /** * Log exception - * */ - public function logException(\Throwable $ex) { + public function logException(\Throwable $ex): void { $exceptionClass = get_class($ex); if (isset($this->nonFatalExceptions[$exceptionClass]) || ( @@ -128,11 +124,12 @@ public function logException(\Throwable $ex) { 'app' => $this->appName, 'exception' => $ex, ]); - } else { - $this->logger->critical($ex->getMessage(), [ - 'app' => $this->appName, - 'exception' => $ex, - ]); + return; } + + $this->logger->critical($ex->getMessage(), [ + 'app' => $this->appName, + 'exception' => $ex, + ]); } } diff --git a/apps/dav/lib/Connector/Sabre/FilesPlugin.php b/apps/dav/lib/Connector/Sabre/FilesPlugin.php index 9c4f912610bf3..9474ed91f8582 100644 --- a/apps/dav/lib/Connector/Sabre/FilesPlugin.php +++ b/apps/dav/lib/Connector/Sabre/FilesPlugin.php @@ -49,6 +49,7 @@ use Sabre\DAV\PropFind; use Sabre\DAV\PropPatch; use Sabre\DAV\ServerPlugin; +use Sabre\DAV\Server; use Sabre\DAV\Tree; use Sabre\HTTP\RequestInterface; use Sabre\HTTP\ResponseInterface; @@ -84,66 +85,28 @@ class FilesPlugin extends ServerPlugin { public const SUBFILE_COUNT_PROPERTYNAME = '{http://nextcloud.org/ns}contained-file-count'; public const FILE_METADATA_SIZE = '{http://nextcloud.org/ns}file-metadata-size'; - /** - * Reference to main server object - * - * @var \Sabre\DAV\Server - */ - private $server; - - /** - * @var Tree - */ - private $tree; - - /** - * @var IUserSession - */ - private $userSession; + /** Reference to main server object */ + private Server $server; + private Tree $tree; + private IUserSession $userSession; /** * Whether this is public webdav. * If true, some returned information will be stripped off. - * - * @var bool - */ - private $isPublic; - - /** - * @var bool */ - private $downloadAttachment; + private bool $isPublic; + private bool $downloadAttachment; + private IConfig $config; + private IRequest $request; + private IPreview $previewManager; - /** - * @var IConfig - */ - private $config; - - /** - * @var IRequest - */ - private $request; - - /** - * @var IPreview - */ - private $previewManager; - - /** - * @param Tree $tree - * @param IConfig $config - * @param IRequest $request - * @param IPreview $previewManager - * @param bool $isPublic - * @param bool $downloadAttachment - */ public function __construct(Tree $tree, IConfig $config, IRequest $request, IPreview $previewManager, IUserSession $userSession, - $isPublic = false, - $downloadAttachment = true) { + bool $isPublic = false, + bool $downloadAttachment = true) { $this->tree = $tree; $this->config = $config; $this->request = $request; @@ -161,10 +124,9 @@ public function __construct(Tree $tree, * * This method should set up the required event subscriptions. * - * @param \Sabre\DAV\Server $server * @return void */ - public function initialize(\Sabre\DAV\Server $server) { + public function initialize(Server $server) { $server->xml->namespaceMap[self::NS_OWNCLOUD] = 'oc'; $server->xml->namespaceMap[self::NS_NEXTCLOUD] = 'nc'; $server->protectedProperties[] = self::FILEID_PROPERTYNAME; @@ -347,7 +309,7 @@ public function handleGetProperties(PropFind $propFind, \Sabre\DAV\INode $node) ); }); - $propFind->handle(self::OCM_SHARE_PERMISSIONS_PROPERTYNAME, function () use ($node, $httpRequest) { + $propFind->handle(self::OCM_SHARE_PERMISSIONS_PROPERTYNAME, function () use ($node, $httpRequest): ?string { $user = $this->userSession->getUser(); if ($user === null) { return null; @@ -359,11 +321,11 @@ public function handleGetProperties(PropFind $propFind, \Sabre\DAV\INode $node) return json_encode($ocmPermissions); }); - $propFind->handle(self::GETETAG_PROPERTYNAME, function () use ($node) { + $propFind->handle(self::GETETAG_PROPERTYNAME, function () use ($node): string { return $node->getETag(); }); - $propFind->handle(self::OWNER_ID_PROPERTYNAME, function () use ($node) { + $propFind->handle(self::OWNER_ID_PROPERTYNAME, function () use ($node): ?string { $owner = $node->getOwner(); if (!$owner) { return null; @@ -371,7 +333,7 @@ public function handleGetProperties(PropFind $propFind, \Sabre\DAV\INode $node) return $owner->getUID(); } }); - $propFind->handle(self::OWNER_DISPLAY_NAME_PROPERTYNAME, function () use ($node) { + $propFind->handle(self::OWNER_DISPLAY_NAME_PROPERTYNAME, function () use ($node): ?string { $owner = $node->getOwner(); if (!$owner) { return null; @@ -383,14 +345,14 @@ public function handleGetProperties(PropFind $propFind, \Sabre\DAV\INode $node) $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) { + $propFind->handle(self::SIZE_PROPERTYNAME, function () use ($node): int { return $node->getSize(); }); $propFind->handle(self::MOUNT_TYPE_PROPERTYNAME, function () use ($node) { return $node->getFileInfo()->getMountPoint()->getMountType(); }); - $propFind->handle(self::SHARE_NOTE, function () use ($node, $httpRequest) { + $propFind->handle(self::SHARE_NOTE, function () use ($node, $httpRequest): ?string { $user = $this->userSession->getUser(); if ($user === null) { return null; @@ -569,10 +531,7 @@ public function handleUpdateProperties($path, PropPatch $propPatch) { if (empty($etag)) { return false; } - if ($node->setEtag($etag) !== -1) { - return true; - } - return false; + return $node->setEtag($etag) !== -1; }); $propPatch->handle(self::CREATIONDATE_PROPERTYNAME, function ($time) use ($node) { if (empty($time)) { diff --git a/apps/dav/lib/Connector/Sabre/ServerFactory.php b/apps/dav/lib/Connector/Sabre/ServerFactory.php index 635645ed99275..8f1f710ca5e09 100644 --- a/apps/dav/lib/Connector/Sabre/ServerFactory.php +++ b/apps/dav/lib/Connector/Sabre/ServerFactory.php @@ -48,25 +48,16 @@ use Symfony\Component\EventDispatcher\EventDispatcherInterface; class ServerFactory { - /** @var IConfig */ - private $config; + private IConfig $config; private LoggerInterface $logger; - /** @var IDBConnection */ - private $databaseConnection; - /** @var IUserSession */ - private $userSession; - /** @var IMountManager */ - private $mountManager; - /** @var ITagManager */ - private $tagManager; - /** @var IRequest */ - private $request; - /** @var IPreview */ - private $previewManager; - /** @var EventDispatcherInterface */ - private $eventDispatcher; - /** @var IL10N */ - private $l10n; + private IDBConnection $databaseConnection; + private IUserSession $userSession; + private IMountManager $mountManager; + private ITagManager $tagManager; + private IRequest $request; + private IPreview $previewManager; + private EventDispatcherInterface $eventDispatcher; + private IL10N $l10n; public function __construct( IConfig $config, @@ -93,16 +84,12 @@ public function __construct( } /** - * @param string $baseUri - * @param string $requestUri - * @param Plugin $authPlugin * @param callable $viewCallBack callback that should return the view for the dav endpoint - * @return Server */ - public function createServer($baseUri, - $requestUri, + public function createServer(string $baseUri, + string $requestUri, Plugin $authPlugin, - callable $viewCallBack) { + callable $viewCallBack): Server { // Fire up server $objectTree = new \OCA\DAV\Connector\Sabre\ObjectTree(); $server = new \OCA\DAV\Connector\Sabre\Server($objectTree); diff --git a/apps/dav/lib/Connector/Sabre/SharesPlugin.php b/apps/dav/lib/Connector/Sabre/SharesPlugin.php index 57c91e05a8c2a..9fa6775c3b5cc 100644 --- a/apps/dav/lib/Connector/Sabre/SharesPlugin.php +++ b/apps/dav/lib/Connector/Sabre/SharesPlugin.php @@ -30,10 +30,14 @@ use OCA\DAV\Connector\Sabre\Node as DavNode; use OCP\Files\Folder; +use OCP\Files\Node; use OCP\Files\NotFoundException; use OCP\IUserSession; use OCP\Share\IShare; +use OCP\Share\IManager; use Sabre\DAV\PropFind; +use Sabre\DAV\Tree; +use Sabre\DAV\Server; /** * Sabre Plugin to provide share-related properties @@ -50,36 +54,20 @@ class SharesPlugin extends \Sabre\DAV\ServerPlugin { * @var \Sabre\DAV\Server */ private $server; - - /** @var \OCP\Share\IManager */ - private $shareManager; - - /** @var \Sabre\DAV\Tree */ - private $tree; - - /** @var string */ - private $userId; - - /** @var \OCP\Files\Folder */ - private $userFolder; - + private IManager $shareManager; + private Tree $tree; + private string $userId; + private Folder $userFolder; /** @var IShare[][] */ - private $cachedShares = []; - + private array $cachedShares = []; /** @var string[] */ - private $cachedFolders = []; + private array $cachedFolders = []; - /** - * @param \Sabre\DAV\Tree $tree tree - * @param IUserSession $userSession user session - * @param \OCP\Files\Folder $userFolder user home folder - * @param \OCP\Share\IManager $shareManager share manager - */ public function __construct( - \Sabre\DAV\Tree $tree, + Tree $tree, IUserSession $userSession, - \OCP\Files\Folder $userFolder, - \OCP\Share\IManager $shareManager + Folder $userFolder, + IManager $shareManager ) { $this->tree = $tree; $this->shareManager = $shareManager; @@ -95,9 +83,9 @@ public function __construct( * * This method should set up the required event subscriptions. * - * @param \Sabre\DAV\Server $server + * @return void */ - public function initialize(\Sabre\DAV\Server $server) { + public function initialize(Server $server) { $server->xml->namespaceMap[self::NS_OWNCLOUD] = 'oc'; $server->xml->elementMap[self::SHARETYPES_PROPERTYNAME] = ShareTypeList::class; $server->protectedProperties[] = self::SHARETYPES_PROPERTYNAME; @@ -108,10 +96,10 @@ public function initialize(\Sabre\DAV\Server $server) { } /** - * @param \OCP\Files\Node $node + * @param Node $node * @return IShare[] */ - private function getShare(\OCP\Files\Node $node): array { + private function getShare(Node $node): array { $result = []; $requestedShareTypes = [ IShare::TYPE_USER, @@ -209,7 +197,7 @@ public function handleGetProperties( } } - $propFind->handle(self::SHARETYPES_PROPERTYNAME, function () use ($sabreNode) { + $propFind->handle(self::SHARETYPES_PROPERTYNAME, function () use ($sabreNode): ShareTypeList { $shares = $this->getShares($sabreNode); $shareTypes = array_unique(array_map(function (IShare $share) { @@ -219,7 +207,7 @@ public function handleGetProperties( return new ShareTypeList($shareTypes); }); - $propFind->handle(self::SHAREES_PROPERTYNAME, function () use ($sabreNode) { + $propFind->handle(self::SHAREES_PROPERTYNAME, function () use ($sabreNode): ShareeList { $shares = $this->getShares($sabreNode); return new ShareeList($shares); diff --git a/apps/dav/lib/Server.php b/apps/dav/lib/Server.php index 9791bc6b334e2..5b532465abad0 100644 --- a/apps/dav/lib/Server.php +++ b/apps/dav/lib/Server.php @@ -237,7 +237,7 @@ public function __construct(IRequest $request, string $baseUri) { $this->server->addPlugin(new SearchPlugin($lazySearchBackend)); // wait with registering these until auth is handled and the filesystem is setup - $this->server->on('beforeMethod:*', function () use ($root, $lazySearchBackend) { + $this->server->on('beforeMethod:*', function () use ($root, $lazySearchBackend, $logger) { // custom properties plugin must be the last one $userSession = \OC::$server->getUserSession(); $user = $userSession->getUser(); @@ -306,7 +306,6 @@ public function __construct(IRequest $request, string $baseUri) { \OC::$server->getShareManager(), $view )); - $logger = \OC::$server->get(LoggerInterface::class); $this->server->addPlugin( new BulkUploadPlugin($userFolder, $logger) ); diff --git a/build/psalm-baseline.xml b/build/psalm-baseline.xml index 4f4e18e1f90b2..d3d497e7e3ce1 100644 --- a/build/psalm-baseline.xml +++ b/build/psalm-baseline.xml @@ -583,11 +583,6 @@ bool - - - bool - - tryTokenLogin From f7be76125f885d66caac4a8d6697e121dce52708 Mon Sep 17 00:00:00 2001 From: Carl Schwan Date: Fri, 6 May 2022 00:01:08 +0200 Subject: [PATCH 2/2] Fix more psalm issues Signed-off-by: Carl Schwan --- apps/dav/appinfo/v1/caldav.php | 2 +- apps/dav/appinfo/v1/carddav.php | 1 - .../BuildReminderIndexBackgroundJob.php | 9 +- .../lib/BackgroundJob/EventReminderJob.php | 3 +- .../GenerateBirthdayCalendarBackgroundJob.php | 9 +- apps/dav/lib/BackgroundJob/UploadCleanup.php | 10 +- apps/dav/lib/CalDAV/BirthdayService.php | 48 ++------ apps/dav/lib/CalDAV/CachedSubscription.php | 13 ++- .../lib/CalDAV/CachedSubscriptionObject.php | 2 +- .../ICSExportPlugin/ICSExportPlugin.php | 2 +- .../InvitationResponseServer.php | 1 - .../lib/CalDAV/Publishing/PublishPlugin.php | 4 +- .../NotificationProvider/EmailProvider.php | 91 ++++----------- .../NotificationProvider/PushProvider.php | 2 - apps/dav/lib/CalDAV/Reminder/Notifier.php | 8 +- apps/dav/lib/CardDAV/CardDavBackend.php | 37 +++--- apps/dav/lib/CardDAV/PhotoCache.php | 13 +-- apps/dav/lib/CardDAV/SyncService.php | 2 +- apps/dav/lib/Connector/PublicAuth.php | 3 +- apps/dav/lib/Connector/Sabre/Auth.php | 2 +- .../Sabre/BlockLegacyClientPlugin.php | 2 +- .../Connector/Sabre/ChecksumUpdatePlugin.php | 2 +- .../Sabre/CommentPropertiesPlugin.php | 2 +- .../Connector/Sabre/CopyEtagHeaderPlugin.php | 2 +- .../Sabre/DummyGetResponsePlugin.php | 2 +- .../Connector/Sabre/ExceptionLoggerPlugin.php | 2 +- apps/dav/lib/Connector/Sabre/FilesPlugin.php | 4 +- .../unit/Files/FileSearchBackendTest.php | 6 +- build/psalm-baseline.xml | 105 ------------------ 29 files changed, 93 insertions(+), 296 deletions(-) diff --git a/apps/dav/appinfo/v1/caldav.php b/apps/dav/appinfo/v1/caldav.php index 9036a30f95ca7..6a496a992e61d 100644 --- a/apps/dav/appinfo/v1/caldav.php +++ b/apps/dav/appinfo/v1/caldav.php @@ -100,7 +100,7 @@ // 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 8dffad16d8d78..a0306118781ef 100644 --- a/apps/dav/appinfo/v1/carddav.php +++ b/apps/dav/appinfo/v1/carddav.php @@ -38,7 +38,6 @@ 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 7f1e78248d347..2ae47ee89ea31 100644 --- a/apps/dav/lib/BackgroundJob/BuildReminderIndexBackgroundJob.php +++ b/apps/dav/lib/BackgroundJob/BuildReminderIndexBackgroundJob.php @@ -71,12 +71,9 @@ public function __construct(IDBConnection $db, $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 ab7dadd8c0b2f..55cecf5519d52 100644 --- a/apps/dav/lib/BackgroundJob/EventReminderJob.php +++ b/apps/dav/lib/BackgroundJob/EventReminderJob.php @@ -52,12 +52,11 @@ public function __construct(ITimeFactory $time, } /** - * @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 a338a172d66f3..8e72e8f076c8c 100644 --- a/apps/dav/lib/BackgroundJob/GenerateBirthdayCalendarBackgroundJob.php +++ b/apps/dav/lib/BackgroundJob/GenerateBirthdayCalendarBackgroundJob.php @@ -47,12 +47,9 @@ public function __construct(ITimeFactory $time, $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 76906becb54c2..f612f58cd7ce5 100644 --- a/apps/dav/lib/BackgroundJob/UploadCleanup.php +++ b/apps/dav/lib/BackgroundJob/UploadCleanup.php @@ -32,18 +32,15 @@ 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 @@ protected function run($argument) { 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 bdcf0796283ef..1030768e26f45 100644 --- a/apps/dav/lib/CalDAV/BirthdayService.php +++ b/apps/dav/lib/CalDAV/BirthdayService.php @@ -53,34 +53,15 @@ */ 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 @@ public function __construct(CalDavBackend $calDavBackEnd, $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 @@ public function onCardChanged(int $addressBookId, } } - /** - * @param int $addressBookId - * @param string $cardUri - */ public function onCardDeleted(int $addressBookId, - string $cardUri) { + string $cardUri): void { if (!$this->isGloballyEnabled()) { return; } @@ -156,11 +128,9 @@ public function onCardDeleted(int $addressBookId, } /** - * @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 18e61450ee9b6..f42b5f97f5d6b 100644 --- a/apps/dav/lib/CalDAV/CachedSubscription.php +++ b/apps/dav/lib/CalDAV/CachedSubscription.php @@ -31,6 +31,7 @@ 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 @@ public function getPrincipalURI():string { /** * @return array */ - public function getACL():array { + public function getACL() { return [ [ 'privilege' => '{DAV:}read', @@ -79,7 +80,7 @@ public function getACL():array { /** * @return array */ - public function getChildACL():array { + public function getChildACL() { return [ [ 'privilege' => '{DAV:}read', @@ -139,9 +140,9 @@ public function getChild($name) { } /** - * @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 @@ public function getMultipleChildren(array $paths):array { /** * @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 db8c9fa8e8011..3c1373763e127 100644 --- a/apps/dav/lib/CalDAV/CachedSubscriptionObject.php +++ b/apps/dav/lib/CalDAV/CachedSubscriptionObject.php @@ -50,7 +50,7 @@ public function get() { /** * @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 2a5a6f1bae395..627959c90f6d8 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 1a70f95aa5f69..a85892443cc45 100644 --- a/apps/dav/lib/CalDAV/InvitationResponse/InvitationResponseServer.php +++ b/apps/dav/lib/CalDAV/InvitationResponse/InvitationResponseServer.php @@ -37,7 +37,6 @@ 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 97e942f9da24a..aabf78da1aa8b 100644 --- a/apps/dav/lib/CalDAV/Publishing/PublishPlugin.php +++ b/apps/dav/lib/CalDAV/Publishing/PublishPlugin.php @@ -134,8 +134,8 @@ public function propFind(PropFind $propFind, INode $node) { $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 7e0020b5f55e9..c147b47860e2c 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\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 @@ private function addBulletList(IEMailTemplate $template, } } - /** - * @param string $path - * @return string - */ private function getAbsoluteImagePath(string $path):string { return $this->urlGenerator->getAbsoluteURL( $this->urlGenerator->imagePath('core', $path) @@ -207,9 +203,8 @@ private function getOrganizerEMailAndNameFromEvent(VEvent $vevent):?array { } /** - * @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 @@ private function sortEMailAddressesByLanguage(array $emails, /** * @param VEvent $vevent - * @return array + * @return array */ private function getAllEMailAddressesFromEvent(VEvent $vevent):array { $emailAddresses = []; @@ -277,7 +272,7 @@ private function getAllEMailAddressesFromEvent(VEvent $vevent):array { $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 @@ private function getAllEMailAddressesFromEvent(VEvent $vevent):array { } 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 @@ private function getCUTypeOfAttendee(VObject\Property $attendee):string { 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 @@ private function getPartstatOfAttendee(VObject\Property $attendee):string { 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 @@ private function getEMailAddressOfAttendee(VObject\Property $attendee):?string { } /** - * @param array $users - * @return array + * @param IUser[] $users + * @return array */ private function getEMailAddressesOfAllUsersWithWriteAccessToCalendar(array $users):array { $emailAddresses = []; @@ -366,12 +346,9 @@ private function getEMailAddressesOfAllUsersWithWriteAccessToCalendar(array $use } /** - * @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 @@ private function generateDateString(IL10N $l10n, VEvent $vevent):string { . ' (' . $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 298297fdc38bb..cb873020c388d 100644 --- a/apps/dav/lib/CalDAV/Reminder/NotificationProvider/PushProvider.php +++ b/apps/dav/lib/CalDAV/Reminder/NotificationProvider/PushProvider.php @@ -109,8 +109,6 @@ public function send(VEvent $vevent, } /** - * @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 8535c55054a90..c658ef2ff0165 100644 --- a/apps/dav/lib/CalDAV/Reminder/Notifier.php +++ b/apps/dav/lib/CalDAV/Reminder/Notifier.php @@ -298,7 +298,7 @@ private function isDayEqual(DateTime $dtStart, * @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 @@ private function getWeekDayName(DateTime $dt):string { * @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 @@ private function getDateString(DateTime $dt):string { * @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 @@ private function getDateTimeString(DateTime $dt):string { * @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 1c1754ff752f3..35df5c0b8cafa 100644 --- a/apps/dav/lib/CardDAV/CardDavBackend.php +++ b/apps/dav/lib/CardDAV/CardDavBackend.php @@ -291,16 +291,15 @@ private function getUserDisplayName($uid) { /** * @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 @@ public function createAddressBook($principalUri, $url, array $properties) { $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 @@ public function deleteAddressBook($addressBookId) { ->execute(); if ($addressBookData) { - $this->dispatcher->dispatchTyped(new AddressBookDeletedEvent((int) $addressBookId, $addressBookData, $shares)); + $this->dispatcher->dispatchTyped(new AddressBookDeletedEvent($addressBookId, $addressBookData, $shares)); } } @@ -515,14 +514,14 @@ public function deleteAddressBook($addressBookId) { * 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 @@ public function getCard($addressBookId, $cardUri) { * 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 @@ public function createCard($addressBookId, $cardUri, $cardData) { $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 @@ public function updateCard($addressBookId, $cardUri, $cardData) { $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 @@ public function deleteCard($addressBookId, $cardUri) { $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 @@ public function getChangesForAddressBook($addressBookId, $syncToken, $syncLevel, ->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 @@ public function getChangesForAddressBook($addressBookId, $syncToken, $syncLevel, } // Fetching all changes - $stmt = $qb->execute(); + $stmt = $qb->executeQuery(); $changes = []; @@ -932,7 +931,7 @@ public function getChangesForAddressBook($addressBookId, $syncToken, $syncLevel, $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 3051d2d48ba96..777a0b0e16945 100644 --- a/apps/dav/lib/CardDAV/PhotoCache.php +++ b/apps/dav/lib/CardDAV/PhotoCache.php @@ -63,15 +63,9 @@ public function __construct(IAppData $appData, LoggerInterface $logger) { } /** - * @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 @@ private function hasPhoto(ISimpleFolder $folder): bool { 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 b93fd94f7419c..95fdf1d21dae0 100644 --- a/apps/dav/lib/CardDAV/SyncService.php +++ b/apps/dav/lib/CardDAV/SyncService.php @@ -86,7 +86,7 @@ public function __construct(CardDavBackend $backend, */ 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 ba5e635e5f353..cc51a249e7570 100644 --- a/apps/dav/lib/Connector/PublicAuth.php +++ b/apps/dav/lib/Connector/PublicAuth.php @@ -44,7 +44,7 @@ */ 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 @@ protected function validateUserPass($username, $password) { } 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 1588e5a2e6c79..1610c554b9bba 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 830c92d2c3061..2d2be63141695 100644 --- a/apps/dav/lib/Connector/Sabre/BlockLegacyClientPlugin.php +++ b/apps/dav/lib/Connector/Sabre/BlockLegacyClientPlugin.php @@ -37,7 +37,7 @@ * @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 c023d918c42a2..c222923bc8e55 100644 --- a/apps/dav/lib/Connector/Sabre/ChecksumUpdatePlugin.php +++ b/apps/dav/lib/Connector/Sabre/ChecksumUpdatePlugin.php @@ -29,7 +29,7 @@ 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 f9a087daeb082..4a1205e8606be 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 5dd0dc6f23177..f3ea94be3b6a1 100644 --- a/apps/dav/lib/Connector/Sabre/CopyEtagHeaderPlugin.php +++ b/apps/dav/lib/Connector/Sabre/CopyEtagHeaderPlugin.php @@ -35,7 +35,7 @@ * 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 bc6c6f5c25fbe..8e35afe2e7cc7 100644 --- a/apps/dav/lib/Connector/Sabre/DummyGetResponsePlugin.php +++ b/apps/dav/lib/Connector/Sabre/DummyGetResponsePlugin.php @@ -44,7 +44,7 @@ * @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 c803358ede10f..ea94b5c8933b9 100644 --- a/apps/dav/lib/Connector/Sabre/ExceptionLoggerPlugin.php +++ b/apps/dav/lib/Connector/Sabre/ExceptionLoggerPlugin.php @@ -112,7 +112,7 @@ public function initialize(\Sabre\DAV\Server $server) { /** * 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 9474ed91f8582..b784764f8fed3 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 @@ public function handleGetProperties(PropFind $propFind, \Sabre\DAV\INode $node) $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 dec5db1b1b0cf..da682a5fb2187 100644 --- a/apps/dav/tests/unit/Files/FileSearchBackendTest.php +++ b/apps/dav/tests/unit/Files/FileSearchBackendTest.php @@ -29,7 +29,7 @@ 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 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 @@ protected function setUp(): void { ->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 d3d497e7e3ce1..cc644443d5136 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