From fe6205aea62ae30cddc2f2b301e928caa5fed012 Mon Sep 17 00:00:00 2001 From: Varun Patil Date: Sat, 14 Oct 2023 16:06:25 -0700 Subject: [PATCH] lin: bump psalm level Signed-off-by: Varun Patil --- lib/ClustersBackend/AlbumsBackend.php | 2 +- .../FaceRecognitionBackend.php | 2 +- lib/ClustersBackend/RecognizeBackend.php | 2 +- lib/Controller/AdminController.php | 2 ++ lib/Controller/PublicAlbumController.php | 5 +++-- lib/Db/AddMissingIndices.php | 2 -- lib/Db/TimelineQueryFilters.php | 1 + lib/Db/TimelineWriteMap.php | 2 +- lib/Service/BinExt.php | 21 ++++++++++++++----- lib/Service/FileRobotMagick.php | 6 +++--- lib/Service/Places.php | 2 +- lib/Util.php | 4 ++++ psalm-ls.xml | 7 ++++++- psalm.xml | 7 ++++++- 14 files changed, 46 insertions(+), 19 deletions(-) diff --git a/lib/ClustersBackend/AlbumsBackend.php b/lib/ClustersBackend/AlbumsBackend.php index c0b6b4cd..ff209f7b 100644 --- a/lib/ClustersBackend/AlbumsBackend.php +++ b/lib/ClustersBackend/AlbumsBackend.php @@ -135,7 +135,7 @@ class AlbumsBackend extends Backend // Get files $id = (int) $album['album_id']; - return $this->albumsQuery->getAlbumPhotos($id, $limit) ?? []; + return $this->albumsQuery->getAlbumPhotos($id, $limit); } public function sortPhotosForPreview(array &$photos): void diff --git a/lib/ClustersBackend/FaceRecognitionBackend.php b/lib/ClustersBackend/FaceRecognitionBackend.php index 31937894..befc1ca9 100644 --- a/lib/ClustersBackend/FaceRecognitionBackend.php +++ b/lib/ClustersBackend/FaceRecognitionBackend.php @@ -107,7 +107,7 @@ class FaceRecognitionBackend extends Backend public function transformDayPost(array &$row): void { // Differentiate Recognize queries from Face Recognition - if (!isset($row) || !isset($row['face_width']) || !isset($row['image_width'])) { + if (!isset($row['face_width']) || !isset($row['image_width'])) { return; } diff --git a/lib/ClustersBackend/RecognizeBackend.php b/lib/ClustersBackend/RecognizeBackend.php index fcb56c7b..cd8dd40f 100644 --- a/lib/ClustersBackend/RecognizeBackend.php +++ b/lib/ClustersBackend/RecognizeBackend.php @@ -116,7 +116,7 @@ class RecognizeBackend extends Backend public function transformDayPost(array &$row): void { // Differentiate Recognize queries from Face Recognition - if (!isset($row) || !isset($row['face_w'])) { + if (!isset($row['face_w'])) { return; } diff --git a/lib/Controller/AdminController.php b/lib/Controller/AdminController.php index 3e078391..98733787 100644 --- a/lib/Controller/AdminController.php +++ b/lib/Controller/AdminController.php @@ -100,6 +100,7 @@ class AdminController extends GenericApiController ); // Check for system perl + /** @psalm-suppress ForbiddenCode */ $status['perl'] = $this->getExecutableStatus( trim(shell_exec('which perl') ?: '/bin/perl'), static fn ($p) => BinExt::testSystemPerl($p) @@ -135,6 +136,7 @@ class AdminController extends GenericApiController } // Check for FFmpeg for preview generation + /** @psalm-suppress ForbiddenCode */ $status['ffmpeg_preview'] = $this->getExecutableStatus( Util::getSystemConfig('preview_ffmpeg_path') ?: trim(shell_exec('which ffmpeg') ?: ''), diff --git a/lib/Controller/PublicAlbumController.php b/lib/Controller/PublicAlbumController.php index b33b6674..714e571c 100644 --- a/lib/Controller/PublicAlbumController.php +++ b/lib/Controller/PublicAlbumController.php @@ -6,6 +6,7 @@ use OCA\Memories\Db\AlbumsQuery; use OCP\App\IAppManager; use OCP\AppFramework\Controller; use OCP\AppFramework\Http\RedirectResponse; +use OCP\AppFramework\Http\Response; use OCP\AppFramework\Http\Template\LinkMenuAction; use OCP\AppFramework\Http\Template\PublicTemplateResponse; use OCP\AppFramework\Http\TemplateResponse; @@ -119,7 +120,7 @@ class PublicAlbumController extends Controller * * @NoCSRFRequired */ - public function download(string $token) + public function download(string $token): Response { $album = $this->albumsQuery->getAlbumByLink($token); if (!$album) { @@ -128,7 +129,7 @@ class PublicAlbumController extends Controller // Get list of files $albumId = (int) $album['album_id']; - $files = $this->albumsQuery->getAlbumPhotos($albumId, null) ?? []; + $files = $this->albumsQuery->getAlbumPhotos($albumId, null); $fileIds = array_map(static fn ($file) => (int) $file['file_id'], $files); // Get download handle diff --git a/lib/Db/AddMissingIndices.php b/lib/Db/AddMissingIndices.php index 3daad3b0..93a720ed 100644 --- a/lib/Db/AddMissingIndices.php +++ b/lib/Db/AddMissingIndices.php @@ -62,8 +62,6 @@ class AddMissingIndices if (\count($ops) > 0) { $output->info('Updating external table schema: '.implode(', ', $ops)); $connection->migrateToSchema($schema->getWrappedSchema()); - } elseif (null === $connection) { - $output->warning('No database connection, skipping external table schema update'); } else { $output->info('External table schema seem up to date'); } diff --git a/lib/Db/TimelineQueryFilters.php b/lib/Db/TimelineQueryFilters.php index c7eaa49d..fe8bc823 100644 --- a/lib/Db/TimelineQueryFilters.php +++ b/lib/Db/TimelineQueryFilters.php @@ -38,6 +38,7 @@ trait TimelineQueryFilters public function transformLimit(IQueryBuilder &$query, bool $aggregate, int $limit): void { + /** @psalm-suppress RedundantCondition */ if ($limit >= 1 || $limit <= 100) { $query->setMaxResults($limit); } diff --git a/lib/Db/TimelineWriteMap.php b/lib/Db/TimelineWriteMap.php index 2f425477..d79ffc75 100644 --- a/lib/Db/TimelineWriteMap.php +++ b/lib/Db/TimelineWriteMap.php @@ -129,7 +129,7 @@ trait TimelineWriteMap ; $query->executeStatement(); - $clusterId = (int) $query->getLastInsertId(); + $clusterId = $query->getLastInsertId(); $this->mapUpdateAggregates($clusterId); $this->connection->commit(); diff --git a/lib/Service/BinExt.php b/lib/Service/BinExt.php index c48dd47b..ce6d295a 100644 --- a/lib/Service/BinExt.php +++ b/lib/Service/BinExt.php @@ -65,6 +65,8 @@ class BinExt public static function testExiftool(): string { $cmd = implode(' ', array_merge(self::getExiftool(), ['-ver'])); + + /** @psalm-suppress ForbiddenCode */ $out = shell_exec($cmd); if (!$out) { throw new \Exception("failed to run exiftool: {$cmd}"); @@ -252,6 +254,7 @@ class BinExt $tmpPath = $env['tempdir']; // (Re-)create temp dir + /** @psalm-suppress ForbiddenCode */ shell_exec("rm -rf '{$tmpPath}' && mkdir -p '{$tmpPath}' && chmod 755 '{$tmpPath}'"); // Check temp directory exists @@ -273,6 +276,7 @@ class BinExt Util::pkill(self::getName('go-vod')); // Start transcoder + /** @psalm-suppress ForbiddenCode */ shell_exec("nohup {$transcoder} {$configFile} >> '{$logFile}' 2>&1 & > /dev/null"); // wait for 500ms @@ -396,17 +400,21 @@ class BinExt return $goVodPath; } - public static function detectFFmpeg() + public static function detectFFmpeg(): ?string { $ffmpegPath = Util::getSystemConfig('memories.vod.ffmpeg'); $ffprobePath = Util::getSystemConfig('memories.vod.ffprobe'); if (empty($ffmpegPath) || !file_exists($ffmpegPath) || empty($ffprobePath) || !file_exists($ffprobePath)) { - // Use PATH + // Use PATH environment variable to find ffmpeg + + /** @psalm-suppress ForbiddenCode */ $ffmpegPath = shell_exec('which ffmpeg'); + + /** @psalm-suppress ForbiddenCode */ $ffprobePath = shell_exec('which ffprobe'); if (!$ffmpegPath || !$ffprobePath) { - return false; + return null; } // Trim @@ -420,7 +428,7 @@ class BinExt // Check if executable if (!is_executable($ffmpegPath) || !is_executable($ffprobePath)) { - return false; + return null; } return $ffmpegPath; @@ -428,6 +436,7 @@ class BinExt public static function testFFmpeg(string $path, string $name): string { + /** @psalm-suppress ForbiddenCode */ $version = shell_exec("{$path} -version") ?: ''; if (!preg_match("/{$name} version \\S*/", $version, $matches)) { throw new \Exception("failed to detect version, found {$version}"); @@ -438,10 +447,12 @@ class BinExt public static function testSystemPerl(string $path): ?string { + /** @psalm-suppress ForbiddenCode */ if (($out = shell_exec("{$path} -e 'print \"OK\";'")) !== 'OK') { - throw new \Exception('Failed to run test perl script: '.$out); + throw new \Exception('Failed to run test perl script: '.(string) $out); } + /** @psalm-suppress ForbiddenCode */ return shell_exec("{$path} -e 'print $^V;'") ?: null; } } diff --git a/lib/Service/FileRobotMagick.php b/lib/Service/FileRobotMagick.php index a764b491..25291278 100644 --- a/lib/Service/FileRobotMagick.php +++ b/lib/Service/FileRobotMagick.php @@ -256,9 +256,9 @@ class FileRobotMagick return; } - $h = abs(($hue ?? 0) + 360) % 360; - $s = 2 ** ($saturation ?? 0); - $v = 2 ** ($value ?? 0); + $h = abs($hue + 360) % 360; + $s = 2 ** $saturation; + $v = 2 ** $value; // https://github.com/konvajs/konva/blob/f0e18b09079175404a1026363689f8f89eae0749/src/filters/HSV.ts#L17-L63 $vsu = $v * $s * cos(($h * M_PI) / 180); diff --git a/lib/Service/Places.php b/lib/Service/Places.php index e51813d8..0244f727 100644 --- a/lib/Service/Places.php +++ b/lib/Service/Places.php @@ -222,7 +222,7 @@ class Places // Create geometry insertion statement $query = $this->connection->getQueryBuilder(); - $geomParam = $query->createParameter('geometry'); + $geomParam = (string) $query->createParameter('geometry'); if (GIS_TYPE_MYSQL === $gis) { $geomParam = "ST_GeomFromText({$geomParam})"; } elseif (GIS_TYPE_POSTGRES === $gis) { diff --git a/lib/Util.php b/lib/Util.php index 84d74397..17314762 100644 --- a/lib/Util.php +++ b/lib/Util.php @@ -45,6 +45,7 @@ class Util */ public static function getLibc(): ?string { + /** @psalm-suppress ForbiddenCode */ if ($ldd = shell_exec('ldd --version 2>&1')) { if (false !== stripos($ldd, 'musl')) { return 'musl'; @@ -496,6 +497,8 @@ class Util // check if ps or busybox is available $ps = 'ps'; + + /** @psalm-suppress ForbiddenCode */ if (!shell_exec('which ps')) { if (!shell_exec('which busybox')) { return; @@ -505,6 +508,7 @@ class Util } // get pids using ps as array + /** @psalm-suppress ForbiddenCode */ $pids = shell_exec("{$ps} -eao pid,comm | grep {$name} | awk '{print $1}'"); if (null === $pids || empty($pids)) { return; diff --git a/psalm-ls.xml b/psalm-ls.xml index eb9f6a8b..fdee1de6 100644 --- a/psalm-ls.xml +++ b/psalm-ls.xml @@ -1,7 +1,7 @@ + + + + + \ No newline at end of file diff --git a/psalm.xml b/psalm.xml index 5cd61c32..7834ffca 100644 --- a/psalm.xml +++ b/psalm.xml @@ -1,7 +1,7 @@ + + + + + \ No newline at end of file