From f56673c4cbefec3a9ac7de03f9e8c6db47531df1 Mon Sep 17 00:00:00 2001 From: Tamino Bauknecht Date: Wed, 6 Dec 2023 23:19:19 +0100 Subject: [PATCH] FilesPlugin/SymlinkPlugin/SymlinkManager: Fix some style guide violations and warnings Signed-off-by: Tamino Bauknecht --- apps/dav/lib/Connector/Sabre/FilesPlugin.php | 9 +++++---- apps/dav/lib/Upload/SymlinkPlugin.php | 12 +++++++++--- lib/private/Files/SymlinkManager.php | 6 +++--- 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/apps/dav/lib/Connector/Sabre/FilesPlugin.php b/apps/dav/lib/Connector/Sabre/FilesPlugin.php index df63f33253427..93eeef0e4d8a4 100644 --- a/apps/dav/lib/Connector/Sabre/FilesPlugin.php +++ b/apps/dav/lib/Connector/Sabre/FilesPlugin.php @@ -229,11 +229,12 @@ public function handleDownloadToken(RequestInterface $request, ResponseInterface } } - public function httpGet(RequestInterface $request, ResponseInterface $response) { + public function httpGet(RequestInterface $request, ResponseInterface $response): bool { // only handle symlinks $node = $this->tree->getNodeForPath($request->getPath()); - if (!($node instanceof \OCA\DAV\Connector\Sabre\File && $this->symlinkManager->isSymlink($node->getFileInfo()))) { - return; + if (!($node instanceof \OCA\DAV\Connector\Sabre\File + && $this->symlinkManager->isSymlink($node->getFileInfo()))) { + return true; } $date = \DateTime::createFromFormat('U', $node->getLastModified()); @@ -255,7 +256,7 @@ public function httpGet(RequestInterface $request, ResponseInterface $response) * @param RequestInterface $request * @param ResponseInterface $response */ - public function afterHttpGet(RequestInterface $request, ResponseInterface $response) { + public function afterHttpGet(RequestInterface $request, ResponseInterface $response): void { // Only handle valid files $node = $this->tree->getNodeForPath($request->getPath()); if (!($node instanceof IFile)) { diff --git a/apps/dav/lib/Upload/SymlinkPlugin.php b/apps/dav/lib/Upload/SymlinkPlugin.php index 077899c7c4194..e619f52aa551a 100644 --- a/apps/dav/lib/Upload/SymlinkPlugin.php +++ b/apps/dav/lib/Upload/SymlinkPlugin.php @@ -33,7 +33,11 @@ use Sabre\HTTP\ResponseInterface; class SymlinkPlugin extends ServerPlugin { - /** @var Server */ + /** + * @var Server + * + * @psalm-suppress PropertyNotSetInConstructor + */ private $server; /** @var SymlinkManager */ private $symlinkManager; @@ -48,7 +52,7 @@ public function __construct(LoggerInterface $logger) { /** * @inheritdoc */ - public function initialize(Server $server) { + public function initialize(Server $server): void { $server->on('method:PUT', [$this, 'httpPut']); $server->on('method:DELETE', [$this, 'httpDelete']); $server->on('afterMove', [$this, 'afterMove']); @@ -74,7 +78,9 @@ public function httpPut(RequestInterface $request, ResponseInterface $response): $symlinkNode->put($symlinkTarget); $this->symlinkManager->storeSymlink($symlinkNode->getFileInfo()); - $response->setHeader("OC-ETag", $etag); + if ($etag) { + $response->setHeader('OC-ETag', $etag); + } $response->setStatus(201); return false; // this request was handled already } elseif ($this->server->tree->nodeExists($request->getPath())) { diff --git a/lib/private/Files/SymlinkManager.php b/lib/private/Files/SymlinkManager.php index f8592ad7060f7..a1c6937cb4efe 100644 --- a/lib/private/Files/SymlinkManager.php +++ b/lib/private/Files/SymlinkManager.php @@ -146,7 +146,7 @@ private function updateSymlink($node) { ->set('storage', $query->createNamedParameter($storageId)) ->set('path', $query->createNamedParameter($path)); if ($query->executeStatement() != 1) { - throw new \OCP\DB\Exception("Invalid number of rows changed while updating symlink!"); + throw new \OCP\DB\Exception('Invalid number of rows changed while updating symlink!'); } } @@ -164,7 +164,7 @@ private function insertSymlink($node) { ->setValue('storage', $query->createNamedParameter($storageId)) ->setValue('path', $query->createNamedParameter($path)); if ($query->executeStatement() != 1) { - throw new \OCP\DB\Exception("Invalid number of rows changed while inserting symlink!"); + throw new \OCP\DB\Exception('Invalid number of rows changed while inserting symlink!'); } } @@ -179,7 +179,7 @@ private function deleteSymlinkById($id) { ->where($query->expr()->eq('id', $query->createNamedParameter($id))); $rowsChanged = $query->executeStatement(); if ($rowsChanged > 1) { - throw new \OCP\DB\Exception("Too many symlink rows deleted!"); + throw new \OCP\DB\Exception('Too many symlink rows deleted!'); } return $rowsChanged == 1; }