diff options
author | Côme Chilliet <come.chilliet@nextcloud.com> | 2023-03-13 18:59:16 +0100 |
---|---|---|
committer | Côme Chilliet <come.chilliet@nextcloud.com> | 2023-04-03 10:52:34 +0200 |
commit | ea05544213b6d472338684e9c7bae66f68453c58 (patch) | |
tree | 809724b54187a4d21fbe967b38b10fc4cb4ca38a /lib/private | |
parent | f974281ac9a086004c7e971f3585ed8aa21d194d (diff) | |
download | nextcloud-server-ea05544213b6d472338684e9c7bae66f68453c58.tar.gz nextcloud-server-ea05544213b6d472338684e9c7bae66f68453c58.zip |
Fix return type of methods returning false on error
Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
Diffstat (limited to 'lib/private')
-rw-r--r-- | lib/private/Files/Filesystem.php | 10 | ||||
-rw-r--r-- | lib/private/Files/SimpleFS/NewSimpleFile.php | 2 | ||||
-rw-r--r-- | lib/private/Files/SimpleFS/SimpleFile.php | 2 | ||||
-rw-r--r-- | lib/private/Files/Storage/LocalTempFileTrait.php | 16 | ||||
-rw-r--r-- | lib/private/Files/Storage/Wrapper/Encoding.php | 6 | ||||
-rw-r--r-- | lib/private/Files/Storage/Wrapper/EncodingDirectoryWrapper.php | 2 | ||||
-rw-r--r-- | lib/private/Files/Storage/Wrapper/Jail.php | 6 | ||||
-rw-r--r-- | lib/private/Files/Storage/Wrapper/Wrapper.php | 6 | ||||
-rw-r--r-- | lib/private/Files/View.php | 8 | ||||
-rw-r--r-- | lib/private/Security/CertificateManager.php | 30 | ||||
-rw-r--r-- | lib/private/Server.php | 2 |
11 files changed, 33 insertions, 57 deletions
diff --git a/lib/private/Files/Filesystem.php b/lib/private/Files/Filesystem.php index 74205351e60..367982eed72 100644 --- a/lib/private/Files/Filesystem.php +++ b/lib/private/Files/Filesystem.php @@ -420,11 +420,8 @@ class Filesystem { * return the path to a local version of the file * we need this because we can't know if a file is stored local or not from * outside the filestorage and for some purposes a local file is needed - * - * @param string $path - * @return string */ - public static function getLocalFile($path) { + public static function getLocalFile(string $path): string|false { return self::$defaultInstance->getLocalFile($path); } @@ -761,11 +758,8 @@ class Filesystem { /** * get the ETag for a file or folder - * - * @param string $path - * @return string */ - public static function getETag($path) { + public static function getETag(string $path): string|false { return self::$defaultInstance->getETag($path); } } diff --git a/lib/private/Files/SimpleFS/NewSimpleFile.php b/lib/private/Files/SimpleFS/NewSimpleFile.php index 1d0972bcc54..50511b5a5f9 100644 --- a/lib/private/Files/SimpleFS/NewSimpleFile.php +++ b/lib/private/Files/SimpleFS/NewSimpleFile.php @@ -196,7 +196,7 @@ class NewSimpleFile implements ISimpleFile { /** * Open the file as stream for reading, resulting resource can be operated as stream like the result from php's own fopen * - * @return resource + * @return resource|false * @throws \OCP\Files\NotPermittedException * @since 14.0.0 */ diff --git a/lib/private/Files/SimpleFS/SimpleFile.php b/lib/private/Files/SimpleFS/SimpleFile.php index 95ef332e2f5..76ab06feaab 100644 --- a/lib/private/Files/SimpleFS/SimpleFile.php +++ b/lib/private/Files/SimpleFS/SimpleFile.php @@ -150,7 +150,7 @@ class SimpleFile implements ISimpleFile { /** * Open the file as stream for reading, resulting resource can be operated as stream like the result from php's own fopen * - * @return resource + * @return resource|false * @throws \OCP\Files\NotPermittedException * @since 14.0.0 */ diff --git a/lib/private/Files/Storage/LocalTempFileTrait.php b/lib/private/Files/Storage/LocalTempFileTrait.php index 2ac0a74b692..314e38cb277 100644 --- a/lib/private/Files/Storage/LocalTempFileTrait.php +++ b/lib/private/Files/Storage/LocalTempFileTrait.php @@ -35,14 +35,10 @@ namespace OC\Files\Storage; * in classes which extend it, e.g. $this->stat() . */ trait LocalTempFileTrait { - /** @var string[] */ - protected $cachedFiles = []; + /** @var array<string,string|false> */ + protected array $cachedFiles = []; - /** - * @param string $path - * @return string - */ - protected function getCachedFile($path) { + protected function getCachedFile(string $path): string|false { if (!isset($this->cachedFiles[$path])) { $this->cachedFiles[$path] = $this->toTmpFile($path); } @@ -56,11 +52,7 @@ trait LocalTempFileTrait { unset($this->cachedFiles[$path]); } - /** - * @param string $path - * @return string - */ - protected function toTmpFile($path) { //no longer in the storage api, still useful here + protected function toTmpFile(string $path): string|false { //no longer in the storage api, still useful here $source = $this->fopen($path, 'r'); if (!$source) { return false; diff --git a/lib/private/Files/Storage/Wrapper/Encoding.php b/lib/private/Files/Storage/Wrapper/Encoding.php index d6006f746ad..dd699993e84 100644 --- a/lib/private/Files/Storage/Wrapper/Encoding.php +++ b/lib/private/Files/Storage/Wrapper/Encoding.php @@ -159,7 +159,7 @@ class Encoding extends Wrapper { * see https://www.php.net/manual/en/function.opendir.php * * @param string $path - * @return resource|bool + * @return resource|false */ public function opendir($path) { $handle = $this->storage->opendir($this->findPathToUse($path)); @@ -429,7 +429,7 @@ class Encoding extends Wrapper { * The local version of the file can be temporary and doesn't have to be persistent across requests * * @param string $path - * @return string|bool + * @return string|false */ public function getLocalFile($path) { return $this->storage->getLocalFile($this->findPathToUse($path)); @@ -481,7 +481,7 @@ class Encoding extends Wrapper { * get the ETag for a file or folder * * @param string $path - * @return string|bool + * @return string|false */ public function getETag($path) { return $this->storage->getETag($this->findPathToUse($path)); diff --git a/lib/private/Files/Storage/Wrapper/EncodingDirectoryWrapper.php b/lib/private/Files/Storage/Wrapper/EncodingDirectoryWrapper.php index fd0d2707f8d..3cda399f22d 100644 --- a/lib/private/Files/Storage/Wrapper/EncodingDirectoryWrapper.php +++ b/lib/private/Files/Storage/Wrapper/EncodingDirectoryWrapper.php @@ -46,7 +46,7 @@ class EncodingDirectoryWrapper extends DirectoryWrapper { /** * @param resource $source * @param callable $filter - * @return resource|bool + * @return resource|false */ public static function wrap($source) { return self::wrapSource($source, [ diff --git a/lib/private/Files/Storage/Wrapper/Jail.php b/lib/private/Files/Storage/Wrapper/Jail.php index e21a2cba244..619d8b07137 100644 --- a/lib/private/Files/Storage/Wrapper/Jail.php +++ b/lib/private/Files/Storage/Wrapper/Jail.php @@ -108,7 +108,7 @@ class Jail extends Wrapper { * see https://www.php.net/manual/en/function.opendir.php * * @param string $path - * @return resource|bool + * @return resource|false */ public function opendir($path) { return $this->getWrapperStorage()->opendir($this->getUnjailedPath($path)); @@ -368,7 +368,7 @@ class Jail extends Wrapper { * The local version of the file can be temporary and doesn't have to be persistent across requests * * @param string $path - * @return string|bool + * @return string|false */ public function getLocalFile($path) { return $this->getWrapperStorage()->getLocalFile($this->getUnjailedPath($path)); @@ -431,7 +431,7 @@ class Jail extends Wrapper { * get the ETag for a file or folder * * @param string $path - * @return string|bool + * @return string|false */ public function getETag($path) { return $this->getWrapperStorage()->getETag($this->getUnjailedPath($path)); diff --git a/lib/private/Files/Storage/Wrapper/Wrapper.php b/lib/private/Files/Storage/Wrapper/Wrapper.php index c2d382f5dfc..28a1e0b1e4d 100644 --- a/lib/private/Files/Storage/Wrapper/Wrapper.php +++ b/lib/private/Files/Storage/Wrapper/Wrapper.php @@ -98,7 +98,7 @@ class Wrapper implements \OC\Files\Storage\Storage, ILockingStorage, IWriteStrea * see https://www.php.net/manual/en/function.opendir.php * * @param string $path - * @return resource|bool + * @return resource|false */ public function opendir($path) { return $this->getWrapperStorage()->opendir($path); @@ -358,7 +358,7 @@ class Wrapper implements \OC\Files\Storage\Storage, ILockingStorage, IWriteStrea * The local version of the file can be temporary and doesn't have to be persistent across requests * * @param string $path - * @return string|bool + * @return string|false */ public function getLocalFile($path) { return $this->getWrapperStorage()->getLocalFile($path); @@ -456,7 +456,7 @@ class Wrapper implements \OC\Files\Storage\Storage, ILockingStorage, IWriteStrea * get the ETag for a file or folder * * @param string $path - * @return string|bool + * @return string|false */ public function getETag($path) { return $this->getWrapperStorage()->getETag($path); diff --git a/lib/private/Files/View.php b/lib/private/Files/View.php index 4ee44b995b3..fd264a77cba 100644 --- a/lib/private/Files/View.php +++ b/lib/private/Files/View.php @@ -223,7 +223,7 @@ class View { * * @param string $path */ - public function getLocalFile($path): string|bool { + public function getLocalFile($path): string|false { $parent = substr($path, 0, strrpos($path, '/') ?: 0); $path = $this->getAbsolutePath($path); [$storage, $internalPath] = Filesystem::resolvePath($path); @@ -333,7 +333,7 @@ class View { /** * @param string $path - * @return resource + * @return resource|false */ public function opendir($path) { return $this->basicOperation('opendir', $path, ['read']); @@ -1680,14 +1680,14 @@ class View { * get the ETag for a file or folder * * @param string $path - * @return string + * @return string|false */ public function getETag($path) { [$storage, $internalPath] = $this->resolvePath($path); if ($storage) { return $storage->getETag($internalPath); } else { - return null; + return false; } } diff --git a/lib/private/Security/CertificateManager.php b/lib/private/Security/CertificateManager.php index fa26c19ceae..be884654bd0 100644 --- a/lib/private/Security/CertificateManager.php +++ b/lib/private/Security/CertificateManager.php @@ -33,6 +33,7 @@ declare(strict_types=1); namespace OC\Security; use OC\Files\Filesystem; +use OC\Files\View; use OCP\ICertificate; use OCP\ICertificateManager; use OCP\IConfig; @@ -43,24 +44,14 @@ use Psr\Log\LoggerInterface; * Manage trusted certificates for users */ class CertificateManager implements ICertificateManager { - /** - * @var \OC\Files\View - */ - protected $view; - - /** - * @var IConfig - */ - protected $config; - + protected View $view; + protected IConfig $config; protected LoggerInterface $logger; - - /** @var ISecureRandom */ - protected $random; + protected ISecureRandom $random; private ?string $bundlePath = null; - public function __construct(\OC\Files\View $view, + public function __construct(View $view, IConfig $config, LoggerInterface $logger, ISecureRandom $random) { @@ -233,8 +224,7 @@ class CertificateManager implements ICertificateManager { /** * Get the full local path to the certificate bundle - * - * @return string + * @throws \Exception when getting bundle path fails */ public function getAbsoluteBundlePath(): string { try { @@ -247,7 +237,10 @@ class CertificateManager implements ICertificateManager { $this->createCertificateBundle(); } - $this->bundlePath = $this->view->getLocalFile($this->getCertificateBundle()); + $this->bundlePath = $this->view->getLocalFile($this->getCertificateBundle()) ?: null; + } + if ($this->bundlePath === null) { + throw new \Exception('Failed to get absolute bundle path'); } return $this->bundlePath; } catch (\Exception $e) { @@ -255,9 +248,6 @@ class CertificateManager implements ICertificateManager { } } - /** - * @return string - */ private function getPathToCertificates(): string { return '/files_external/'; } diff --git a/lib/private/Server.php b/lib/private/Server.php index f1e96170886..97762e4b29b 100644 --- a/lib/private/Server.php +++ b/lib/private/Server.php @@ -439,7 +439,7 @@ class Server extends ServerContainer implements IServerContainer { return $c->get('SystemTagManagerFactory')->getObjectMapper(); }); $this->registerService('RootFolder', function (ContainerInterface $c) { - $manager = \OC\Files\Filesystem::getMountManager(null); + $manager = \OC\Files\Filesystem::getMountManager(); $view = new View(); $root = new Root( $manager, |