diff options
Diffstat (limited to 'apps')
-rw-r--r-- | apps/dav/lib/Connector/Sabre/File.php | 14 | ||||
-rw-r--r-- | apps/dav/tests/unit/Connector/Sabre/FileTest.php | 6 | ||||
-rw-r--r-- | apps/dav/tests/unit/Connector/Sabre/NodeTest.php | 8 | ||||
-rw-r--r-- | apps/encryption/tests/Crypto/EncryptionTest.php | 8 | ||||
-rw-r--r-- | apps/encryption/tests/KeyManagerTest.php | 4 | ||||
-rw-r--r-- | apps/encryption/tests/UtilTest.php | 4 | ||||
-rw-r--r-- | apps/files_external/lib/Config/ConfigAdapter.php | 20 | ||||
-rw-r--r-- | apps/files_external/lib/Lib/Auth/Password/SessionCredentials.php | 4 | ||||
-rw-r--r-- | apps/files_external/lib/Lib/StorageModifierTrait.php | 12 | ||||
-rw-r--r-- | apps/files_sharing/tests/Controller/ShareAPIControllerTest.php | 32 |
10 files changed, 54 insertions, 58 deletions
diff --git a/apps/dav/lib/Connector/Sabre/File.php b/apps/dav/lib/Connector/Sabre/File.php index 0b9199492fe..34cc2b77b37 100644 --- a/apps/dav/lib/Connector/Sabre/File.php +++ b/apps/dav/lib/Connector/Sabre/File.php @@ -28,7 +28,7 @@ use OCP\Files\InvalidPathException; use OCP\Files\LockNotAcquiredException; use OCP\Files\NotFoundException; use OCP\Files\NotPermittedException; -use OCP\Files\Storage; +use OCP\Files\Storage\IWriteStreamStorage; use OCP\Files\StorageNotAvailableException; use OCP\IL10N; use OCP\IRequest; @@ -117,8 +117,10 @@ class File extends Node implements IFile { // verify path of the target $this->verifyPath(); - /** @var Storage $partStorage */ [$partStorage] = $this->fileView->resolvePath($this->path); + if ($partStorage === null) { + throw new ServiceUnavailable($this->l10n->t('Failed to get storage for file')); + } $needsPartFile = $partStorage->needsPartFile() && (strlen($this->path) > 1); $view = \OC\Files\Filesystem::getView(); @@ -141,10 +143,11 @@ class File extends Node implements IFile { } // the part file and target file might be on a different storage in case of a single file storage (e.g. single file share) - /** @var \OC\Files\Storage\Storage $partStorage */ [$partStorage, $internalPartPath] = $this->fileView->resolvePath($partFilePath); - /** @var \OC\Files\Storage\Storage $storage */ [$storage, $internalPath] = $this->fileView->resolvePath($this->path); + if ($partStorage === null || $storage === null) { + throw new ServiceUnavailable($this->l10n->t('Failed to get storage for file')); + } try { if (!$needsPartFile) { try { @@ -196,7 +199,7 @@ class File extends Node implements IFile { } } - if ($partStorage->instanceOfStorage(Storage\IWriteStreamStorage::class)) { + if ($partStorage->instanceOfStorage(IWriteStreamStorage::class)) { $isEOF = false; $wrappedData = CallbackWrapper::wrap($data, null, null, null, null, function ($stream) use (&$isEOF) { $isEOF = feof($stream); @@ -535,7 +538,6 @@ class File extends Node implements IFile { if (\OCP\Server::get(\OCP\App\IAppManager::class)->isEnabledForUser('encryption')) { return []; } - /** @var \OCP\Files\Storage $storage */ [$storage, $internalPath] = $this->fileView->resolvePath($this->path); if (is_null($storage)) { return []; diff --git a/apps/dav/tests/unit/Connector/Sabre/FileTest.php b/apps/dav/tests/unit/Connector/Sabre/FileTest.php index 6f9a214fab9..07128a1c7af 100644 --- a/apps/dav/tests/unit/Connector/Sabre/FileTest.php +++ b/apps/dav/tests/unit/Connector/Sabre/FileTest.php @@ -17,7 +17,7 @@ use OCA\DAV\Connector\Sabre\File; use OCP\Constants; use OCP\Files\FileInfo; use OCP\Files\ForbiddenException; -use OCP\Files\Storage; +use OCP\Files\Storage\IStorage; use OCP\IConfig; use OCP\IRequestId; use OCP\ITempManager; @@ -73,10 +73,10 @@ class FileTest extends TestCase { } /** - * @return MockObject|Storage + * @return MockObject|IStorage */ private function getMockStorage() { - $storage = $this->getMockBuilder(Storage::class) + $storage = $this->getMockBuilder(IStorage::class) ->disableOriginalConstructor() ->getMock(); $storage->method('getId') diff --git a/apps/dav/tests/unit/Connector/Sabre/NodeTest.php b/apps/dav/tests/unit/Connector/Sabre/NodeTest.php index 83f4139a2d9..c5e2b03d8b4 100644 --- a/apps/dav/tests/unit/Connector/Sabre/NodeTest.php +++ b/apps/dav/tests/unit/Connector/Sabre/NodeTest.php @@ -18,7 +18,7 @@ use OCA\Files_Sharing\SharedStorage; use OCP\Constants; use OCP\Files\Cache\ICacheEntry; use OCP\Files\Mount\IMountPoint; -use OCP\Files\Storage; +use OCP\Files\Storage\IStorage; use OCP\ICache; use OCP\Share\IManager; use OCP\Share\IShare; @@ -75,7 +75,7 @@ class NodeTest extends \Test\TestCase { return $this->createMock(MountPoint::class); } }); - $storage = $this->createMock(Storage\IStorage::class); + $storage = $this->createMock(IStorage::class); if ($shared) { $storage->method('instanceOfStorage') ->willReturn(true); @@ -145,7 +145,7 @@ class NodeTest extends \Test\TestCase { * @dataProvider sharePermissionsProvider */ public function testSharePermissions($type, $user, $permissions, $expected): void { - $storage = $this->getMockBuilder(Storage::class) + $storage = $this->getMockBuilder(IStorage::class) ->disableOriginalConstructor() ->getMock(); $storage->method('getPermissions')->willReturn($permissions); @@ -223,7 +223,7 @@ class NodeTest extends \Test\TestCase { } public function testShareAttributesNonShare(): void { - $storage = $this->getMockBuilder(Storage::class) + $storage = $this->getMockBuilder(IStorage::class) ->disableOriginalConstructor() ->getMock(); diff --git a/apps/encryption/tests/Crypto/EncryptionTest.php b/apps/encryption/tests/Crypto/EncryptionTest.php index b07bd0a6b25..10f85f7e74e 100644 --- a/apps/encryption/tests/Crypto/EncryptionTest.php +++ b/apps/encryption/tests/Crypto/EncryptionTest.php @@ -15,8 +15,9 @@ use OCA\Encryption\Exceptions\PublicKeyMissingException; use OCA\Encryption\KeyManager; use OCA\Encryption\Session; use OCA\Encryption\Util; -use OCP\Files\Storage; +use OCP\Files\Storage\IStorage; use OCP\IL10N; +use PHPUnit\Framework\MockObject\MockObject; use Psr\Log\LoggerInterface; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; @@ -50,13 +51,12 @@ class EncryptionTest extends TestCase { /** @var \OCP\IL10N|\PHPUnit\Framework\MockObject\MockObject */ private $l10nMock; - /** @var \OCP\Files\Storage|\PHPUnit\Framework\MockObject\MockObject */ - private $storageMock; + private IStorage&MockObject $storageMock; protected function setUp(): void { parent::setUp(); - $this->storageMock = $this->getMockBuilder(Storage::class) + $this->storageMock = $this->getMockBuilder(IStorage::class) ->disableOriginalConstructor()->getMock(); $this->cryptMock = $this->getMockBuilder(Crypt::class) ->disableOriginalConstructor() diff --git a/apps/encryption/tests/KeyManagerTest.php b/apps/encryption/tests/KeyManagerTest.php index a9919e8eab4..869e5e2cf96 100644 --- a/apps/encryption/tests/KeyManagerTest.php +++ b/apps/encryption/tests/KeyManagerTest.php @@ -15,7 +15,7 @@ use OCA\Encryption\Session; use OCA\Encryption\Util; use OCP\Encryption\Keys\IStorage; use OCP\Files\Cache\ICache; -use OCP\Files\Storage; +use OCP\Files\Storage\IStorage as FilesIStorage; use OCP\IConfig; use OCP\IUserSession; use OCP\Lock\ILockingProvider; @@ -687,7 +687,7 @@ class KeyManagerTest extends TestCase { $cache->expects($this->once()) ->method('update') ->with(123, ['encrypted' => 5, 'encryptedVersion' => 5]); - $storage = $this->getMockBuilder(Storage::class) + $storage = $this->getMockBuilder(FilesIStorage::class) ->disableOriginalConstructor()->getMock(); $storage->expects($this->once()) ->method('getCache') diff --git a/apps/encryption/tests/UtilTest.php b/apps/encryption/tests/UtilTest.php index 6f2eec1ebf4..f2e6f406c35 100644 --- a/apps/encryption/tests/UtilTest.php +++ b/apps/encryption/tests/UtilTest.php @@ -11,7 +11,7 @@ use OC\Files\View; use OCA\Encryption\Crypto\Crypt; use OCA\Encryption\Util; use OCP\Files\Mount\IMountPoint; -use OCP\Files\Storage; +use OCP\Files\Storage\IStorage; use OCP\IConfig; use OCP\IUser; use OCP\IUserManager; @@ -181,7 +181,7 @@ class UtilTest extends TestCase { } public function testGetStorage(): void { - $return = $this->getMockBuilder(Storage::class) + $return = $this->getMockBuilder(IStorage::class) ->disableOriginalConstructor() ->getMock(); diff --git a/apps/files_external/lib/Config/ConfigAdapter.php b/apps/files_external/lib/Config/ConfigAdapter.php index 97bc4f78142..d0437432427 100644 --- a/apps/files_external/lib/Config/ConfigAdapter.php +++ b/apps/files_external/lib/Config/ConfigAdapter.php @@ -14,7 +14,8 @@ use OCA\Files_External\Lib\StorageConfig; use OCA\Files_External\Service\UserGlobalStoragesService; use OCA\Files_External\Service\UserStoragesService; use OCP\Files\Config\IMountProvider; -use OCP\Files\Storage; +use OCP\Files\ObjectStore\IObjectStore; +use OCP\Files\Storage\IStorage; use OCP\Files\Storage\IStorageFactory; use OCP\Files\StorageNotAvailableException; use OCP\IUser; @@ -34,11 +35,9 @@ class ConfigAdapter implements IMountProvider { /** * Process storage ready for mounting * - * @param StorageConfig $storage - * @param IUser $user * @throws \OCP\AppFramework\QueryException */ - private function prepareStorageConfig(StorageConfig &$storage, IUser $user) { + private function prepareStorageConfig(StorageConfig &$storage, IUser $user): void { foreach ($storage->getBackendOptions() as $option => $value) { $storage->setBackendOption($option, \OCA\Files_External\MountConfig::substitutePlaceholdersInConfig($value, $user->getUID())); } @@ -46,7 +45,7 @@ class ConfigAdapter implements IMountProvider { $objectStore = $storage->getBackendOption('objectstore'); if ($objectStore) { $objectClass = $objectStore['class']; - if (!is_subclass_of($objectClass, '\OCP\Files\ObjectStore\IObjectStore')) { + if (!is_subclass_of($objectClass, IObjectStore::class)) { throw new \InvalidArgumentException('Invalid object store'); } $storage->setBackendOption('objectstore', new $objectClass($objectStore)); @@ -60,9 +59,8 @@ class ConfigAdapter implements IMountProvider { * Construct the storage implementation * * @param StorageConfig $storageConfig - * @return Storage */ - private function constructStorage(StorageConfig $storageConfig) { + private function constructStorage(StorageConfig $storageConfig): IStorage { $class = $storageConfig->getBackend()->getStorageClass(); $storage = new $class($storageConfig->getBackendOptions()); @@ -76,8 +74,6 @@ class ConfigAdapter implements IMountProvider { /** * Get all mountpoints applicable for the user * - * @param \OCP\IUser $user - * @param \OCP\Files\Storage\IStorageFactory $loader * @return \OCP\Files\Mount\IMountPoint[] */ public function getMountsForUser(IUser $user, IStorageFactory $loader) { @@ -97,11 +93,11 @@ class ConfigAdapter implements IMountProvider { }, $storageConfigs); - \OC\Files\Cache\Storage::getGlobalCache()->loadForStorageIds(array_map(function (Storage\IStorage $storage) { + \OC\Files\Cache\Storage::getGlobalCache()->loadForStorageIds(array_map(function (IStorage $storage) { return $storage->getId(); }, $storages)); - $availableStorages = array_map(function (Storage\IStorage $storage, StorageConfig $storageConfig) { + $availableStorages = array_map(function (IStorage $storage, StorageConfig $storageConfig): IStorage { try { $availability = $storage->getAvailability(); if (!$availability['available'] && !Availability::shouldRecheck($availability)) { @@ -116,7 +112,7 @@ class ConfigAdapter implements IMountProvider { return $storage; }, $storages, $storageConfigs); - $mounts = array_map(function (StorageConfig $storageConfig, Storage\IStorage $storage) use ($user, $loader) { + $mounts = array_map(function (StorageConfig $storageConfig, IStorage $storage) use ($user, $loader) { $storage->setOwner($user->getUID()); if ($storageConfig->getType() === StorageConfig::MOUNT_TYPE_PERSONAL) { return new PersonalMount( diff --git a/apps/files_external/lib/Lib/Auth/Password/SessionCredentials.php b/apps/files_external/lib/Lib/Auth/Password/SessionCredentials.php index d81c73ca13f..314ab82385e 100644 --- a/apps/files_external/lib/Lib/Auth/Password/SessionCredentials.php +++ b/apps/files_external/lib/Lib/Auth/Password/SessionCredentials.php @@ -12,7 +12,7 @@ use OCA\Files_External\Lib\SessionStorageWrapper; use OCA\Files_External\Lib\StorageConfig; use OCP\Authentication\Exceptions\CredentialsUnavailableException; use OCP\Authentication\LoginCredentials\IStore as CredentialsStore; -use OCP\Files\Storage; +use OCP\Files\Storage\IStorage; use OCP\Files\StorageAuthException; use OCP\IL10N; use OCP\IUser; @@ -56,7 +56,7 @@ class SessionCredentials extends AuthMechanism { $storage->setBackendOption('password', $credentials->getPassword()); } - public function wrapStorage(Storage $storage) { + public function wrapStorage(IStorage $storage): IStorage { return new SessionStorageWrapper(['storage' => $storage]); } } diff --git a/apps/files_external/lib/Lib/StorageModifierTrait.php b/apps/files_external/lib/Lib/StorageModifierTrait.php index 7cc7a15605c..4b9264f4223 100644 --- a/apps/files_external/lib/Lib/StorageModifierTrait.php +++ b/apps/files_external/lib/Lib/StorageModifierTrait.php @@ -6,7 +6,7 @@ */ namespace OCA\Files_External\Lib; -use OCP\Files\Storage; +use OCP\Files\Storage\IStorage; use OCP\Files\StorageNotAvailableException; use OCP\IUser; @@ -28,8 +28,8 @@ trait StorageModifierTrait { /** * Modify a StorageConfig parameters * - * @param StorageConfig $storage - * @param IUser $user User the storage is being used as + * @param StorageConfig &$storage + * @param ?IUser $user User the storage is being used as * @return void * @throws InsufficientDataForMeaningfulAnswerException * @throws StorageNotAvailableException @@ -38,14 +38,12 @@ trait StorageModifierTrait { } /** - * Wrap a Storage if necessary + * Wrap a storage if necessary * - * @param Storage $storage - * @return Storage * @throws InsufficientDataForMeaningfulAnswerException * @throws StorageNotAvailableException */ - public function wrapStorage(Storage $storage) { + public function wrapStorage(IStorage $storage): IStorage { return $storage; } } diff --git a/apps/files_sharing/tests/Controller/ShareAPIControllerTest.php b/apps/files_sharing/tests/Controller/ShareAPIControllerTest.php index f28302b4ccd..36ac04714b7 100644 --- a/apps/files_sharing/tests/Controller/ShareAPIControllerTest.php +++ b/apps/files_sharing/tests/Controller/ShareAPIControllerTest.php @@ -16,7 +16,7 @@ use OCP\Files\Folder; use OCP\Files\IRootFolder; use OCP\Files\Mount\IMountPoint; use OCP\Files\NotFoundException; -use OCP\Files\Storage; +use OCP\Files\Storage\IStorage; use OCP\IConfig; use OCP\IDateTimeZone; use OCP\IGroup; @@ -526,7 +526,7 @@ class ShareAPIControllerTest extends TestCase { ->getMock(); $cache->method('getNumericStorageId')->willReturn(101); - $storage = $this->getMockBuilder(Storage::class) + $storage = $this->getMockBuilder(IStorage::class) ->disableOriginalConstructor() ->getMock(); $storage->method('getId')->willReturn('STORAGE'); @@ -1923,7 +1923,7 @@ class ShareAPIControllerTest extends TestCase { $path = $this->getMockBuilder(Folder::class)->getMock(); $path->method('getId')->willReturn(42); - $storage = $this->createMock(Storage::class); + $storage = $this->createMock(IStorage::class); $storage->method('instanceOfStorage') ->willReturnMap([ ['OCA\Files_Sharing\External\Storage', false], @@ -1947,7 +1947,7 @@ class ShareAPIControllerTest extends TestCase { $path = $this->getMockBuilder(Folder::class)->getMock(); $path->method('getId')->willReturn(42); - $storage = $this->createMock(Storage::class); + $storage = $this->createMock(IStorage::class); $storage->method('instanceOfStorage') ->willReturnMap([ ['OCA\Files_Sharing\External\Storage', false], @@ -1972,7 +1972,7 @@ class ShareAPIControllerTest extends TestCase { $path = $this->getMockBuilder(File::class)->getMock(); $path->method('getId')->willReturn(42); - $storage = $this->createMock(Storage::class); + $storage = $this->createMock(IStorage::class); $storage->method('instanceOfStorage') ->willReturnMap([ ['OCA\Files_Sharing\External\Storage', false], @@ -1996,7 +1996,7 @@ class ShareAPIControllerTest extends TestCase { $path = $this->getMockBuilder(Folder::class)->getMock(); $path->method('getId')->willReturn(1); - $storage = $this->createMock(Storage::class); + $storage = $this->createMock(IStorage::class); $storage->method('instanceOfStorage') ->willReturnMap([ ['OCA\Files_Sharing\External\Storage', false], @@ -2035,7 +2035,7 @@ class ShareAPIControllerTest extends TestCase { $path = $this->getMockBuilder(Folder::class)->getMock(); $path->method('getId')->willReturn(42); - $storage = $this->createMock(Storage::class); + $storage = $this->createMock(IStorage::class); $storage->method('instanceOfStorage') ->willReturnMap([ ['OCA\Files_Sharing\External\Storage', false], @@ -2074,7 +2074,7 @@ class ShareAPIControllerTest extends TestCase { $path = $this->getMockBuilder(Folder::class)->getMock(); $path->method('getId')->willReturn(42); - $storage = $this->createMock(Storage::class); + $storage = $this->createMock(IStorage::class); $storage->method('instanceOfStorage') ->willReturnMap([ ['OCA\Files_Sharing\External\Storage', false], @@ -2120,7 +2120,7 @@ class ShareAPIControllerTest extends TestCase { $path = $this->getMockBuilder(Folder::class)->getMock(); $path->method('getId')->willReturn(42); - $storage = $this->createMock(Storage::class); + $storage = $this->createMock(IStorage::class); $storage->method('instanceOfStorage') ->willReturnMap([ ['OCA\Files_Sharing\External\Storage', false], @@ -2159,7 +2159,7 @@ class ShareAPIControllerTest extends TestCase { $path = $this->getMockBuilder(Folder::class)->getMock(); $path->method('getId')->willReturn(42); - $storage = $this->createMock(Storage::class); + $storage = $this->createMock(IStorage::class); $storage->method('instanceOfStorage') ->willReturnMap([ ['OCA\Files_Sharing\External\Storage', false], @@ -2205,7 +2205,7 @@ class ShareAPIControllerTest extends TestCase { $path = $this->getMockBuilder(Folder::class)->getMock(); $path->method('getId')->willReturn(42); - $storage = $this->createMock(Storage::class); + $storage = $this->createMock(IStorage::class); $storage->method('instanceOfStorage') ->willReturnMap([ ['OCA\Files_Sharing\External\Storage', false], @@ -2574,7 +2574,7 @@ class ShareAPIControllerTest extends TestCase { $path = $this->getMockBuilder(Folder::class)->getMock(); $path->method('getId')->willReturn(42); - $storage = $this->createMock(Storage::class); + $storage = $this->createMock(IStorage::class); $storage->method('instanceOfStorage') ->willReturnMap([ ['OCA\Files_Sharing\External\Storage', true], @@ -3762,7 +3762,7 @@ class ShareAPIControllerTest extends TestCase { $cache = $this->getMockBuilder('OCP\Files\Cache\ICache')->getMock(); $cache->method('getNumericStorageId')->willReturn(100); - $storage = $this->createMock(Storage::class); + $storage = $this->createMock(IStorage::class); $storage->method('getId')->willReturn('storageId'); $storage->method('getCache')->willReturn($cache); @@ -4759,7 +4759,7 @@ class ShareAPIControllerTest extends TestCase { $cache = $this->getMockBuilder('OCP\Files\Cache\ICache')->getMock(); $cache->method('getNumericStorageId')->willReturn(100); - $storage = $this->createMock(Storage::class); + $storage = $this->createMock(IStorage::class); $storage->method('getId')->willReturn('storageId'); $storage->method('getCache')->willReturn($cache); @@ -4923,7 +4923,7 @@ class ShareAPIControllerTest extends TestCase { private function getNonSharedUserFolder(): array { $node = $this->getMockBuilder(Folder::class)->getMock(); $userFolder = $this->getMockBuilder(Folder::class)->getMock(); - $storage = $this->createMock(Storage::class); + $storage = $this->createMock(IStorage::class); $storage->method('instanceOfStorage') ->willReturnMap([ ['OCA\Files_Sharing\External\Storage', false], @@ -4938,7 +4938,7 @@ class ShareAPIControllerTest extends TestCase { private function getNonSharedUserFile(): array { $node = $this->getMockBuilder(File::class)->getMock(); $userFolder = $this->getMockBuilder(Folder::class)->getMock(); - $storage = $this->createMock(Storage::class); + $storage = $this->createMock(IStorage::class); $storage->method('instanceOfStorage') ->willReturnMap([ ['OCA\Files_Sharing\External\Storage', false], |