From 6d8ffb381f82549846c54c94ce2fb93732b5a02b Mon Sep 17 00:00:00 2001 From: provokateurin Date: Tue, 1 Oct 2024 16:14:04 +0200 Subject: [PATCH] refactor(files_trashbin): Add Storage parameter strong types Signed-off-by: provokateurin --- apps/files_trashbin/lib/Storage.php | 13 +++++-------- apps/files_trashbin/tests/StorageTest.php | 4 ++-- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/apps/files_trashbin/lib/Storage.php b/apps/files_trashbin/lib/Storage.php index 23a0e5bd919..c6f90b175b9 100644 --- a/apps/files_trashbin/lib/Storage.php +++ b/apps/files_trashbin/lib/Storage.php @@ -48,7 +48,7 @@ class Storage extends Wrapper { parent::__construct($parameters); } - public function unlink($path): bool { + public function unlink(string $path): bool { if ($this->trashEnabled) { try { return $this->doDelete($path, 'unlink'); @@ -65,7 +65,7 @@ class Storage extends Wrapper { } } - public function rmdir($path): bool { + public function rmdir(string $path): bool { if ($this->trashEnabled) { return $this->doDelete($path, 'rmdir'); } else { @@ -76,11 +76,8 @@ class Storage extends Wrapper { /** * check if it is a file located in data/user/files only files in the * 'files' directory should be moved to the trash - * - * @param $path - * @return bool */ - protected function shouldMoveToTrash($path): bool { + protected function shouldMoveToTrash(string $path): bool { $normalized = Filesystem::normalizePath($this->mountPoint . '/' . $path); $parts = explode('/', $normalized); if (count($parts) < 4 || strpos($normalized, '/appdata_') === 0) { @@ -130,7 +127,7 @@ class Storage extends Wrapper { * * @return bool true if the operation succeeded, false otherwise */ - private function doDelete($path, $method): bool { + private function doDelete(string $path, string $method): bool { if ( !\OC::$server->getAppManager()->isEnabledForUser('files_trashbin') || (pathinfo($path, PATHINFO_EXTENSION) === 'part') @@ -181,7 +178,7 @@ class Storage extends Wrapper { return $this->mountPoint; } - public function moveFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath): bool { + public function moveFromStorage(IStorage $sourceStorage, string $sourceInternalPath, string $targetInternalPath): bool { $sourceIsTrashbin = $sourceStorage->instanceOfStorage(Storage::class); try { // the fallback for moving between storage involves a copy+delete diff --git a/apps/files_trashbin/tests/StorageTest.php b/apps/files_trashbin/tests/StorageTest.php index 65e4d9a9bca..8271109037c 100644 --- a/apps/files_trashbin/tests/StorageTest.php +++ b/apps/files_trashbin/tests/StorageTest.php @@ -28,11 +28,11 @@ use Psr\Log\LoggerInterface; use Test\Traits\MountProviderTrait; class TemporaryNoCross extends Temporary { - public function copyFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath, $preserveMtime = null): bool { + public function copyFromStorage(IStorage $sourceStorage, string $sourceInternalPath, string $targetInternalPath, ?bool $preserveMtime = null): bool { return Common::copyFromStorage($sourceStorage, $sourceInternalPath, $targetInternalPath, $preserveMtime); } - public function moveFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath): bool { + public function moveFromStorage(IStorage $sourceStorage, string $sourceInternalPath, string $targetInternalPath): bool { return Common::moveFromStorage($sourceStorage, $sourceInternalPath, $targetInternalPath); } } -- 2.39.5