diff --git a/lib/ClustersBackend/Backend.php b/lib/ClustersBackend/Backend.php index e697bf9a..398bd2e1 100644 --- a/lib/ClustersBackend/Backend.php +++ b/lib/ClustersBackend/Backend.php @@ -68,6 +68,8 @@ abstract class Backend /** * Get a cluster ID for the given cluster. + * + * @return string|int */ abstract public static function getClusterId(array $cluster); diff --git a/lib/Command/Index.php b/lib/Command/Index.php index 301a066d..ca7276bc 100644 --- a/lib/Command/Index.php +++ b/lib/Command/Index.php @@ -57,9 +57,6 @@ class IndexOpts class Index extends Command { - /** @var int[][] */ - protected array $sizes; - protected IUserManager $userManager; protected IGroupManager $groupManager; protected IRootFolder $rootFolder; diff --git a/lib/Controller/AdminController.php b/lib/Controller/AdminController.php index f2794153..3e078391 100644 --- a/lib/Controller/AdminController.php +++ b/lib/Controller/AdminController.php @@ -229,18 +229,20 @@ class AdminController extends GenericApiController bool $testIfFile = true, bool $testIfExecutable = true ): string { - if ($testIfFile) { - if ($path instanceof \Closure) { - try { - $path = $path(); - } catch (\Exception $e) { - return 'test_fail:'.$e->getMessage(); - } + if ($path instanceof \Closure) { + try { + $path = $path(); + } catch (\Exception $e) { + return 'test_fail:'.$e->getMessage(); } + } - if (!\is_string($path) || !is_file($path)) { - return 'not_found'; - } + if (!\is_string($path)) { + return 'not_found'; + } + + if ($testIfFile && !is_file($path)) { + return 'not_found'; } if ($testIfExecutable && !is_executable($path)) { @@ -268,6 +270,6 @@ class AdminController extends GenericApiController $token = bin2hex(random_bytes(32)); $session->set('memories_action_token', $token); - return $token ?? ''; + return $token; } } diff --git a/lib/Controller/DaysController.php b/lib/Controller/DaysController.php index ef17ff51..6ef4ec2f 100644 --- a/lib/Controller/DaysController.php +++ b/lib/Controller/DaysController.php @@ -99,7 +99,7 @@ class DaysController extends GenericApiController ); // Force month id for dayId for month view - if ($this->isMonthView()) { + if ($this->isMonthView() && $dayIds) { foreach ($list as &$photo) { $photo['dayid'] = (int) $dayIds[0]; } @@ -189,7 +189,7 @@ class DaysController extends GenericApiController } // Build identical transforms for sub queries - $transforms = $this->getTransformations(false); + $transforms = $this->getTransformations(); $preloaded = 0; $preloadDayIds = []; $preloadDays = []; diff --git a/lib/Controller/DownloadController.php b/lib/Controller/DownloadController.php index 6141a9d3..a35aa46f 100644 --- a/lib/Controller/DownloadController.php +++ b/lib/Controller/DownloadController.php @@ -186,6 +186,9 @@ class DownloadController extends GenericApiController // Open file to send $res = $file->fopen('rb'); + if (false === $res) { + throw new \Exception('Failed to open file on disk'); + } // Seek to start if not zero if ($seekStart > 0) { diff --git a/lib/Controller/OtherController.php b/lib/Controller/OtherController.php index db117580..3f5328f5 100644 --- a/lib/Controller/OtherController.php +++ b/lib/Controller/OtherController.php @@ -77,7 +77,7 @@ class OtherController extends GenericApiController } // helper function to get user config values - $getAppConfig = function ($key, $default) use ($uid): string { + $getAppConfig = function ($key, $default) use ($uid) { return $this->config->getUserValue($uid, Application::APPNAME, $key, $default); }; diff --git a/lib/Controller/PublicController.php b/lib/Controller/PublicController.php index 6900d1cb..b5a8a82f 100644 --- a/lib/Controller/PublicController.php +++ b/lib/Controller/PublicController.php @@ -162,11 +162,11 @@ class PublicController extends AuthPublicShareController return null !== $this->share->getPassword(); } - protected function redirectIfOwned(IShare $share) + protected function redirectIfOwned(IShare $share): void { $user = $this->userSession->getUser(); if (!$user) { - return null; + return; } /** @var \OCP\Files\Node */ @@ -180,16 +180,16 @@ class PublicController extends AuthPublicShareController $userFolder = $this->rootFolder->getUserFolder($user->getUID()); $nodes = $userFolder->getById($share->getNodeId()); if (0 === \count($nodes)) { - return null; + return; } $node = $nodes[0]; } catch (NotFoundException $e) { - return null; + return; } // Check if node is a folder if (!$node instanceof \OCP\Files\Folder) { - return null; + return; } // Remove user folder path from start of node path @@ -203,7 +203,7 @@ class PublicController extends AuthPublicShareController // Check if relPath starts with foldersPath if (0 !== strpos($relPath, $foldersPath)) { - return null; + return; } // Remove foldersPath from start of relPath diff --git a/lib/Controller/VideoController.php b/lib/Controller/VideoController.php index 13ea0a94..2e1e88e2 100644 --- a/lib/Controller/VideoController.php +++ b/lib/Controller/VideoController.php @@ -162,6 +162,11 @@ class VideoController extends GenericApiController throw Exceptions::NotFound('Could not read binary EXIF field'); } } elseif (str_starts_with($liveid, 'self__traileroffset=')) { + // Make sure we have a path + if (!$path) { + throw Exceptions::BadRequest('File path missing for self__traileroffset'); + } + // Remove prefix $offset = (int) substr($liveid, \strlen('self__traileroffset=')); if ($offset <= 0) { diff --git a/lib/Db/AddMissingIndices.php b/lib/Db/AddMissingIndices.php index dff0051f..3daad3b0 100644 --- a/lib/Db/AddMissingIndices.php +++ b/lib/Db/AddMissingIndices.php @@ -59,7 +59,7 @@ class AddMissingIndices } // Migrate - if (\count($ops) > 0 && null !== $connection) { + if (\count($ops) > 0) { $output->info('Updating external table schema: '.implode(', ', $ops)); $connection->migrateToSchema($schema->getWrappedSchema()); } elseif (null === $connection) { diff --git a/lib/Db/AlbumsQuery.php b/lib/Db/AlbumsQuery.php index c025243f..1f5e7cbc 100644 --- a/lib/Db/AlbumsQuery.php +++ b/lib/Db/AlbumsQuery.php @@ -217,7 +217,7 @@ class AlbumsQuery * Get album object by token. * Returns false if album link does not exist. */ - public function getAlbumByLink(string $token) + public function getAlbumByLink(string $token): ?array { $query = $this->connection->getQueryBuilder(); $query->select('*')->from('photos_albums', 'pa') diff --git a/lib/Db/FsManager.php b/lib/Db/FsManager.php index 6c524dbc..6c71ceed 100644 --- a/lib/Db/FsManager.php +++ b/lib/Db/FsManager.php @@ -262,8 +262,8 @@ class FsManager { try { // Album share - if ($this->hasAlbumToken() && $this->getShareToken()) { - $album = $this->albumsQuery->getAlbumByLink($this->getShareToken()); + if ($this->hasAlbumToken() && ($token = $this->getShareToken())) { + $album = $this->albumsQuery->getAlbumByLink($token); if (null === $album) { return null; } diff --git a/lib/Db/LivePhoto.php b/lib/Db/LivePhoto.php index d101bd41..970d163e 100644 --- a/lib/Db/LivePhoto.php +++ b/lib/Db/LivePhoto.php @@ -29,11 +29,11 @@ class LivePhoto } /** Get liveid from photo part */ - public function getLivePhotoId(File $file, array $exif) + public function getLivePhotoId(File $file, array $exif): string { // Apple JPEG (MOV has ContentIdentifier) if (\array_key_exists('MediaGroupUUID', $exif)) { - return $exif['MediaGroupUUID']; + return (string) $exif['MediaGroupUUID']; } // Google MVIMG and Samsung JPEG diff --git a/lib/Db/TimelineWriteMap.php b/lib/Db/TimelineWriteMap.php index b2ee5e89..2f425477 100644 --- a/lib/Db/TimelineWriteMap.php +++ b/lib/Db/TimelineWriteMap.php @@ -17,15 +17,15 @@ trait TimelineWriteMap * Get the cluster ID for a given point. * If the cluster ID changes, update the old cluster and the new cluster. * - * @param int $prevCluster The current cluster ID of the point - * @param null|float $lat The latitude of the point - * @param null|float $lon The longitude of the point - * @param null|float $oldLat The old latitude of the point - * @param null|float $oldLon The old longitude of the point + * @param int $prevCluster The current cluster ID of the point + * @param ?float $lat The latitude of the point + * @param ?float $lon The longitude of the point + * @param ?float $oldLat The old latitude of the point + * @param ?float $oldLon The old longitude of the point * * @return int The new cluster ID */ - protected function mapGetCluster(int $prevCluster, $lat, $lon, $oldLat, $oldLon): int + protected function mapGetCluster(int $prevCluster, ?float $lat, ?float $lon, ?float $oldLat, ?float $oldLon): int { // Just remove from old cluster if the point is no longer valid if (null === $lat || null === $lon) { @@ -140,11 +140,11 @@ trait TimelineWriteMap /** * Remove a point from a cluster. * - * @param int $clusterId The ID of the cluster - * @param float $lat The latitude of the point - * @param float $lon The longitude of the point + * @param int $clusterId The ID of the cluster + * @param ?float $lat The latitude of the point + * @param ?float $lon The longitude of the point */ - private function mapRemoveFromCluster(int $clusterId, $lat, $lon): void + private function mapRemoveFromCluster(int $clusterId, ?float $lat, ?float $lon): void { if ($clusterId <= 0 || null === $lat || null === $lon) { return; diff --git a/lib/Db/TimelineWritePlaces.php b/lib/Db/TimelineWritePlaces.php index 0546bf22..4a6109cd 100644 --- a/lib/Db/TimelineWritePlaces.php +++ b/lib/Db/TimelineWritePlaces.php @@ -83,13 +83,13 @@ trait TimelineWritePlaces * Also update the exif data with the tzid from location (LocationTZID) * Performs an in-place update of the exif data. * - * @param int $fileId The file ID - * @param array $exif The exif data (will change) - * @param array|bool $prevRow The previous row of data + * @param int $fileId The file ID + * @param array $exif The exif data (will change) + * @param ?array $prevRow The previous row of data * * @return array Update values */ - protected function processExifLocation(int $fileId, array &$exif, $prevRow): array + protected function processExifLocation(int $fileId, array &$exif, ?array $prevRow): array { // Store location data [$lat, $lon] = self::readCoord($exif); diff --git a/lib/Exif.php b/lib/Exif.php index d1334df1..7d3492e1 100644 --- a/lib/Exif.php +++ b/lib/Exif.php @@ -17,7 +17,7 @@ class Exif /** Opened instance of exiftool when running in command mode */ private static $staticProc; private static $staticPipes; - private static $noStaticProc = false; + private static bool $noStaticProc = false; public static function closeStaticExiftoolProc(): void { @@ -334,6 +334,9 @@ class Exif { // Get path to local file so we can skip reading $path = $file->getStorage()->getLocalFile($file->getInternalPath()); + if (!$path) { + throw new \Exception('Failed to get local file path'); + } // Set exif data self::setExif($path, $data); diff --git a/lib/Migration/Version505000Date20230821044807.php b/lib/Migration/Version505000Date20230821044807.php index b99aeb1f..62e8f3bf 100644 --- a/lib/Migration/Version505000Date20230821044807.php +++ b/lib/Migration/Version505000Date20230821044807.php @@ -81,7 +81,7 @@ class Version505000Date20230821044807 extends SimpleMigrationStep ->executeQuery() ->fetchOne() ; - $output->startProgress($maxCount); + $output->startProgress((int) $maxCount); // get the required records $result = $this->dbc->getQueryBuilder() diff --git a/lib/Service/BinExt.php b/lib/Service/BinExt.php index bbbd406e..c48dd47b 100644 --- a/lib/Service/BinExt.php +++ b/lib/Service/BinExt.php @@ -108,7 +108,11 @@ class BinExt return self::getTempBin($path, self::getName('exiftool', self::EXIFTOOL_VER)); } - /** Get path to exiftool binary for proc_open */ + /** + * Get path to exiftool binary for proc_open. + * + * @return string[] + */ public static function getExiftool(): array { if (Util::getSystemConfig('memories.exiftool_no_local')) { @@ -118,7 +122,11 @@ class BinExt return [self::getExiftoolPBin()]; } - /** Detect the exiftool binary to use */ + /** + * Detect the exiftool binary to use. + * + * @return false|string + */ public static function detectExiftool() { if (!empty($path = Util::getSystemConfig('memories.exiftool'))) { @@ -216,21 +224,21 @@ class BinExt * If local, restart the go-vod instance. * If external, configure the go-vod instance. */ - public static function startGoVod() + public static function startGoVod(): ?string { // Check if disabled if (Util::getSystemConfig('memories.vod.disable')) { // Make sure it's dead, in case the user just disabled it Util::pkill(self::getName('go-vod')); - return; + return null; } // Check if external if (Util::getSystemConfig('memories.vod.external')) { self::configureGoVod(); - return; + return null; } // Get transcoder path @@ -357,7 +365,11 @@ class BinExt return true; } - /** Detect the go-vod binary to use */ + /** + * Detect the go-vod binary to use. + * + * @return false|string + */ public static function detectGoVod() { $goVodPath = Util::getSystemConfig('memories.vod.path'); @@ -416,7 +428,7 @@ class BinExt public static function testFFmpeg(string $path, string $name): string { - $version = shell_exec("{$path} -version"); + $version = shell_exec("{$path} -version") ?: ''; if (!preg_match("/{$name} version \\S*/", $version, $matches)) { throw new \Exception("failed to detect version, found {$version}"); } diff --git a/lib/Service/Index.php b/lib/Service/Index.php index da095fd5..81e6fc06 100644 --- a/lib/Service/Index.php +++ b/lib/Service/Index.php @@ -299,7 +299,7 @@ class Index */ private function log(string $message, bool $overwrite = false): void { - if ($this->output) { + if ($this->section) { if ($overwrite) { $this->section->clear(1); } diff --git a/lib/Service/Places.php b/lib/Service/Places.php index 41462ffd..e51813d8 100644 --- a/lib/Service/Places.php +++ b/lib/Service/Places.php @@ -16,8 +16,6 @@ const PLANET_URL = 'https://github.com/pulsejet/memories-assets/releases/downloa class Places { - protected IDBConnection $db; - protected IConfig $config; protected IDBConnection $connection; protected TimelineWrite $timelineWrite; @@ -322,7 +320,7 @@ class Places } if (GIS_TYPE_MYSQL === $gis) { - $points = implode(',', array_map(static function ($point) { + $points = implode(',', array_map(static function (array $point) { $x = $point[0]; $y = $point[1]; @@ -331,7 +329,7 @@ class Places $geometry = "POLYGON(({$points}))"; } elseif (GIS_TYPE_POSTGRES === $gis) { - $geometry = implode(',', array_map(static function ($point) { + $geometry = implode(',', array_map(static function (array $point) { $x = $point[0]; $y = $point[1]; diff --git a/lib/Util.php b/lib/Util.php index a9934d05..84d74397 100644 --- a/lib/Util.php +++ b/lib/Util.php @@ -18,7 +18,7 @@ class Util { use UtilController; - public static $ARCHIVE_FOLDER = '.archive'; + public static string $ARCHIVE_FOLDER = '.archive'; /** * Get host CPU architecture (amd64 or aarch64). @@ -248,7 +248,7 @@ class Util * @param $url URL of the page * @param $previewArgs Preview arguments (e.g. token) */ - public static function addOgMetadata(Node $node, string $title, string $url, array $previewArgs) + public static function addOgMetadata(Node $node, string $title, string $url, array $previewArgs): void { // Add title \OCP\Util::addHeader('meta', ['property' => 'og:title', 'content' => $title]);