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.
*
* @return string|int
*/
abstract public static function getClusterId(array $cluster);

View File

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

View File

@ -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;
}
}

View File

@ -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 = [];

View File

@ -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) {

View File

@ -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);
};

View File

@ -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

View File

@ -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) {

View File

@ -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) {

View File

@ -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')

View File

@ -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;
}

View File

@ -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

View File

@ -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;

View File

@ -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);

View File

@ -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);

View File

@ -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()

View File

@ -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}");
}

View File

@ -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);
}

View File

@ -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];

View File

@ -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]);