[TASK] CGL: Fix a series of minor indentation issues
[Packages/TYPO3.CMS.git] / typo3 / sysext / core / Classes / Resource / ResourceStorage.php
index 9f027a3..def4d7e 100644 (file)
@@ -15,10 +15,11 @@ namespace TYPO3\CMS\Core\Resource;
  */
 
 use TYPO3\CMS\Core\Database\ConnectionPool;
+use TYPO3\CMS\Core\Log\LogManager;
 use TYPO3\CMS\Core\Registry;
+use TYPO3\CMS\Core\Resource\Exception\ExistingTargetFileNameException;
 use TYPO3\CMS\Core\Resource\Exception\InvalidTargetFolderException;
 use TYPO3\CMS\Core\Resource\Index\FileIndexRepository;
-use TYPO3\CMS\Core\Resource\Index\Indexer;
 use TYPO3\CMS\Core\Resource\OnlineMedia\Helpers\OnlineMediaHelperRegistry;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
 use TYPO3\CMS\Core\Utility\PathUtility;
@@ -168,7 +169,7 @@ class ResourceStorage implements ResourceStorageInterface
     public function __construct(Driver\DriverInterface $driver, array $storageRecord)
     {
         $this->storageRecord = $storageRecord;
-        $this->configuration = ResourceFactory::getInstance()->convertFlexFormDataToConfigurationArray($storageRecord['configuration']);
+        $this->configuration = $this->getResourceFactoryInstance()->convertFlexFormDataToConfigurationArray($storageRecord['configuration']);
         $this->capabilities =
             ($this->storageRecord['is_browsable'] ? self::CAPABILITY_BROWSABLE : 0) |
             ($this->storageRecord['is_public'] ? self::CAPABILITY_PUBLIC : 0) |
@@ -180,9 +181,18 @@ class ResourceStorage implements ResourceStorageInterface
         try {
             $this->driver->processConfiguration();
         } catch (Exception\InvalidConfigurationException $e) {
-            // configuration error
-            // mark this storage as permanently unusable
-            $this->markAsPermanentlyOffline();
+            // Configuration error
+            $this->isOnline = false;
+
+            $message = sprintf(
+                'Failed initializing storage [%d] "%s", error: %s',
+                $this->getUid(),
+                $this->getName(),
+                $e->getMessage()
+            );
+
+            // create a dedicated logger instance because we need a logger in the constructor
+            GeneralUtility::makeInstance(LogManager::class)->getLogger(static::class)->error($message);
         }
         $this->driver->initialize();
         $this->capabilities = $this->driver->getCapabilities();
@@ -392,8 +402,6 @@ class ResourceStorage implements ResourceStorageInterface
      * Can only be modified by an admin.
      *
      * Typically, this is only done if the configuration is wrong.
-     *
-     * @return void
      */
     public function markAsPermanentlyOffline()
     {
@@ -416,8 +424,6 @@ class ResourceStorage implements ResourceStorageInterface
      *
      * Non-permanent: This typically happens for remote storages
      * that are "flaky" and not available all the time.
-     *
-     * @return void
      */
     public function markAsTemporaryOffline()
     {
@@ -438,7 +444,6 @@ class ResourceStorage implements ResourceStorageInterface
      * @param array $additionalData
      *
      * @throws Exception\FolderDoesNotExistException
-     * @return void
      */
     public function addFileMount($folderIdentifier, $additionalData = [])
     {
@@ -449,7 +454,7 @@ class ResourceStorage implements ResourceStorageInterface
             throw new Exception\FolderDoesNotExistException('Folder for file mount ' . $folderIdentifier . ' does not exist.', 1334427099);
         }
         $data = $this->driver->getFolderInfoByIdentifier($folderIdentifier);
-        $folderObject = ResourceFactory::getInstance()->createFolderObject($this, $data['identifier'], $data['name']);
+        $folderObject = $this->getResourceFactoryInstance()->createFolderObject($this, $data['identifier'], $data['name']);
         // Use the canonical identifier instead of the user provided one!
         $folderIdentifier = $folderObject->getIdentifier();
         if (
@@ -518,7 +523,8 @@ class ResourceStorage implements ResourceStorageInterface
                     $isWithinFileMount = true;
                     if (!$checkWriteAccess) {
                         break;
-                    } elseif (empty($fileMount['read_only'])) {
+                    }
+                    if (empty($fileMount['read_only'])) {
                         $writableFileMountAvailable = true;
                         break;
                     }
@@ -555,7 +561,6 @@ class ResourceStorage implements ResourceStorageInterface
      * Sets the user permissions of the storage.
      *
      * @param array $userPermissions
-     * @return void
      */
     public function setUserPermissions(array $userPermissions)
     {
@@ -714,42 +719,13 @@ class ResourceStorage implements ResourceStorageInterface
     protected function checkFileExtensionPermission($fileName)
     {
         $fileName = $this->driver->sanitizeFileName($fileName);
-        $isAllowed = GeneralUtility::verifyFilenameAgainstDenyPattern($fileName);
-        if ($isAllowed && $this->evaluatePermissions) {
-            $fileExtension = strtolower(PathUtility::pathinfo($fileName, PATHINFO_EXTENSION));
-            // Set up the permissions for the file extension
-            $fileExtensionPermissions = $GLOBALS['TYPO3_CONF_VARS']['BE']['fileExtensions']['webspace'];
-            $fileExtensionPermissions['allow'] = GeneralUtility::uniqueList(strtolower($fileExtensionPermissions['allow']));
-            $fileExtensionPermissions['deny'] = GeneralUtility::uniqueList(strtolower($fileExtensionPermissions['deny']));
-            if ($fileExtension !== '') {
-                // If the extension is found amongst the allowed types, we return TRUE immediately
-                if ($fileExtensionPermissions['allow'] === '*' || GeneralUtility::inList($fileExtensionPermissions['allow'], $fileExtension)) {
-                    return true;
-                }
-                // If the extension is found amongst the denied types, we return FALSE immediately
-                if ($fileExtensionPermissions['deny'] === '*' || GeneralUtility::inList($fileExtensionPermissions['deny'], $fileExtension)) {
-                    return false;
-                }
-                // If no match we return TRUE
-                return true;
-            } else {
-                if ($fileExtensionPermissions['allow'] === '*') {
-                    return true;
-                }
-                if ($fileExtensionPermissions['deny'] === '*') {
-                    return false;
-                }
-                return true;
-            }
-        }
-        return $isAllowed;
+        return GeneralUtility::verifyFilenameAgainstDenyPattern($fileName);
     }
 
     /**
      * Assures read permission for given folder.
      *
      * @param Folder $folder If a folder is given, mountpoints are checked. If not only user folder read permissions are checked.
-     * @return void
      * @throws Exception\InsufficientFolderAccessPermissionsException
      */
     protected function assureFolderReadPermission(Folder $folder = null)
@@ -760,12 +736,11 @@ class ResourceStorage implements ResourceStorageInterface
                     'You are not allowed to read folders',
                     1430657869
                 );
-            } else {
-                throw new Exception\InsufficientFolderAccessPermissionsException(
+            }
+            throw new Exception\InsufficientFolderAccessPermissionsException(
                     'You are not allowed to access the given folder: "' . $folder->getName() . '"',
                     1375955684
                 );
-            }
         }
     }
 
@@ -774,7 +749,6 @@ class ResourceStorage implements ResourceStorageInterface
      *
      * @param Folder $folder If a folder is given, mountpoints are checked. If not only user folder delete permissions are checked.
      * @param bool $checkDeleteRecursively
-     * @return void
      * @throws Exception\InsufficientFolderAccessPermissionsException
      * @throws Exception\InsufficientFolderWritePermissionsException
      * @throws Exception\InsufficientUserPermissionsException
@@ -804,7 +778,6 @@ class ResourceStorage implements ResourceStorageInterface
      * Assures read permission for given file.
      *
      * @param FileInterface $file
-     * @return void
      * @throws Exception\InsufficientFileAccessPermissionsException
      * @throws Exception\IllegalFileExtensionException
      */
@@ -828,7 +801,6 @@ class ResourceStorage implements ResourceStorageInterface
      * Assures write permission for given file.
      *
      * @param FileInterface $file
-     * @return void
      * @throws Exception\IllegalFileExtensionException
      * @throws Exception\InsufficientFileWritePermissionsException
      * @throws Exception\InsufficientUserPermissionsException
@@ -848,7 +820,6 @@ class ResourceStorage implements ResourceStorageInterface
      * Assure replace permission for given file.
      *
      * @param FileInterface $file
-     * @return void
      * @throws Exception\InsufficientFileWritePermissionsException
      * @throws Exception\InsufficientFolderWritePermissionsException
      */
@@ -868,7 +839,6 @@ class ResourceStorage implements ResourceStorageInterface
      * Assures delete permission for given file.
      *
      * @param FileInterface $file
-     * @return void
      * @throws Exception\IllegalFileExtensionException
      * @throws Exception\InsufficientFileWritePermissionsException
      * @throws Exception\InsufficientFolderWritePermissionsException
@@ -900,7 +870,6 @@ class ResourceStorage implements ResourceStorageInterface
      *
      * @param Folder $targetFolder The target folder where the file should be written
      * @param string $targetFileName The file name which should be written into the storage
-     * @return void
      *
      * @throws Exception\InsufficientFolderWritePermissionsException
      * @throws Exception\IllegalFileExtensionException
@@ -930,7 +899,6 @@ class ResourceStorage implements ResourceStorageInterface
      * @param Folder $targetFolder The target folder where the file should be uploaded
      * @param string $targetFileName the destination file name $_FILES['file1']['name']
      * @param int $uploadedFileSize
-     * @return void
      *
      * @throws Exception\InsufficientFolderWritePermissionsException
      * @throws Exception\UploadException
@@ -963,13 +931,12 @@ class ResourceStorage implements ResourceStorageInterface
      * @param FileInterface $file
      * @param Folder $targetFolder
      * @param string $targetFileName
-     * @return void
      */
     protected function assureFileMovePermissions(FileInterface $file, Folder $targetFolder, $targetFileName)
     {
         // Check if targetFolder is within this storage
         if ($this->getUid() !== $targetFolder->getStorage()->getUid()) {
-            throw new \RuntimeException('The target folder is not in the same storage. Target folder given: "' . $targetFolder . '"', 1422553107);
+            throw new \RuntimeException('The target folder is not in the same storage. Target folder given: "' . $targetFolder->getIdentifier() . '"', 1422553107);
         }
         // Check for a valid file extension
         if (!$this->checkFileExtensionPermission($targetFileName)) {
@@ -994,7 +961,6 @@ class ResourceStorage implements ResourceStorageInterface
      * @throws Exception\IllegalFileExtensionException
      * @throws Exception\InsufficientFileReadPermissionsException
      * @throws Exception\InsufficientUserPermissionsException
-     * @return void
      */
     protected function assureFileRenamePermissions(FileInterface $file, $targetFileName)
     {
@@ -1028,7 +994,6 @@ class ResourceStorage implements ResourceStorageInterface
      * @throws Exception\IllegalFileExtensionException
      * @throws Exception\InsufficientFileReadPermissionsException
      * @throws Exception\InsufficientUserPermissionsException
-     * @return void
      */
     protected function assureFileCopyPermissions(FileInterface $file, Folder $targetFolder, $targetFileName)
     {
@@ -1056,7 +1021,6 @@ class ResourceStorage implements ResourceStorageInterface
      *
      * @param FolderInterface $folderToCopy
      * @param FolderInterface $targetParentFolder
-     * @return void
      *
      * @throws Exception
      * @throws Exception\InsufficientFolderWritePermissionsException
@@ -1100,7 +1064,6 @@ class ResourceStorage implements ResourceStorageInterface
      * @throws Exception\InsufficientFileReadPermissionsException
      * @throws Exception\InsufficientUserPermissionsException
      * @throws \RuntimeException
-     * @return void
      */
     protected function assureFolderMovePermissions(FolderInterface $folderToMove, FolderInterface $targetParentFolder)
     {
@@ -1177,18 +1140,25 @@ class ResourceStorage implements ResourceStorageInterface
         $targetFileName = $this->emitPreFileAddSignal($targetFileName, $targetFolder, $localFilePath);
 
         $this->assureFileAddPermissions($targetFolder, $targetFileName);
+
+        $replaceExisting = false;
         if ($conflictMode->equals(DuplicationBehavior::CANCEL) && $this->driver->fileExistsInFolder($targetFileName, $targetFolder->getIdentifier())) {
             throw new Exception\ExistingTargetFileNameException('File "' . $targetFileName . '" already exists in folder ' . $targetFolder->getIdentifier(), 1322121068);
-        } elseif ($conflictMode->equals(DuplicationBehavior::RENAME)) {
+        }
+        if ($conflictMode->equals(DuplicationBehavior::RENAME)) {
             $targetFileName = $this->getUniqueName($targetFolder, $targetFileName);
+        } elseif ($conflictMode->equals(DuplicationBehavior::REPLACE) && $this->driver->fileExistsInFolder($targetFileName, $targetFolder->getIdentifier())) {
+            $replaceExisting = true;
         }
 
         $fileIdentifier = $this->driver->addFile($localFilePath, $targetFolder->getIdentifier(), $targetFileName, $removeOriginal);
-        $file = ResourceFactory::getInstance()->getFileObjectByStorageAndIdentifier($this->getUid(), $fileIdentifier);
+        $file = $this->getResourceFactoryInstance()->getFileObjectByStorageAndIdentifier($this->getUid(), $fileIdentifier);
 
+        if ($replaceExisting && $file instanceof File) {
+            $this->getIndexer()->updateIndexEntry($file);
+        }
         if ($this->autoExtractMetadataEnabled()) {
-            $indexer = GeneralUtility::makeInstance(Indexer::class, $this);
-            $indexer->extractMetaData($file);
+            $this->getIndexer()->extractMetaData($file);
         }
 
         $this->emitPostFileAddSignal($file, $targetFolder);
@@ -1234,7 +1204,7 @@ class ResourceStorage implements ResourceStorageInterface
 
     /**
      * Creates a (cryptographic) hash for a fileIdentifier.
-
+     *
      * @param string $fileIdentifier
      * @param string $hash
      *
@@ -1304,7 +1274,8 @@ class ResourceStorage implements ResourceStorageInterface
                     }
 
                     $queryParameterArray['token'] = GeneralUtility::hmac(implode('|', $queryParameterArray), 'resourceStorageDumpFile');
-                    $publicUrl = 'index.php?' . str_replace('+', '%20', http_build_query($queryParameterArray));
+                    $publicUrl = GeneralUtility::locationHeaderUrl(PathUtility::getAbsoluteWebPath(PATH_site . 'index.php'));
+                    $publicUrl .= '?' . http_build_query($queryParameterArray, '', '&', PHP_QUERY_RFC3986);
                 }
 
                 // If requested, make the path relative to the current script in order to make it possible
@@ -1395,8 +1366,6 @@ class ResourceStorage implements ResourceStorageInterface
 
     /**
      * Unsets the file and folder name filters, thus making this storage return unfiltered filelists.
-     *
-     * @return void
      */
     public function unsetFileAndFolderNameFilters()
     {
@@ -1405,8 +1374,6 @@ class ResourceStorage implements ResourceStorageInterface
 
     /**
      * Resets the file and folder name filters to the default values defined in the TYPO3 configuration.
-     *
-     * @return void
      */
     public function resetFileAndFolderNameFiltersToDefault()
     {
@@ -1456,7 +1423,7 @@ class ResourceStorage implements ResourceStorageInterface
      *
      * @param string $fileName
      * @param Folder $folder
-     * @return NULL|File|ProcessedFile
+     * @return File|ProcessedFile|null
      */
     public function getFileInFolder($fileName, Folder $folder)
     {
@@ -1576,11 +1543,11 @@ class ResourceStorage implements ResourceStorageInterface
             foreach ($allStorages as $storage) {
                 // To circumvent the permission check of the folder, we use the factory to create it "manually" instead of directly using $storage->getProcessingFolder()
                 // See #66695 for details
-                list($storageUid, $processingFolderIdentifier) = GeneralUtility::trimExplode(':', $storage->getStorageRecord()['processingfolder']);
+                list($storageUid, $processingFolderIdentifier) = array_pad(GeneralUtility::trimExplode(':', $storage->getStorageRecord()['processingfolder']), 2, null);
                 if (empty($processingFolderIdentifier) || (int)$storageUid !== $this->getUid()) {
                     continue;
                 }
-                $potentialProcessingFolder = ResourceFactory::getInstance()->getInstance()->createFolderObject($this, $processingFolderIdentifier, $processingFolderIdentifier);
+                $potentialProcessingFolder = $this->getResourceFactoryInstance()->getInstance()->createFolderObject($this, $processingFolderIdentifier, $processingFolderIdentifier);
                 if ($potentialProcessingFolder->getStorage() === $this && $potentialProcessingFolder->getIdentifier() !== $this->getProcessingFolder()->getIdentifier()) {
                     $this->processingFolders[] = $potentialProcessingFolder;
                 }
@@ -1644,7 +1611,6 @@ class ResourceStorage implements ResourceStorageInterface
      * @param bool $asDownload If set Content-Disposition attachment is sent, inline otherwise
      * @param string $alternativeFilename the filename for the download (if $asDownload is set)
      * @param string $overrideMimeType If set this will be used as Content-Type header instead of the automatically detected mime type.
-     * @return void
      */
     public function dumpFileContents(FileInterface $file, $asDownload = false, $alternativeFilename = null, $overrideMimeType = null)
     {
@@ -1657,7 +1623,8 @@ class ResourceStorage implements ResourceStorageInterface
         // Cache-Control header is needed here to solve an issue with browser IE8 and lower
         // See for more information: http://support.microsoft.com/kb/323308
         header("Cache-Control: ''");
-        header('Last-Modified: ' .
+        header(
+            'Last-Modified: ' .
             gmdate('D, d M Y H:i:s', array_pop($this->driver->getFileInfoByIdentifier($file->getIdentifier(), ['mtime']))) . ' GMT',
             true,
             200
@@ -1711,7 +1678,7 @@ class ResourceStorage implements ResourceStorageInterface
         $this->assureFileAddPermissions($targetFolderObject, $fileName);
         $newFileIdentifier = $this->driver->createFile($fileName, $targetFolderObject->getIdentifier());
         $this->emitPostFileCreateSignal($newFileIdentifier, $targetFolderObject);
-        return ResourceFactory::getInstance()->getFileObjectByStorageAndIdentifier($this->getUid(), $newFileIdentifier);
+        return $this->getResourceFactoryInstance()->getFileObjectByStorageAndIdentifier($this->getUid(), $newFileIdentifier);
     }
 
     /**
@@ -1735,7 +1702,7 @@ class ResourceStorage implements ResourceStorageInterface
             }
         }
         // Mark the file object as deleted
-        if ($fileObject instanceof File) {
+        if ($fileObject instanceof AbstractFile) {
             $fileObject->setDeleted();
         }
 
@@ -1784,7 +1751,7 @@ class ResourceStorage implements ResourceStorageInterface
             $tempPath = $file->getForLocalProcessing();
             $newFileObjectIdentifier = $this->driver->addFile($tempPath, $targetFolder->getIdentifier(), $sanitizedTargetFileName);
         }
-        $newFileObject = ResourceFactory::getInstance()->getFileObjectByStorageAndIdentifier($this->getUid(), $newFileObjectIdentifier);
+        $newFileObject = $this->getResourceFactoryInstance()->getFileObjectByStorageAndIdentifier($this->getUid(), $newFileObjectIdentifier);
         $this->emitPostFileCopySignal($file, $targetFolder);
         return $newFileObject;
     }
@@ -1852,16 +1819,12 @@ class ResourceStorage implements ResourceStorageInterface
      *
      * @param FileInterface $file
      * @param string $targetFileName
-     *
-     * @throws Exception\InsufficientFileWritePermissionsException
-     * @throws Exception\InsufficientFileReadPermissionsException
-     * @throws Exception\InsufficientUserPermissionsException
+     * @param string $conflictMode
      * @return FileInterface
+     * @throws ExistingTargetFileNameException
      */
-    public function renameFile($file, $targetFileName)
+    public function renameFile($file, $targetFileName, $conflictMode = DuplicationBehavior::RENAME)
     {
-        // @todo add $conflictMode setting
-
         // The name should be different from the current.
         if ($file->getName() === $targetFileName) {
             return $file;
@@ -1870,6 +1833,8 @@ class ResourceStorage implements ResourceStorageInterface
         $this->assureFileRenamePermissions($file, $sanitizedTargetFileName);
         $this->emitPreFileRenameSignal($file, $sanitizedTargetFileName);
 
+        $conflictMode = DuplicationBehavior::cast($conflictMode);
+
         // Call driver method to rename the file and update the index entry
         try {
             $newIdentifier = $this->driver->renameFile($file->getIdentifier(), $sanitizedTargetFileName);
@@ -1877,6 +1842,17 @@ class ResourceStorage implements ResourceStorageInterface
                 $file->updateProperties(['identifier' => $newIdentifier]);
             }
             $this->getIndexer()->updateIndexEntry($file);
+        } catch (ExistingTargetFileNameException $exception) {
+            if ($conflictMode->equals(DuplicationBehavior::RENAME)) {
+                $newName = $this->getUniqueName($file->getParentFolder(), $sanitizedTargetFileName);
+                $file = $this->renameFile($file, $newName);
+            } elseif ($conflictMode->equals(DuplicationBehavior::CANCEL)) {
+                throw $exception;
+            } elseif ($conflictMode->equals(DuplicationBehavior::REPLACE)) {
+                $sourceFileIdentifier = substr($file->getCombinedIdentifier(), 0, strrpos($file->getCombinedIdentifier(), '/') + 1) . $targetFileName;
+                $sourceFile = $this->getResourceFactoryInstance()->getFileObjectFromCombinedIdentifier($sourceFileIdentifier);
+                $file = $this->replaceFile($sourceFile, PATH_site . $file->getPublicUrl());
+            }
         } catch (\RuntimeException $e) {
         }
 
@@ -1899,9 +1875,6 @@ class ResourceStorage implements ResourceStorageInterface
     public function replaceFile(FileInterface $file, $localFilePath)
     {
         $this->assureFileReplacePermissions($file);
-        if (!$this->checkFileExtensionPermission($localFilePath)) {
-            throw new Exception\IllegalFileExtensionException('Source file extension not allowed.', 1378132239);
-        }
         if (!file_exists($localFilePath)) {
             throw new \InvalidArgumentException('File "' . $localFilePath . '" does not exist.', 1325842622);
         }
@@ -1911,8 +1884,7 @@ class ResourceStorage implements ResourceStorageInterface
             $this->getIndexer()->updateIndexEntry($file);
         }
         if ($this->autoExtractMetadataEnabled()) {
-            $indexer = GeneralUtility::makeInstance(Indexer::class, $this);
-            $indexer->extractMetaData($file);
+            $this->getIndexer()->extractMetaData($file);
         }
         $this->emitPostFileReplaceSignal($file, $localFilePath);
 
@@ -2333,7 +2305,7 @@ class ResourceStorage implements ResourceStorageInterface
     public function getFolder($identifier, $returnInaccessibleFolderObject = false)
     {
         $data = $this->driver->getFolderInfoByIdentifier($identifier);
-        $folder = ResourceFactory::getInstance()->createFolderObject($this, $data['identifier'], $data['name']);
+        $folder = $this->getResourceFactoryInstance()->createFolderObject($this, $data['identifier'], $data['name']);
 
         try {
             $this->assureFolderReadPermission($folder);
@@ -2344,7 +2316,10 @@ class ResourceStorage implements ResourceStorageInterface
                 $parentPermissions = $this->driver->getPermissions($this->driver->getParentFolderIdentifierOfIdentifier($identifier));
                 if ($parentPermissions['r']) {
                     $folder = GeneralUtility::makeInstance(
-                        InaccessibleFolder::class, $this, $data['identifier'], $data['name']
+                        InaccessibleFolder::class,
+                        $this,
+                        $data['identifier'],
+                        $data['name']
                     );
                 }
             }
@@ -2406,9 +2381,8 @@ class ResourceStorage implements ResourceStorageInterface
         if ($respectFileMounts && !empty($this->fileMounts)) {
             $mount = reset($this->fileMounts);
             return $mount['folder'];
-        } else {
-            return ResourceFactory::getInstance()->createFolderObject($this, $this->driver->getRootLevelFolder(), '');
         }
+        return $this->getResourceFactoryInstance()->createFolderObject($this, $this->driver->getRootLevelFolder(), '');
     }
 
     /**
@@ -2443,7 +2417,6 @@ class ResourceStorage implements ResourceStorageInterface
      *
      * @param FileInterface $file
      * @param Folder $targetFolder
-     * @return void
      */
     protected function emitPostFileAddSignal(FileInterface $file, Folder $targetFolder)
     {
@@ -2455,7 +2428,6 @@ class ResourceStorage implements ResourceStorageInterface
      *
      * @param FileInterface $file
      * @param Folder $targetFolder
-     * @return void
      */
     protected function emitPreFileCopySignal(FileInterface $file, Folder $targetFolder)
     {
@@ -2467,7 +2439,6 @@ class ResourceStorage implements ResourceStorageInterface
      *
      * @param FileInterface $file
      * @param Folder $targetFolder
-     * @return void
      */
     protected function emitPostFileCopySignal(FileInterface $file, Folder $targetFolder)
     {
@@ -2479,7 +2450,6 @@ class ResourceStorage implements ResourceStorageInterface
      *
      * @param FileInterface $file
      * @param Folder $targetFolder
-     * @return void
      */
     protected function emitPreFileMoveSignal(FileInterface $file, Folder $targetFolder)
     {
@@ -2492,7 +2462,6 @@ class ResourceStorage implements ResourceStorageInterface
      * @param FileInterface $file
      * @param Folder $targetFolder
      * @param FolderInterface $originalFolder
-     * @return void
      */
     protected function emitPostFileMoveSignal(FileInterface $file, Folder $targetFolder, FolderInterface $originalFolder)
     {
@@ -2504,7 +2473,6 @@ class ResourceStorage implements ResourceStorageInterface
      *
      * @param FileInterface $file
      * @param $targetFolder
-     * @return void
      */
     protected function emitPreFileRenameSignal(FileInterface $file, $targetFolder)
     {
@@ -2516,7 +2484,6 @@ class ResourceStorage implements ResourceStorageInterface
      *
      * @param FileInterface $file
      * @param string $sanitizedTargetFileName
-     * @return void
      */
     protected function emitPostFileRenameSignal(FileInterface $file, $sanitizedTargetFileName)
     {
@@ -2528,7 +2495,6 @@ class ResourceStorage implements ResourceStorageInterface
      *
      * @param FileInterface $file
      * @param $localFilePath
-     * @return void
      */
     protected function emitPreFileReplaceSignal(FileInterface $file, $localFilePath)
     {
@@ -2540,7 +2506,6 @@ class ResourceStorage implements ResourceStorageInterface
      *
      * @param FileInterface $file
      * @param string $localFilePath
-     * @return void
      */
     protected function emitPostFileReplaceSignal(FileInterface $file, $localFilePath)
     {
@@ -2562,7 +2527,6 @@ class ResourceStorage implements ResourceStorageInterface
      * Emits the file pre-deletion signal.
      *
      * @param FileInterface $file
-     * @return void
      */
     protected function emitPreFileDeleteSignal(FileInterface $file)
     {
@@ -2573,7 +2537,6 @@ class ResourceStorage implements ResourceStorageInterface
      * Emits the file post-deletion signal
      *
      * @param FileInterface $file
-     * @return void
      */
     protected function emitPostFileDeleteSignal(FileInterface $file)
     {
@@ -2585,7 +2548,6 @@ class ResourceStorage implements ResourceStorageInterface
      *
      * @param FileInterface $file
      * @param mixed $content
-     * @return void
      */
     protected function emitPostFileSetContentsSignal(FileInterface $file, $content)
     {
@@ -2597,7 +2559,6 @@ class ResourceStorage implements ResourceStorageInterface
      *
      * @param Folder $targetFolder
      * @param string $name
-     * @return void
      */
     protected function emitPreFolderAddSignal(Folder $targetFolder, $name)
     {
@@ -2608,7 +2569,6 @@ class ResourceStorage implements ResourceStorageInterface
      * Emits the folder post-add signal.
      *
      * @param Folder $folder
-     * @return void
      */
     protected function emitPostFolderAddSignal(Folder $folder)
     {
@@ -2621,7 +2581,6 @@ class ResourceStorage implements ResourceStorageInterface
      * @param Folder $folder
      * @param Folder $targetFolder
      * @param $newName
-     * @return void
      */
     protected function emitPreFolderCopySignal(Folder $folder, Folder $targetFolder, $newName)
     {
@@ -2634,7 +2593,6 @@ class ResourceStorage implements ResourceStorageInterface
      * @param Folder $folder
      * @param Folder $targetFolder
      * @param $newName
-     * @return void
      */
     protected function emitPostFolderCopySignal(Folder $folder, Folder $targetFolder, $newName)
     {
@@ -2647,7 +2605,6 @@ class ResourceStorage implements ResourceStorageInterface
      * @param Folder $folder
      * @param Folder $targetFolder
      * @param $newName
-     * @return void
      */
     protected function emitPreFolderMoveSignal(Folder $folder, Folder $targetFolder, $newName)
     {
@@ -2661,7 +2618,6 @@ class ResourceStorage implements ResourceStorageInterface
      * @param Folder $targetFolder
      * @param string $newName
      * @param Folder $originalFolder
-     * @return void
      */
     protected function emitPostFolderMoveSignal(Folder $folder, Folder $targetFolder, $newName, Folder $originalFolder)
     {
@@ -2673,7 +2629,6 @@ class ResourceStorage implements ResourceStorageInterface
      *
      * @param Folder $folder
      * @param string $newName
-     * @return void
      */
     protected function emitPreFolderRenameSignal(Folder $folder, $newName)
     {
@@ -2685,7 +2640,6 @@ class ResourceStorage implements ResourceStorageInterface
      *
      * @param Folder $folder
      * @param string $newName
-     * @return void
      */
     protected function emitPostFolderRenameSignal(Folder $folder, $newName)
     {
@@ -2696,7 +2650,6 @@ class ResourceStorage implements ResourceStorageInterface
      * Emits the folder pre-deletion signal.
      *
      * @param Folder $folder
-     * @return void
      */
     protected function emitPreFolderDeleteSignal(Folder $folder)
     {
@@ -2707,7 +2660,6 @@ class ResourceStorage implements ResourceStorageInterface
      * Emits folder post-deletion signal..
      *
      * @param Folder $folder
-     * @return void
      */
     protected function emitPostFolderDeleteSignal(Folder $folder)
     {
@@ -2731,7 +2683,7 @@ class ResourceStorage implements ResourceStorageInterface
      * If $theFile exists in $theDest (directory) the file have numbers appended up to $this->maxNumber. Hereafter a unique string will be appended.
      * This function is used by fx. DataHandler when files are attached to records and needs to be uniquely named in the uploads/* folders
      *
-     * @param Folder $folder
+     * @param FolderInterface $folder
      * @param string $theFile The input fileName to check
      * @param bool $dontCheckForUnique If set the fileName is returned with the path prepended without checking whether it already existed!
      *
@@ -2739,7 +2691,7 @@ class ResourceStorage implements ResourceStorageInterface
      * @return string A unique fileName inside $folder, based on $theFile.
      * @see \TYPO3\CMS\Core\Utility\File\BasicFileUtility::getUniqueName()
      */
-    protected function getUniqueName(Folder $folder, $theFile, $dontCheckForUnique = false)
+    protected function getUniqueName(FolderInterface $folder, $theFile, $dontCheckForUnique = false)
     {
         static $maxNumber = 99, $uniqueNamePrefix = '';
         // Fetches info about path, name, extension of $theFile
@@ -2876,7 +2828,7 @@ class ResourceStorage implements ResourceStorageInterface
             try {
                 if (strpos($processingFolder, ':') !== false) {
                     list($storageUid, $processingFolderIdentifier) = explode(':', $processingFolder, 2);
-                    $storage = ResourceFactory::getInstance()->getStorageObject($storageUid);
+                    $storage = $this->getResourceFactoryInstance()->getStorageObject($storageUid);
                     if ($storage->hasFolder($processingFolderIdentifier)) {
                         $this->processingFolder = $storage->getFolder($processingFolderIdentifier);
                     } else {
@@ -2901,16 +2853,22 @@ class ResourceStorage implements ResourceStorageInterface
                         $this->evaluatePermissions = $currentEvaluatePermissions;
                     } else {
                         $data = $this->driver->getFolderInfoByIdentifier($processingFolder);
-                        $this->processingFolder = ResourceFactory::getInstance()->createFolderObject($this, $data['identifier'], $data['name']);
+                        $this->processingFolder = $this->getResourceFactoryInstance()->createFolderObject($this, $data['identifier'], $data['name']);
                     }
                 }
             } catch (Exception\InsufficientFolderWritePermissionsException $e) {
                 $this->processingFolder = GeneralUtility::makeInstance(
-                    InaccessibleFolder::class, $this, $processingFolder, $processingFolder
+                    InaccessibleFolder::class,
+                    $this,
+                    $processingFolder,
+                    $processingFolder
                 );
             } catch (Exception\ResourcePermissionsUnavailableException $e) {
                 $this->processingFolder = GeneralUtility::makeInstance(
-                    InaccessibleFolder::class, $this, $processingFolder, $processingFolder
+                    InaccessibleFolder::class,
+                    $this,
+                    $processingFolder,
+                    $processingFolder
                 );
             }
         }
@@ -2998,7 +2956,6 @@ class ResourceStorage implements ResourceStorageInterface
 
     /**
      * @param bool $isDefault
-     * @return void
      */
     public function setDefault($isDefault)
     {
@@ -3012,4 +2969,22 @@ class ResourceStorage implements ResourceStorageInterface
     {
         return $this->isDefault;
     }
+
+    /**
+     * @return ResourceFactory
+     */
+    public function getResourceFactoryInstance(): ResourceFactory
+    {
+        return ResourceFactory::getInstance();
+    }
+
+    /**
+     * Returns the current BE user.
+     *
+     * @return \TYPO3\CMS\Core\Authentication\BackendUserAuthentication
+     */
+    protected function getBackendUser()
+    {
+        return $GLOBALS['BE_USER'];
+    }
 }