refactor: fix psalm info things

Signed-off-by: Varun Patil <radialapps@gmail.com>
pull/877/head
Varun Patil 2023-10-14 02:07:18 -07:00
parent 71ef41f763
commit 3fddf35415
20 changed files with 81 additions and 59 deletions

View File

@ -68,6 +68,8 @@ abstract class Backend
/** /**
* Get a cluster ID for the given cluster. * Get a cluster ID for the given cluster.
*
* @return string|int
*/ */
abstract public static function getClusterId(array $cluster); abstract public static function getClusterId(array $cluster);

View File

@ -57,9 +57,6 @@ class IndexOpts
class Index extends Command class Index extends Command
{ {
/** @var int[][] */
protected array $sizes;
protected IUserManager $userManager; protected IUserManager $userManager;
protected IGroupManager $groupManager; protected IGroupManager $groupManager;
protected IRootFolder $rootFolder; protected IRootFolder $rootFolder;

View File

@ -229,7 +229,6 @@ class AdminController extends GenericApiController
bool $testIfFile = true, bool $testIfFile = true,
bool $testIfExecutable = true bool $testIfExecutable = true
): string { ): string {
if ($testIfFile) {
if ($path instanceof \Closure) { if ($path instanceof \Closure) {
try { try {
$path = $path(); $path = $path();
@ -238,9 +237,12 @@ class AdminController extends GenericApiController
} }
} }
if (!\is_string($path) || !is_file($path)) { if (!\is_string($path)) {
return 'not_found'; return 'not_found';
} }
if ($testIfFile && !is_file($path)) {
return 'not_found';
} }
if ($testIfExecutable && !is_executable($path)) { if ($testIfExecutable && !is_executable($path)) {
@ -268,6 +270,6 @@ class AdminController extends GenericApiController
$token = bin2hex(random_bytes(32)); $token = bin2hex(random_bytes(32));
$session->set('memories_action_token', $token); $session->set('memories_action_token', $token);
return $token ?? ''; return $token;
} }
} }

View File

@ -99,7 +99,7 @@ class DaysController extends GenericApiController
); );
// Force month id for dayId for month view // Force month id for dayId for month view
if ($this->isMonthView()) { if ($this->isMonthView() && $dayIds) {
foreach ($list as &$photo) { foreach ($list as &$photo) {
$photo['dayid'] = (int) $dayIds[0]; $photo['dayid'] = (int) $dayIds[0];
} }
@ -189,7 +189,7 @@ class DaysController extends GenericApiController
} }
// Build identical transforms for sub queries // Build identical transforms for sub queries
$transforms = $this->getTransformations(false); $transforms = $this->getTransformations();
$preloaded = 0; $preloaded = 0;
$preloadDayIds = []; $preloadDayIds = [];
$preloadDays = []; $preloadDays = [];

View File

@ -186,6 +186,9 @@ class DownloadController extends GenericApiController
// Open file to send // Open file to send
$res = $file->fopen('rb'); $res = $file->fopen('rb');
if (false === $res) {
throw new \Exception('Failed to open file on disk');
}
// Seek to start if not zero // Seek to start if not zero
if ($seekStart > 0) { if ($seekStart > 0) {

View File

@ -77,7 +77,7 @@ class OtherController extends GenericApiController
} }
// helper function to get user config values // 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); return $this->config->getUserValue($uid, Application::APPNAME, $key, $default);
}; };

View File

@ -162,11 +162,11 @@ class PublicController extends AuthPublicShareController
return null !== $this->share->getPassword(); return null !== $this->share->getPassword();
} }
protected function redirectIfOwned(IShare $share) protected function redirectIfOwned(IShare $share): void
{ {
$user = $this->userSession->getUser(); $user = $this->userSession->getUser();
if (!$user) { if (!$user) {
return null; return;
} }
/** @var \OCP\Files\Node */ /** @var \OCP\Files\Node */
@ -180,16 +180,16 @@ class PublicController extends AuthPublicShareController
$userFolder = $this->rootFolder->getUserFolder($user->getUID()); $userFolder = $this->rootFolder->getUserFolder($user->getUID());
$nodes = $userFolder->getById($share->getNodeId()); $nodes = $userFolder->getById($share->getNodeId());
if (0 === \count($nodes)) { if (0 === \count($nodes)) {
return null; return;
} }
$node = $nodes[0]; $node = $nodes[0];
} catch (NotFoundException $e) { } catch (NotFoundException $e) {
return null; return;
} }
// Check if node is a folder // Check if node is a folder
if (!$node instanceof \OCP\Files\Folder) { if (!$node instanceof \OCP\Files\Folder) {
return null; return;
} }
// Remove user folder path from start of node path // Remove user folder path from start of node path
@ -203,7 +203,7 @@ class PublicController extends AuthPublicShareController
// Check if relPath starts with foldersPath // Check if relPath starts with foldersPath
if (0 !== strpos($relPath, $foldersPath)) { if (0 !== strpos($relPath, $foldersPath)) {
return null; return;
} }
// Remove foldersPath from start of relPath // Remove foldersPath from start of relPath

View File

@ -162,6 +162,11 @@ class VideoController extends GenericApiController
throw Exceptions::NotFound('Could not read binary EXIF field'); throw Exceptions::NotFound('Could not read binary EXIF field');
} }
} elseif (str_starts_with($liveid, 'self__traileroffset=')) { } 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 // Remove prefix
$offset = (int) substr($liveid, \strlen('self__traileroffset=')); $offset = (int) substr($liveid, \strlen('self__traileroffset='));
if ($offset <= 0) { if ($offset <= 0) {

View File

@ -59,7 +59,7 @@ class AddMissingIndices
} }
// Migrate // Migrate
if (\count($ops) > 0 && null !== $connection) { if (\count($ops) > 0) {
$output->info('Updating external table schema: '.implode(', ', $ops)); $output->info('Updating external table schema: '.implode(', ', $ops));
$connection->migrateToSchema($schema->getWrappedSchema()); $connection->migrateToSchema($schema->getWrappedSchema());
} elseif (null === $connection) { } elseif (null === $connection) {

View File

@ -217,7 +217,7 @@ class AlbumsQuery
* Get album object by token. * Get album object by token.
* Returns false if album link does not exist. * Returns false if album link does not exist.
*/ */
public function getAlbumByLink(string $token) public function getAlbumByLink(string $token): ?array
{ {
$query = $this->connection->getQueryBuilder(); $query = $this->connection->getQueryBuilder();
$query->select('*')->from('photos_albums', 'pa') $query->select('*')->from('photos_albums', 'pa')

View File

@ -262,8 +262,8 @@ class FsManager
{ {
try { try {
// Album share // Album share
if ($this->hasAlbumToken() && $this->getShareToken()) { if ($this->hasAlbumToken() && ($token = $this->getShareToken())) {
$album = $this->albumsQuery->getAlbumByLink($this->getShareToken()); $album = $this->albumsQuery->getAlbumByLink($token);
if (null === $album) { if (null === $album) {
return null; return null;
} }

View File

@ -29,11 +29,11 @@ class LivePhoto
} }
/** Get liveid from photo part */ /** 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) // Apple JPEG (MOV has ContentIdentifier)
if (\array_key_exists('MediaGroupUUID', $exif)) { if (\array_key_exists('MediaGroupUUID', $exif)) {
return $exif['MediaGroupUUID']; return (string) $exif['MediaGroupUUID'];
} }
// Google MVIMG and Samsung JPEG // Google MVIMG and Samsung JPEG

View File

@ -18,14 +18,14 @@ trait TimelineWriteMap
* If the cluster ID changes, update the old cluster and the new cluster. * If the cluster ID changes, update the old cluster and the new cluster.
* *
* @param int $prevCluster The current cluster ID of the point * @param int $prevCluster The current cluster ID of the point
* @param null|float $lat The latitude of the point * @param ?float $lat The latitude of the point
* @param null|float $lon The longitude of the point * @param ?float $lon The longitude of the point
* @param null|float $oldLat The old latitude of the point * @param ?float $oldLat The old latitude of the point
* @param null|float $oldLon The old longitude of the point * @param ?float $oldLon The old longitude of the point
* *
* @return int The new cluster ID * @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 // Just remove from old cluster if the point is no longer valid
if (null === $lat || null === $lon) { if (null === $lat || null === $lon) {
@ -141,10 +141,10 @@ trait TimelineWriteMap
* Remove a point from a cluster. * Remove a point from a cluster.
* *
* @param int $clusterId The ID of the cluster * @param int $clusterId The ID of the cluster
* @param float $lat The latitude of the point * @param ?float $lat The latitude of the point
* @param float $lon The longitude 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) { if ($clusterId <= 0 || null === $lat || null === $lon) {
return; return;

View File

@ -85,11 +85,11 @@ trait TimelineWritePlaces
* *
* @param int $fileId The file ID * @param int $fileId The file ID
* @param array $exif The exif data (will change) * @param array $exif The exif data (will change)
* @param array|bool $prevRow The previous row of data * @param ?array $prevRow The previous row of data
* *
* @return array Update values * @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 // Store location data
[$lat, $lon] = self::readCoord($exif); [$lat, $lon] = self::readCoord($exif);

View File

@ -17,7 +17,7 @@ class Exif
/** Opened instance of exiftool when running in command mode */ /** Opened instance of exiftool when running in command mode */
private static $staticProc; private static $staticProc;
private static $staticPipes; private static $staticPipes;
private static $noStaticProc = false; private static bool $noStaticProc = false;
public static function closeStaticExiftoolProc(): void public static function closeStaticExiftoolProc(): void
{ {
@ -334,6 +334,9 @@ class Exif
{ {
// Get path to local file so we can skip reading // Get path to local file so we can skip reading
$path = $file->getStorage()->getLocalFile($file->getInternalPath()); $path = $file->getStorage()->getLocalFile($file->getInternalPath());
if (!$path) {
throw new \Exception('Failed to get local file path');
}
// Set exif data // Set exif data
self::setExif($path, $data); self::setExif($path, $data);

View File

@ -81,7 +81,7 @@ class Version505000Date20230821044807 extends SimpleMigrationStep
->executeQuery() ->executeQuery()
->fetchOne() ->fetchOne()
; ;
$output->startProgress($maxCount); $output->startProgress((int) $maxCount);
// get the required records // get the required records
$result = $this->dbc->getQueryBuilder() $result = $this->dbc->getQueryBuilder()

View File

@ -108,7 +108,11 @@ class BinExt
return self::getTempBin($path, self::getName('exiftool', self::EXIFTOOL_VER)); 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 public static function getExiftool(): array
{ {
if (Util::getSystemConfig('memories.exiftool_no_local')) { if (Util::getSystemConfig('memories.exiftool_no_local')) {
@ -118,7 +122,11 @@ class BinExt
return [self::getExiftoolPBin()]; return [self::getExiftoolPBin()];
} }
/** Detect the exiftool binary to use */ /**
* Detect the exiftool binary to use.
*
* @return false|string
*/
public static function detectExiftool() public static function detectExiftool()
{ {
if (!empty($path = Util::getSystemConfig('memories.exiftool'))) { if (!empty($path = Util::getSystemConfig('memories.exiftool'))) {
@ -216,21 +224,21 @@ class BinExt
* If local, restart the go-vod instance. * If local, restart the go-vod instance.
* If external, configure the go-vod instance. * If external, configure the go-vod instance.
*/ */
public static function startGoVod() public static function startGoVod(): ?string
{ {
// Check if disabled // Check if disabled
if (Util::getSystemConfig('memories.vod.disable')) { if (Util::getSystemConfig('memories.vod.disable')) {
// Make sure it's dead, in case the user just disabled it // Make sure it's dead, in case the user just disabled it
Util::pkill(self::getName('go-vod')); Util::pkill(self::getName('go-vod'));
return; return null;
} }
// Check if external // Check if external
if (Util::getSystemConfig('memories.vod.external')) { if (Util::getSystemConfig('memories.vod.external')) {
self::configureGoVod(); self::configureGoVod();
return; return null;
} }
// Get transcoder path // Get transcoder path
@ -357,7 +365,11 @@ class BinExt
return true; return true;
} }
/** Detect the go-vod binary to use */ /**
* Detect the go-vod binary to use.
*
* @return false|string
*/
public static function detectGoVod() public static function detectGoVod()
{ {
$goVodPath = Util::getSystemConfig('memories.vod.path'); $goVodPath = Util::getSystemConfig('memories.vod.path');
@ -416,7 +428,7 @@ class BinExt
public static function testFFmpeg(string $path, string $name): string 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)) { if (!preg_match("/{$name} version \\S*/", $version, $matches)) {
throw new \Exception("failed to detect version, found {$version}"); throw new \Exception("failed to detect version, found {$version}");
} }

View File

@ -299,7 +299,7 @@ class Index
*/ */
private function log(string $message, bool $overwrite = false): void private function log(string $message, bool $overwrite = false): void
{ {
if ($this->output) { if ($this->section) {
if ($overwrite) { if ($overwrite) {
$this->section->clear(1); $this->section->clear(1);
} }

View File

@ -16,8 +16,6 @@ const PLANET_URL = 'https://github.com/pulsejet/memories-assets/releases/downloa
class Places class Places
{ {
protected IDBConnection $db;
protected IConfig $config; protected IConfig $config;
protected IDBConnection $connection; protected IDBConnection $connection;
protected TimelineWrite $timelineWrite; protected TimelineWrite $timelineWrite;
@ -322,7 +320,7 @@ class Places
} }
if (GIS_TYPE_MYSQL === $gis) { if (GIS_TYPE_MYSQL === $gis) {
$points = implode(',', array_map(static function ($point) { $points = implode(',', array_map(static function (array $point) {
$x = $point[0]; $x = $point[0];
$y = $point[1]; $y = $point[1];
@ -331,7 +329,7 @@ class Places
$geometry = "POLYGON(({$points}))"; $geometry = "POLYGON(({$points}))";
} elseif (GIS_TYPE_POSTGRES === $gis) { } elseif (GIS_TYPE_POSTGRES === $gis) {
$geometry = implode(',', array_map(static function ($point) { $geometry = implode(',', array_map(static function (array $point) {
$x = $point[0]; $x = $point[0];
$y = $point[1]; $y = $point[1];

View File

@ -18,7 +18,7 @@ class Util
{ {
use UtilController; use UtilController;
public static $ARCHIVE_FOLDER = '.archive'; public static string $ARCHIVE_FOLDER = '.archive';
/** /**
* Get host CPU architecture (amd64 or aarch64). * Get host CPU architecture (amd64 or aarch64).
@ -248,7 +248,7 @@ class Util
* @param $url URL of the page * @param $url URL of the page
* @param $previewArgs Preview arguments (e.g. token) * @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 // Add title
\OCP\Util::addHeader('meta', ['property' => 'og:title', 'content' => $title]); \OCP\Util::addHeader('meta', ['property' => 'og:title', 'content' => $title]);