Skip to content

Commit

Permalink
refactor: fix psalm info things
Browse files Browse the repository at this point in the history
Signed-off-by: Varun Patil <[email protected]>
  • Loading branch information
pulsejet committed Oct 14, 2023
1 parent 71ef41f commit 3fddf35
Show file tree
Hide file tree
Showing 20 changed files with 81 additions and 59 deletions.
2 changes: 2 additions & 0 deletions lib/ClustersBackend/Backend.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ abstract public function getClustersInternal(int $fileid = 0): array;

/**
* Get a cluster ID for the given cluster.
*
* @return string|int
*/
abstract public static function getClusterId(array $cluster);

Expand Down
3 changes: 0 additions & 3 deletions lib/Command/Index.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,6 @@ public function __construct(InputInterface $input)

class Index extends Command
{
/** @var int[][] */
protected array $sizes;

protected IUserManager $userManager;
protected IGroupManager $groupManager;
protected IRootFolder $rootFolder;
Expand Down
24 changes: 13 additions & 11 deletions lib/Controller/AdminController.php
Original file line number Diff line number Diff line change
Expand Up @@ -229,18 +229,20 @@ private function getExecutableStatus(
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)) {
Expand Down Expand Up @@ -268,6 +270,6 @@ private function actionToken(bool $set = false): string
$token = bin2hex(random_bytes(32));
$session->set('memories_action_token', $token);

return $token ?? '';
return $token;
}
}
4 changes: 2 additions & 2 deletions lib/Controller/DaysController.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public function day(string $id): Http\Response
);

// Force month id for dayId for month view
if ($this->isMonthView()) {
if ($this->isMonthView() && $dayIds) {
foreach ($list as &$photo) {
$photo['dayid'] = (int) $dayIds[0];
}
Expand Down Expand Up @@ -189,7 +189,7 @@ private function preloadDays(array &$days): void
}

// Build identical transforms for sub queries
$transforms = $this->getTransformations(false);
$transforms = $this->getTransformations();
$preloaded = 0;
$preloadDayIds = [];
$preloadDays = [];
Expand Down
3 changes: 3 additions & 0 deletions lib/Controller/DownloadController.php
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,9 @@ public function one(int $fileid, bool $resumable = true): Http\Response

// 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) {
Expand Down
2 changes: 1 addition & 1 deletion lib/Controller/OtherController.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public function getUserConfig(): Http\Response
}

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

Expand Down
12 changes: 6 additions & 6 deletions lib/Controller/PublicController.php
Original file line number Diff line number Diff line change
Expand Up @@ -162,11 +162,11 @@ protected function isPasswordProtected(): bool
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 */
Expand All @@ -180,16 +180,16 @@ protected function redirectIfOwned(IShare $share)
$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
Expand All @@ -203,7 +203,7 @@ protected function redirectIfOwned(IShare $share)

// Check if relPath starts with foldersPath
if (0 !== strpos($relPath, $foldersPath)) {
return null;
return;
}

// Remove foldersPath from start of relPath
Expand Down
5 changes: 5 additions & 0 deletions lib/Controller/VideoController.php
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,11 @@ public function livephoto(
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) {
Expand Down
2 changes: 1 addition & 1 deletion lib/Db/AddMissingIndices.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public static function run(IOutput $output): SchemaWrapper
}

// 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) {
Expand Down
2 changes: 1 addition & 1 deletion lib/Db/AlbumsQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ public function userIsCollaborator(string $uid, int $albumId): bool
* 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')
Expand Down
4 changes: 2 additions & 2 deletions lib/Db/FsManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -262,8 +262,8 @@ public function getShareFile(int $id): ?File
{
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;
}
Expand Down
4 changes: 2 additions & 2 deletions lib/Db/LivePhoto.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ public function isVideoPart(array $exif): bool
}

/** 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
Expand Down
20 changes: 10 additions & 10 deletions lib/Db/TimelineWriteMap.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -140,11 +140,11 @@ private function mapCreateCluster(float $lat, float $lon): int
/**
* 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;
Expand Down
8 changes: 4 additions & 4 deletions lib/Db/TimelineWritePlaces.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,13 @@ public function updatePlacesData(int $fileId, $lat, $lon): array
* 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);
Expand Down
5 changes: 4 additions & 1 deletion lib/Exif.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -334,6 +334,9 @@ public static function setFileExif(File $file, array $data): void
{
// 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);
Expand Down
2 changes: 1 addition & 1 deletion lib/Migration/Version505000Date20230821044807.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public function postSchemaChange(IOutput $output, \Closure $schemaClosure, array
->executeQuery()
->fetchOne()
;
$output->startProgress($maxCount);
$output->startProgress((int) $maxCount);

// get the required records
$result = $this->dbc->getQueryBuilder()
Expand Down
26 changes: 19 additions & 7 deletions lib/Service/BinExt.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,11 @@ public static function getExiftoolPBin(): string
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')) {
Expand All @@ -118,7 +122,11 @@ public static function getExiftool(): array
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'))) {
Expand Down Expand Up @@ -216,21 +224,21 @@ public static function getGoVodBin(): string
* 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
Expand Down Expand Up @@ -357,7 +365,11 @@ public static function configureGoVod(): bool
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');
Expand Down Expand Up @@ -416,7 +428,7 @@ public static function detectFFmpeg()

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}");
}
Expand Down
2 changes: 1 addition & 1 deletion lib/Service/Index.php
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ private function error(string $message): void
*/
private function log(string $message, bool $overwrite = false): void
{
if ($this->output) {
if ($this->section) {
if ($overwrite) {
$this->section->clear(1);
}
Expand Down
6 changes: 2 additions & 4 deletions lib/Service/Places.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@

class Places
{
protected IDBConnection $db;

protected IConfig $config;
protected IDBConnection $connection;
protected TimelineWrite $timelineWrite;
Expand Down Expand Up @@ -322,7 +320,7 @@ public function importPlanet(string $datafile): void
}

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

Expand All @@ -331,7 +329,7 @@ public function importPlanet(string $datafile): void

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

Expand Down
Loading

0 comments on commit 3fddf35

Please sign in to comment.