From 7472ad7c3685667f8fdb35e9e8f40dbdcf568fa1 Mon Sep 17 00:00:00 2001 From: Git'Fellow <12234510+solracsf@users.noreply.github.com> Date: Wed, 4 Sep 2024 11:17:55 +0200 Subject: [PATCH] chore(storage): refactor some code portions Signed-off-by: Git'Fellow <12234510+solracsf@users.noreply.github.com> chore: revert portion Signed-off-by: Git'Fellow <12234510+solracsf@users.noreply.github.com> --- lib/private/Files/Storage/DAV.php | 46 +++++++++++-------------------- 1 file changed, 16 insertions(+), 30 deletions(-) diff --git a/lib/private/Files/Storage/DAV.php b/lib/private/Files/Storage/DAV.php index 7abc0ccc18245..ac9b7a7285593 100644 --- a/lib/private/Files/Storage/DAV.php +++ b/lib/private/Files/Storage/DAV.php @@ -23,6 +23,7 @@ use OCP\Http\Client\IClientService; use OCP\ICertificateManager; use OCP\IConfig; +use OCP\Server; use OCP\Util; use Psr\Http\Message\ResponseInterface; use Psr\Log\LoggerInterface; @@ -86,7 +87,7 @@ class DAV extends Common { */ public function __construct($params) { $this->statCache = new ArrayCache(); - $this->httpClientService = \OC::$server->get(IClientService::class); + $this->httpClientService = Server::get(IClientService::class); if (isset($params['host']) && isset($params['user']) && isset($params['password'])) { $host = $params['host']; //remove leading http[s], will be generated in createBaseUri() @@ -120,10 +121,10 @@ public function __construct($params) { } else { throw new \Exception('Invalid webdav storage configuration'); } - $this->logger = \OC::$server->get(LoggerInterface::class); - $this->eventLogger = \OC::$server->get(IEventLogger::class); + $this->logger = Server::get(LoggerInterface::class); + $this->eventLogger = Server::get(IEventLogger::class); // This timeout value will be used for the download and upload of files - $this->timeout = \OC::$server->get(IConfig::class)->getSystemValueInt('davstorage.request_timeout', 30); + $this->timeout = Server::get(IConfig::class)->getSystemValueInt('davstorage.request_timeout', 30); $this->mimeTypeDetector = \OC::$server->getMimeTypeDetector(); } @@ -142,7 +143,7 @@ protected function init() { $settings['authType'] = $this->authType; } - $proxy = \OC::$server->getConfig()->getSystemValueString('proxy', ''); + $proxy = Server::get(IConfig::class)->getSystemValueString('proxy', ''); if ($proxy !== '') { $settings['proxy'] = $proxy; } @@ -287,7 +288,7 @@ public function filetype($path) { /** @var ResourceType[] $response */ $responseType = $response['{DAV:}resourcetype']->getValue(); } - return (count($responseType) > 0 and $responseType[0] == '{DAV:}collection') ? 'dir' : 'file'; + return (count($responseType) > 0 && $responseType[0] == '{DAV:}collection') ? 'dir' : 'file'; } catch (\Exception $e) { $this->convertException($e, $path); } @@ -352,7 +353,7 @@ public function fopen($path, $mode) { if ($response->getStatusCode() === Http::STATUS_LOCKED) { throw new \OCP\Lock\LockedException($path); } else { - \OC::$server->get(LoggerInterface::class)->error('Guzzle get returned status code ' . $response->getStatusCode(), ['app' => 'webdav client']); + Server::get(LoggerInterface::class)->error('Guzzle get returned status code ' . $response->getStatusCode(), ['app' => 'webdav client']); } } @@ -380,7 +381,7 @@ public function fopen($path, $mode) { if (!$this->isUpdatable($path)) { return false; } - if ($mode === 'w' or $mode === 'w+') { + if ($mode === 'w' || $mode === 'w+') { $tmpFile = $tempManager->getTemporaryFile($ext); } else { $tmpFile = $this->getCachedFile($path); @@ -586,7 +587,7 @@ private function getMetaFromPropfind(string $path, array $response): array { /** @var ResourceType[] $response */ $responseType = $response['{DAV:}resourcetype']->getValue(); } - $type = (count($responseType) > 0 and $responseType[0] == '{DAV:}collection') ? 'dir' : 'file'; + $type = (count($responseType) > 0 && $responseType[0] == '{DAV:}collection') ? 'dir' : 'file'; if ($type === 'dir') { $mimeType = 'httpd/unix-directory'; } elseif (isset($response['{DAV:}getcontenttype'])) { @@ -625,21 +626,14 @@ private function getMetaFromPropfind(string $path, array $response): array { /** {@inheritdoc} */ public function stat($path) { $meta = $this->getMetaData($path); - if (!$meta) { - return false; - } else { - return $meta; - } + return $meta ?: false; + } /** {@inheritdoc} */ public function getMimeType($path) { $meta = $this->getMetaData($path); - if ($meta) { - return $meta['mimetype']; - } else { - return false; - } + return $meta ? $meta['mimetype'] : false; } /** @@ -724,21 +718,13 @@ public function isDeletable($path) { /** {@inheritdoc} */ public function getPermissions($path) { $stat = $this->getMetaData($path); - if ($stat) { - return $stat['permissions']; - } else { - return 0; - } + return $stat ? $stat['permissions'] : 0; } /** {@inheritdoc} */ public function getETag($path) { $meta = $this->getMetaData($path); - if ($meta) { - return $meta['etag']; - } else { - return null; - } + return $meta ? $meta['etag'] : null; } /** @@ -838,7 +824,7 @@ public function hasUpdated($path, $time) { * @throws ForbiddenException if the action is not allowed */ protected function convertException(Exception $e, $path = '') { - \OC::$server->get(LoggerInterface::class)->debug($e->getMessage(), ['app' => 'files_external', 'exception' => $e]); + Server::get(LoggerInterface::class)->debug($e->getMessage(), ['app' => 'files_external', 'exception' => $e]); if ($e instanceof ClientHttpException) { if ($e->getHttpStatus() === Http::STATUS_LOCKED) { throw new \OCP\Lock\LockedException($path);