diff options
author | Carl Schwan <carl@carlschwan.eu> | 2022-04-12 14:01:13 +0200 |
---|---|---|
committer | Carl Schwan <carl@carlschwan.eu> | 2022-05-05 22:03:59 +0200 |
commit | 829490ab7a02579c6b31573c3f53428e86cbf2e0 (patch) | |
tree | 1f644d168039ea1875398234419ace13f49dac5f /apps/dav | |
parent | 0690646d09430ce363b07bc2cd59283e303314eb (diff) | |
download | nextcloud-server-829490ab7a02579c6b31573c3f53428e86cbf2e0.tar.gz nextcloud-server-829490ab7a02579c6b31573c3f53428e86cbf2e0.zip |
Cleanup dav
- Remove unused class AppEnabledPlugin
- Add more type hinting when possible
Signed-off-by: Carl Schwan <carl@carlschwan.eu>
Diffstat (limited to 'apps/dav')
25 files changed, 145 insertions, 402 deletions
diff --git a/apps/dav/appinfo/v1/carddav.php b/apps/dav/appinfo/v1/carddav.php index a0306118781..8dffad16d8d 100644 --- a/apps/dav/appinfo/v1/carddav.php +++ b/apps/dav/appinfo/v1/carddav.php @@ -38,6 +38,7 @@ 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/appinfo/v1/publicwebdav.php b/apps/dav/appinfo/v1/publicwebdav.php index 43b472c107b..389461f94b1 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 <http://www.gnu.org/licenses/> * */ + +use Psr\Log\LoggerInterface; + // load needed apps $RUNTIME_APPTYPES = ['filesystem', 'authentication', 'logging']; @@ -48,7 +51,7 @@ $authPlugin = new \Sabre\DAV\Auth\Plugin($authBackend); $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 e39a6b48d57..8dbe846f3ff 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 <http://www.gnu.org/licenses/> * */ +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 @@ ignore_user_abort(true); $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 5f7815a9bfc..0583b94a86c 100644 --- a/apps/dav/composer/composer/autoload_classmap.php +++ b/apps/dav/composer/composer/autoload_classmap.php @@ -139,7 +139,6 @@ return array( '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 1f57b8b043a..301be38246a 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 0c76e4f5e10..2a5a6f1bae3 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 @@ use Sabre\VObject\Property\ICalendar\Duration; * @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 c8da92c8277..1a70f95aa5f 100644 --- a/apps/dav/lib/CalDAV/InvitationResponse/InvitationResponseServer.php +++ b/apps/dav/lib/CalDAV/InvitationResponse/InvitationResponseServer.php @@ -37,6 +37,7 @@ use OCA\DAV\RootCollection; use OCP\EventDispatcher\IEventDispatcher; use Psr\Log\LoggerInterface; use Sabre\VObject\ITip\Message; +use Psr\Log\LoggerInterface; class InvitationResponseServer { @@ -100,7 +101,7 @@ class InvitationResponseServer { )); // 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 66391b268a6..3051d2d48ba 100644 --- a/apps/dav/lib/CardDAV/PhotoCache.php +++ b/apps/dav/lib/CardDAV/PhotoCache.php @@ -34,12 +34,12 @@ use OCP\Files\NotFoundException; 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 @@ class PhotoCache { 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 @@ class PhotoCache { $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 @@ class PhotoCache { /** * 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 @@ class PhotoCache { /** * @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 @@ class PhotoCache { } /** - * @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 @@ class PhotoCache { 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 426cbf871d7..ba5e635e5f3 100644 --- a/apps/dav/lib/Connector/PublicAuth.php +++ b/apps/dav/lib/Connector/PublicAuth.php @@ -44,28 +44,12 @@ use Sabre\DAV\Auth\Backend\AbstractBasic; */ 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 @@ class PublicAuth extends AbstractBasic { * * @param string $username * @param string $password - * * @return bool * @throws \Sabre\DAV\Exception\NotAuthenticated */ @@ -133,15 +116,11 @@ class PublicAuth extends AbstractBasic { $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 244e5de0683..00000000000 --- a/apps/dav/lib/Connector/Sabre/AppEnabledPlugin.php +++ /dev/null @@ -1,88 +0,0 @@ -<?php -/** - * @copyright Copyright (c) 2016, ownCloud, Inc. - * - * @author Georg Ehrke <oc.list@georgehrke.com> - * @author Robin Appelman <robin@icewind.nl> - * @author Thomas Müller <thomas.mueller@tmit.eu> - * - * @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 <http://www.gnu.org/licenses/> - * - */ -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 d81a3f9d667..1588e5a2e6c 100644 --- a/apps/dav/lib/Connector/Sabre/Auth.php +++ b/apps/dav/lib/Connector/Sabre/Auth.php @@ -51,33 +51,19 @@ use Sabre\HTTP\ResponseInterface; 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 @@ class Auth extends AbstractBasic { * 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 @@ class Auth extends AbstractBasic { } /** - * @param RequestInterface $request - * @param ResponseInterface $response - * @return array + * @return array{bool, string} * @throws NotAuthenticated * @throws ServiceUnavailable */ @@ -165,10 +146,8 @@ class Auth extends AbstractBasic { /** * 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 @@ class Auth extends AbstractBasic { } /** - * @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 d28a9cfdb84..5a69d07b002 100644 --- a/apps/dav/lib/Connector/Sabre/BearerAuth.php +++ b/apps/dav/lib/Connector/Sabre/BearerAuth.php @@ -31,21 +31,11 @@ use Sabre\HTTP\RequestInterface; 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 @@ class BearerAuth extends AbstractBearer { * @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 8e2ea4d4e16..830c92d2c30 100644 --- a/apps/dav/lib/Connector/Sabre/BlockLegacyClientPlugin.php +++ b/apps/dav/lib/Connector/Sabre/BlockLegacyClientPlugin.php @@ -28,6 +28,7 @@ namespace OCA\DAV\Connector\Sabre; 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 @@ use Sabre\HTTP\RequestInterface; * @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 eb1233d3540..81ffd47a977 100644 --- a/apps/dav/lib/Connector/Sabre/CachingTree.php +++ b/apps/dav/lib/Connector/Sabre/CachingTree.php @@ -28,17 +28,18 @@ use Sabre\DAV\Tree; 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 74cdc98ef4f..344e6a4ab3c 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 3247259357f..c023d918c42 100644 --- a/apps/dav/lib/Connector/Sabre/ChecksumUpdatePlugin.php +++ b/apps/dav/lib/Connector/Sabre/ChecksumUpdatePlugin.php @@ -26,14 +26,12 @@ namespace OCA\DAV\Connector\Sabre; 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 @@ class ChecksumUpdatePlugin extends ServerPlugin { return 'checksumupdate'; } + /** @return string[] */ public function getHTTPMethods($path): array { $tree = $this->server->tree; @@ -55,6 +54,7 @@ class ChecksumUpdatePlugin extends ServerPlugin { 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 82980553fa8..f9a087daeb0 100644 --- a/apps/dav/lib/Connector/Sabre/CommentPropertiesPlugin.php +++ b/apps/dav/lib/Connector/Sabre/CommentPropertiesPlugin.php @@ -29,22 +29,17 @@ use OCP\Comments\ICommentsManager; 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 @@ class CommentPropertiesPlugin extends ServerPlugin { $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 @@ class CommentPropertiesPlugin extends ServerPlugin { } // 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 @@ class CommentPropertiesPlugin extends ServerPlugin { 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 @@ class CommentPropertiesPlugin extends ServerPlugin { } /** - * 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 029e631f4d9..5dd0dc6f231 100644 --- a/apps/dav/lib/Connector/Sabre/CopyEtagHeaderPlugin.php +++ b/apps/dav/lib/Connector/Sabre/CopyEtagHeaderPlugin.php @@ -27,6 +27,7 @@ namespace OCA\DAV\Connector\Sabre; 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 @@ use Sabre\HTTP\ResponseInterface; * 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 ed98b5050f8..5280511d5be 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\NotFound; 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<string, array<int, FileMetadata>> */ 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 3a8469e99b4..bc6c6f5c25f 100644 --- a/apps/dav/lib/Connector/Sabre/DummyGetResponsePlugin.php +++ b/apps/dav/lib/Connector/Sabre/DummyGetResponsePlugin.php @@ -28,6 +28,7 @@ namespace OCA\DAV\Connector\Sabre; 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 @@ use Sabre\HTTP\ResponseInterface; * @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 e89ce3a8037..c803358ede1 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 @@ class ExceptionLoggerPlugin extends \Sabre\DAV\ServerPlugin { /** * 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 @@ class ExceptionLoggerPlugin extends \Sabre\DAV\ServerPlugin { '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 9c4f912610b..9474ed91f85 100644 --- a/apps/dav/lib/Connector/Sabre/FilesPlugin.php +++ b/apps/dav/lib/Connector/Sabre/FilesPlugin.php @@ -49,6 +49,7 @@ use Sabre\DAV\IFile; 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 @@ class FilesPlugin extends ServerPlugin { * * 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 @@ class FilesPlugin extends ServerPlugin { ); }); - $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 @@ class FilesPlugin extends ServerPlugin { 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 @@ class FilesPlugin extends ServerPlugin { 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 @@ 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) { + $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 @@ class FilesPlugin extends ServerPlugin { 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 635645ed992..8f1f710ca5e 100644 --- a/apps/dav/lib/Connector/Sabre/ServerFactory.php +++ b/apps/dav/lib/Connector/Sabre/ServerFactory.php @@ -48,25 +48,16 @@ use Sabre\DAV\Auth\Plugin; 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 @@ class ServerFactory { } /** - * @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 57c91e05a8c..9fa6775c3b5 100644 --- a/apps/dav/lib/Connector/Sabre/SharesPlugin.php +++ b/apps/dav/lib/Connector/Sabre/SharesPlugin.php @@ -30,10 +30,14 @@ namespace OCA\DAV\Connector\Sabre; 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 @@ class SharesPlugin extends \Sabre\DAV\ServerPlugin { * * 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 @@ class SharesPlugin extends \Sabre\DAV\ServerPlugin { } /** - * @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 @@ class SharesPlugin extends \Sabre\DAV\ServerPlugin { } } - $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 @@ class SharesPlugin extends \Sabre\DAV\ServerPlugin { 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 9791bc6b334..5b532465aba 100644 --- a/apps/dav/lib/Server.php +++ b/apps/dav/lib/Server.php @@ -237,7 +237,7 @@ class Server { $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 @@ class Server { \OC::$server->getShareManager(), $view )); - $logger = \OC::$server->get(LoggerInterface::class); $this->server->addPlugin( new BulkUploadPlugin($userFolder, $logger) ); |