diff options
author | Robin Appelman <robin@icewind.nl> | 2022-02-18 16:42:11 +0100 |
---|---|---|
committer | Robin Appelman <robin@icewind.nl> | 2022-03-04 16:26:08 +0100 |
commit | a6f245f6ffca51dd72149ac5e82b17fa7589ae02 (patch) | |
tree | 8f27b08dbf657296011ef3f060b8c0d804fe8501 /apps/files_external | |
parent | 5b77099612286061f8a48618ffa513dcf6aa4c31 (diff) | |
download | nextcloud-server-a6f245f6ffca51dd72149ac5e82b17fa7589ae02.tar.gz nextcloud-server-a6f245f6ffca51dd72149ac5e82b17fa7589ae02.zip |
type hint as generator
Signed-off-by: Robin Appelman <robin@icewind.nl>
Diffstat (limited to 'apps/files_external')
-rw-r--r-- | apps/files_external/lib/Lib/Storage/SMB.php | 23 |
1 files changed, 14 insertions, 9 deletions
diff --git a/apps/files_external/lib/Lib/Storage/SMB.php b/apps/files_external/lib/Lib/Storage/SMB.php index 78918343cee..6464264f3a4 100644 --- a/apps/files_external/lib/Lib/Storage/SMB.php +++ b/apps/files_external/lib/Lib/Storage/SMB.php @@ -85,7 +85,7 @@ class SMB extends Common implements INotifyStorage { protected $root; /** - * @var \Icewind\SMB\IFileInfo[] + * @var IFileInfo[] */ protected $statCache; @@ -180,20 +180,24 @@ class SMB extends Common implements INotifyStorage { /** * @param string $path - * @return \Icewind\SMB\IFileInfo + * @return IFileInfo * @throws StorageAuthException */ protected function getFileInfo($path) { try { $path = $this->buildPath($path); - if (!isset($this->statCache[$path])) { - $this->statCache[$path] = $this->share->stat($path); + $cached = $this->statCache[$path] ?? null; + if ($cached instanceof IFileInfo) { + return $cached; + } else { + $stat = $this->share->stat($path); + $this->statCache[$path] = $stat; + return $stat; } - return $this->statCache[$path]; } catch (ConnectException $e) { $this->throwUnavailable($e); } catch (ForbiddenException $e) { - // with php-smbclient, this exceptions is thrown when the provided password is invalid. + // with php-smbclient, this exception is thrown when the provided password is invalid. // Possible is also ForbiddenException with a different error code, so we check it. if ($e->getCode() === 1) { $this->throwUnavailable($e); @@ -204,6 +208,7 @@ class SMB extends Common implements INotifyStorage { /** * @param \Exception $e + * @return never * @throws StorageAuthException */ protected function throwUnavailable(\Exception $e) { @@ -231,7 +236,7 @@ class SMB extends Common implements INotifyStorage { /** * @param string $path - * @return \Icewind\SMB\IFileInfo[] + * @return \Generator<IFileInfo> * @throws StorageNotAvailableException */ protected function getFolderContents($path): iterable { @@ -284,7 +289,7 @@ class SMB extends Common implements INotifyStorage { } /** - * @param \Icewind\SMB\IFileInfo $info + * @param IFileInfo $info * @return array */ protected function formatInfo($info) { @@ -616,7 +621,7 @@ class SMB extends Common implements INotifyStorage { return false; } $names = array_map(function ($info) { - /** @var \Icewind\SMB\IFileInfo $info */ + /** @var IFileInfo $info */ return $info->getName(); }, iterator_to_array($files)); return IteratorDirectory::wrap($names); |