lin: bump psalm level

Signed-off-by: Varun Patil <radialapps@gmail.com>
pull/877/head
Varun Patil 2023-10-14 16:06:25 -07:00
parent eace12df0f
commit fe6205aea6
14 changed files with 46 additions and 19 deletions

View File

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

View File

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

View File

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

View File

@ -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') ?: ''),

View File

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

View File

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

View File

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

View File

@ -129,7 +129,7 @@ trait TimelineWriteMap
;
$query->executeStatement();
$clusterId = (int) $query->getLastInsertId();
$clusterId = $query->getLastInsertId();
$this->mapUpdateAggregates($clusterId);
$this->connection->commit();

View File

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

View File

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

View File

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

View File

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

View File

@ -1,7 +1,7 @@
<?xml version="1.0"?>
<psalm
totallyTyped="true"
errorLevel="5"
errorLevel="4"
resolveFromConfigFile="true"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://getpsalm.org/schema/config"
@ -37,4 +37,9 @@
</errorLevel>
</UndefinedDocblockClass>
</issueHandlers>
<forbiddenFunctions>
<function name="var_dump" />
<function name="print" />
<function name="print_r" />
</forbiddenFunctions>
</psalm>

View File

@ -1,7 +1,7 @@
<?xml version="1.0"?>
<psalm
totallyTyped="true"
errorLevel="5"
errorLevel="4"
resolveFromConfigFile="true"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://getpsalm.org/schema/config"
@ -36,4 +36,9 @@
</errorLevel>
</UndefinedDocblockClass>
</issueHandlers>
<forbiddenFunctions>
<function name="var_dump" />
<function name="print" />
<function name="print_r" />
</forbiddenFunctions>
</psalm>