Skip to content

Commit 4b4d171

Browse files
committed
fix: fix psalm issues
Signed-off-by: Marcel Klehr <mklehr@gmx.net>
1 parent dd78c84 commit 4b4d171

5 files changed

Lines changed: 15 additions & 590 deletions

File tree

lib/Service/GoogleDriveAPIService.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -542,7 +542,7 @@ private function createDirsUnder(array &$directoriesById, Folder $currentFolder,
542542
// create dir if we are on top OR if its parent is current dir
543543
if (($currentFolderId === '' && !array_key_exists($parentId, $directoriesById))
544544
|| $parentId === $currentFolderId) {
545-
$name = $this->fileUtils->sanitizeFilename((string)($dir['name']), $id);
545+
$name = $this->fileUtils->sanitizeFilename((string)($dir['name']), (string)$id);
546546
if (!$currentFolder->nodeExists($name)) {
547547
$newDir = $currentFolder->newFolder($name);
548548
} else {
@@ -552,7 +552,7 @@ private function createDirsUnder(array &$directoriesById, Folder $currentFolder,
552552
}
553553
}
554554
$directoriesById[$id]['node'] = $newDir;
555-
$success = $this->createDirsUnder($directoriesById, $newDir, $id);
555+
$success = $this->createDirsUnder($directoriesById, $newDir, (string)$id);
556556
if (!$success) {
557557
return false;
558558
}
@@ -625,7 +625,7 @@ private function downloadAndSaveFile(
625625
* @return string name of the file to be saved
626626
*/
627627
private function getFileName(array $fileItem, string $userId, bool $hasNameConflict): string {
628-
$fileName = $this->fileUtils->sanitizeFilename((string)($fileItem['name']), $fileItem['id']);
628+
$fileName = $this->fileUtils->sanitizeFilename((string)($fileItem['name']), (string)$fileItem['id']);
629629

630630
if (in_array($fileItem['mimeType'], array_values(self::DOCUMENT_MIME_TYPES))) {
631631
$documentFormat = $this->getUserDocumentFormat($userId);

lib/Service/GooglePhotosAPIService.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ public function importPhotos(
279279
$seenIds = [];
280280
foreach ($albums as $album) {
281281
$albumId = $album['id'];
282-
$albumName = $this->fileUtils->sanitizeFilename((string)($album['title']), $album['id']);
282+
$albumName = $this->fileUtils->sanitizeFilename((string)($album['title']), (string)$album['id']);
283283
if (!$folder->nodeExists($albumName)) {
284284
$albumFolder = $folder->newFolder($albumName);
285285
} else {
@@ -374,7 +374,7 @@ public function importPhotos(
374374
* @throws \OCP\Files\NotPermittedException
375375
*/
376376
private function getPhoto(string $userId, array $photo, Folder $albumFolder): ?int {
377-
$photoName = $this->fileUtils->sanitizeFilename((string)($photo['filename']), $photo['id']);
377+
$photoName = $this->fileUtils->sanitizeFilename($photo['filename'], (string)$photo['id']);
378378
if ($albumFolder->nodeExists($photoName)) {
379379
$photoName = $photo['id'] . '_' . $photoName;
380380
}

lib/Service/Utils/FileUtils.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
use Psr\Container\NotFoundExceptionInterface;
1212
use Psr\Log\LoggerInterface;
1313

14-
class FileUtils {
14+
final class FileUtils {
1515

1616
public function __construct(
1717
private \OCP\Files\IFilenameValidator $validator,
@@ -46,7 +46,7 @@ public function sanitizeFilename(
4646
}
4747

4848
// Use Nextcloud 32+ validator if available
49-
if (version_compare($this->config->getSystemValue('version', '0.0.0'), '32.0.0', '>=')) {
49+
if (version_compare($this->config->getSystemValueString('version', '0.0.0'), '32.0.0', '>=')) {
5050
$this->logger->debug('Using Nextcloud 32+ filename validator for sanitization.');
5151
try {
5252
return $this->validator->sanitizeFilename($filename);
@@ -80,7 +80,7 @@ public function sanitizeFilename(
8080
return $filename;
8181
} catch (\Throwable $exception) {
8282
$this->logger->warning('Exception during filename validation: ' . $filename, ['exception' => $exception]);
83-
$filename = self::handleFilenameException($filename, $id, $exception, $logger);
83+
$filename = self::handleFilenameException($filename, $id, $exception, $this->logger);
8484
if (strpos($filename, $id) === false) {
8585
$filename = self::appendIdBeforeExtension($filename, $id);
8686
}

0 commit comments

Comments
 (0)