Add some typing to SharedStorage

Makes psalm a bit more happy.

Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
This commit is contained in:
Roeland Jago Douma 2021-03-03 12:49:56 +01:00
parent 9b573c6bd5
commit 7b9ca4f7c2
2 changed files with 27 additions and 27 deletions

View File

@ -45,6 +45,7 @@ use OCP\Files\NotFoundException;
use OCP\Files\Storage\IDisableEncryptionStorage; use OCP\Files\Storage\IDisableEncryptionStorage;
use OCP\Files\Storage\IStorage; use OCP\Files\Storage\IStorage;
use OCP\Lock\ILockingProvider; use OCP\Lock\ILockingProvider;
use OCP\Share\IShare;
/** /**
* Convert target path to source path and pass the function call to the correct storage provider * Convert target path to source path and pass the function call to the correct storage provider
@ -159,7 +160,7 @@ class SharedStorage extends \OC\Files\Storage\Wrapper\Jail implements ISharedSto
/** /**
* @inheritdoc * @inheritdoc
*/ */
public function instanceOfStorage($class) { public function instanceOfStorage($class): bool {
if ($class === '\OC\Files\Storage\Common') { if ($class === '\OC\Files\Storage\Common') {
return true; return true;
} }
@ -176,7 +177,7 @@ class SharedStorage extends \OC\Files\Storage\Wrapper\Jail implements ISharedSto
return $this->superShare->getId(); return $this->superShare->getId();
} }
private function isValid() { private function isValid(): bool {
return $this->getSourceRootInfo() && ($this->getSourceRootInfo()->getPermissions() & Constants::PERMISSION_SHARE) === Constants::PERMISSION_SHARE; return $this->getSourceRootInfo() && ($this->getSourceRootInfo()->getPermissions() & Constants::PERMISSION_SHARE) === Constants::PERMISSION_SHARE;
} }
@ -185,7 +186,7 @@ class SharedStorage extends \OC\Files\Storage\Wrapper\Jail implements ISharedSto
* *
* @return string * @return string
*/ */
public function getId() { public function getId(): string {
return 'shared::' . $this->getMountPoint(); return 'shared::' . $this->getMountPoint();
} }
@ -195,7 +196,7 @@ class SharedStorage extends \OC\Files\Storage\Wrapper\Jail implements ISharedSto
* @param string $target Shared target file path * @param string $target Shared target file path
* @return int CRUDS permissions granted * @return int CRUDS permissions granted
*/ */
public function getPermissions($target = '') { public function getPermissions($target = ''): int {
if (!$this->isValid()) { if (!$this->isValid()) {
return 0; return 0;
} }
@ -213,11 +214,11 @@ class SharedStorage extends \OC\Files\Storage\Wrapper\Jail implements ISharedSto
return $permissions; return $permissions;
} }
public function isCreatable($path) { public function isCreatable($path): bool {
return ($this->getPermissions($path) & \OCP\Constants::PERMISSION_CREATE); return (bool)($this->getPermissions($path) & \OCP\Constants::PERMISSION_CREATE);
} }
public function isReadable($path) { public function isReadable($path): bool {
if (!$this->isValid()) { if (!$this->isValid()) {
return false; return false;
} }
@ -230,19 +231,19 @@ class SharedStorage extends \OC\Files\Storage\Wrapper\Jail implements ISharedSto
return $storage->isReadable($internalPath); return $storage->isReadable($internalPath);
} }
public function isUpdatable($path) { public function isUpdatable($path): bool {
return ($this->getPermissions($path) & \OCP\Constants::PERMISSION_UPDATE); return (bool)($this->getPermissions($path) & \OCP\Constants::PERMISSION_UPDATE);
} }
public function isDeletable($path) { public function isDeletable($path): bool {
return ($this->getPermissions($path) & \OCP\Constants::PERMISSION_DELETE); return (bool)($this->getPermissions($path) & \OCP\Constants::PERMISSION_DELETE);
} }
public function isSharable($path) { public function isSharable($path): bool {
if (\OCP\Util::isSharingDisabledForUser() || !\OC\Share\Share::isResharingAllowed()) { if (\OCP\Util::isSharingDisabledForUser() || !\OC\Share\Share::isResharingAllowed()) {
return false; return false;
} }
return ($this->getPermissions($path) & \OCP\Constants::PERMISSION_SHARE); return (bool)($this->getPermissions($path) & \OCP\Constants::PERMISSION_SHARE);
} }
public function fopen($path, $mode) { public function fopen($path, $mode) {
@ -304,7 +305,7 @@ class SharedStorage extends \OC\Files\Storage\Wrapper\Jail implements ISharedSto
* @param string $path2 * @param string $path2
* @return bool * @return bool
*/ */
public function rename($path1, $path2) { public function rename($path1, $path2): bool {
$this->init(); $this->init();
$isPartFile = pathinfo($path1, PATHINFO_EXTENSION) === 'part'; $isPartFile = pathinfo($path1, PATHINFO_EXTENSION) === 'part';
$targetExists = $this->file_exists($path2); $targetExists = $this->file_exists($path2);
@ -328,14 +329,14 @@ class SharedStorage extends \OC\Files\Storage\Wrapper\Jail implements ISharedSto
* *
* @return string * @return string
*/ */
public function getMountPoint() { public function getMountPoint(): string {
return $this->superShare->getTarget(); return $this->superShare->getTarget();
} }
/** /**
* @param string $path * @param string $path
*/ */
public function setMountPoint($path) { public function setMountPoint($path): void {
$this->superShare->setTarget($path); $this->superShare->setTarget($path);
foreach ($this->groupedShares as $share) { foreach ($this->groupedShares as $share) {
@ -348,14 +349,14 @@ class SharedStorage extends \OC\Files\Storage\Wrapper\Jail implements ISharedSto
* *
* @return string * @return string
*/ */
public function getSharedFrom() { public function getSharedFrom(): string {
return $this->superShare->getShareOwner(); return $this->superShare->getShareOwner();
} }
/** /**
* @return \OCP\Share\IShare * @return \OCP\Share\IShare
*/ */
public function getShare() { public function getShare(): IShare {
return $this->superShare; return $this->superShare;
} }
@ -364,7 +365,7 @@ class SharedStorage extends \OC\Files\Storage\Wrapper\Jail implements ISharedSto
* *
* @return string * @return string
*/ */
public function getItemType() { public function getItemType(): string {
return $this->superShare->getNodeType(); return $this->superShare->getNodeType();
} }
@ -396,11 +397,11 @@ class SharedStorage extends \OC\Files\Storage\Wrapper\Jail implements ISharedSto
return new \OCA\Files_Sharing\Scanner($storage); return new \OCA\Files_Sharing\Scanner($storage);
} }
public function getOwner($path) { public function getOwner($path): string {
return $this->superShare->getShareOwner(); return $this->superShare->getShareOwner();
} }
public function getWatcher($path = '', $storage = null) { public function getWatcher($path = '', $storage = null): NullWatcher {
// cache updating is handled by the share source // cache updating is handled by the share source
return new NullWatcher(); return new NullWatcher();
} }
@ -410,7 +411,7 @@ class SharedStorage extends \OC\Files\Storage\Wrapper\Jail implements ISharedSto
* *
* @return bool * @return bool
*/ */
public function unshareStorage() { public function unshareStorage(): bool {
foreach ($this->groupedShares as $share) { foreach ($this->groupedShares as $share) {
\OC::$server->getShareManager()->deleteFromSelf($share, $this->user); \OC::$server->getShareManager()->deleteFromSelf($share, $this->user);
} }

View File

@ -197,11 +197,10 @@ class ScannerTest extends \Test\TestCase {
$sharedMount = new MountPoint($sharedStorage, '/share'); $sharedMount = new MountPoint($sharedStorage, '/share');
Filesystem::getMountManager()->addMount($sharedMount); Filesystem::getMountManager()->addMount($sharedMount);
$sharedStorage->expects($this->any()) $sharedStorage->method('instanceOfStorage')
->method('instanceOfStorage') ->willReturnCallback(function (string $c) {
->willReturnMap([ return $c === SharedStorage::class;
[SharedStorage::class, true], });
]);
$sharedStorage->expects($this->never()) $sharedStorage->expects($this->never())
->method('getScanner'); ->method('getScanner');