Skip to content

Commit

Permalink
FilesPlugin/SymlinkPlugin/SymlinkManager: Fix some style guide violat…
Browse files Browse the repository at this point in the history
…ions and warnings

Signed-off-by: Tamino Bauknecht <[email protected]>
  • Loading branch information
taminob committed Dec 11, 2023
1 parent 2bc28c3 commit 2f7d601
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 10 deletions.
9 changes: 5 additions & 4 deletions apps/dav/lib/Connector/Sabre/FilesPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand All @@ -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)) {
Expand Down
12 changes: 9 additions & 3 deletions apps/dav/lib/Upload/SymlinkPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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']);
Expand All @@ -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())) {
Expand Down
6 changes: 3 additions & 3 deletions lib/private/Files/SymlinkManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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!');
}
}

Expand All @@ -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!');
}
}

Expand All @@ -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;
}
Expand Down

0 comments on commit 2f7d601

Please sign in to comment.