diff --git a/lib/ClustersBackend/AlbumsBackend.php b/lib/ClustersBackend/AlbumsBackend.php index 452fe699..f12f0366 100644 --- a/lib/ClustersBackend/AlbumsBackend.php +++ b/lib/ClustersBackend/AlbumsBackend.php @@ -99,7 +99,7 @@ class AlbumsBackend extends Backend // Remove elements with duplicate album_id $seenIds = []; - $list = array_filter($list, function ($item) use (&$seenIds) { + $list = array_filter($list, static function ($item) use (&$seenIds) { if (\in_array($item['album_id'], $seenIds, true)) { return false; } @@ -110,7 +110,7 @@ class AlbumsBackend extends Backend // Add display names for users $userManager = \OC::$server->get(\OCP\IUserManager::class); - array_walk($list, function (&$item) use ($userManager) { + array_walk($list, static function (&$item) use ($userManager) { $user = $userManager->get($item['user']); $item['user_display'] = $user ? $user->getDisplayName() : null; }); diff --git a/lib/ClustersBackend/PeopleBackendUtils.php b/lib/ClustersBackend/PeopleBackendUtils.php index 8cef941f..d0637797 100644 --- a/lib/ClustersBackend/PeopleBackendUtils.php +++ b/lib/ClustersBackend/PeopleBackendUtils.php @@ -71,7 +71,7 @@ trait PeopleBackendUtils } // Sort previews by score descending - usort($list, fn ($a, $b) => $b['score'] <=> $a['score']); + usort($list, static fn ($a, $b) => $b['score'] <=> $a['score']); } /** diff --git a/lib/Command/Index.php b/lib/Command/Index.php index bc1bc6ef..d8458340 100644 --- a/lib/Command/Index.php +++ b/lib/Command/Index.php @@ -201,7 +201,7 @@ class Index extends Command $this->output->writeln("User {$uid} not found"); } } else { - $this->userManager->callForSeenUsers(fn (IUser $user) => $closure($user)); + $this->userManager->callForSeenUsers(static fn (IUser $user) => $closure($user)); } } } diff --git a/lib/Command/MigrateGoogleTakeout.php b/lib/Command/MigrateGoogleTakeout.php index a5a66354..96c3c76a 100644 --- a/lib/Command/MigrateGoogleTakeout.php +++ b/lib/Command/MigrateGoogleTakeout.php @@ -243,7 +243,7 @@ class MigrateGoogleTakeout extends Command // Keep keys that are not in EXIF unless --override is specified if (!((bool) $this->input->getOption('override'))) { - $txf = array_filter($txf, function ($value, $key) use ($exif) { + $txf = array_filter($txf, static function ($value, $key) use ($exif) { return !isset($exif[$key]); }, ARRAY_FILTER_USE_BOTH); @@ -297,7 +297,7 @@ class MigrateGoogleTakeout extends Command protected function takeoutToExiftoolJson(array $json) { // Helper to get a value from nested JSON - $get = function (string $source) use ($json) { + $get = static function (string $source) use ($json) { $keys = array_reverse(explode('.', $source)); while (\count($keys) > 0) { $key = array_pop($keys); @@ -343,7 +343,7 @@ class MigrateGoogleTakeout extends Command $txf['GPSAltitude'] = $get('geoData.altitude'); // Remove all null values - return array_filter($txf, function ($value) { + return array_filter($txf, static function ($value) { return null !== $value; }); } diff --git a/lib/Controller/AdminController.php b/lib/Controller/AdminController.php index 2dbb589a..e488b5a8 100644 --- a/lib/Controller/AdminController.php +++ b/lib/Controller/AdminController.php @@ -93,14 +93,14 @@ class AdminController extends GenericApiController // Check exiftool version $exiftoolNoLocal = Util::getSystemConfig('memories.exiftool_no_local'); $status['exiftool'] = $this->getExecutableStatus( - fn () => BinExt::getExiftoolPBin(), - fn ($p) => BinExt::testExiftool(), + static fn () => BinExt::getExiftoolPBin(), + static fn ($p) => BinExt::testExiftool(), !$exiftoolNoLocal, !$exiftoolNoLocal, ); // Check for system perl - $status['perl'] = $this->getExecutableStatus(exec('which perl'), fn ($p) => BinExt::testSystemPerl($p)); + $status['perl'] = $this->getExecutableStatus(exec('which perl'), static fn ($p) => BinExt::testSystemPerl($p)); // Check number of indexed files $status['indexed_count'] = $index->getIndexedCount(); @@ -135,24 +135,24 @@ class AdminController extends GenericApiController $status['ffmpeg_preview'] = $this->getExecutableStatus( Util::getSystemConfig('preview_ffmpeg_path', null, true) ?: trim(shell_exec('which ffmpeg') ?: ''), - fn ($p) => BinExt::testFFmpeg($p, 'ffmpeg'), + static fn ($p) => BinExt::testFFmpeg($p, 'ffmpeg'), ); // Check ffmpeg and ffprobe binaries for transcoding $status['ffmpeg'] = $this->getExecutableStatus( Util::getSystemConfig('memories.vod.ffmpeg'), - fn ($p) => BinExt::testFFmpeg($p, 'ffmpeg'), + static fn ($p) => BinExt::testFFmpeg($p, 'ffmpeg'), ); $status['ffprobe'] = $this->getExecutableStatus( Util::getSystemConfig('memories.vod.ffprobe'), - fn ($p) => BinExt::testFFmpeg($p, 'ffprobe'), + static fn ($p) => BinExt::testFFmpeg($p, 'ffprobe'), ); // Check go-vod binary $extGoVod = Util::getSystemConfig('memories.vod.external'); $status['govod'] = $this->getExecutableStatus( - fn () => BinExt::getGoVodBin(), - fn ($p) => BinExt::testStartGoVod(), + static fn () => BinExt::getGoVodBin(), + static fn ($p) => BinExt::testStartGoVod(), !$extGoVod, !$extGoVod, ); @@ -188,7 +188,7 @@ class AdminController extends GenericApiController // Reset action token $this->actionToken(true); - return Util::guardExDirect(function (Http\IOutput $out) { + return Util::guardExDirect(static function (Http\IOutput $out) { try { // Set PHP timeout to infinite set_time_limit(0); diff --git a/lib/Controller/DaysController.php b/lib/Controller/DaysController.php index c0ec0360..a26a07df 100644 --- a/lib/Controller/DaysController.php +++ b/lib/Controller/DaysController.php @@ -76,7 +76,7 @@ class DaysController extends GenericApiController $dayIds = null; } else { // Split at commas and convert all parts to int - $dayIds = array_map(fn ($p) => (int) $p, explode(',', $id)); + $dayIds = array_map(static fn ($p) => (int) $p, explode(',', $id)); } // Check if $dayIds is empty diff --git a/lib/Controller/DownloadController.php b/lib/Controller/DownloadController.php index bf95843b..b3c7da57 100644 --- a/lib/Controller/DownloadController.php +++ b/lib/Controller/DownloadController.php @@ -46,7 +46,7 @@ class DownloadController extends GenericApiController */ public function request($files): Http\Response { - return Util::guardEx(function () use ($files) { + return Util::guardEx(static function () use ($files) { // Get ids from body if (null === $files || !\is_array($files)) { throw Exceptions::MissingParameter('files'); @@ -105,7 +105,7 @@ class DownloadController extends GenericApiController $fileIds = $info[1]; /** @var int[] $fileIds */ - $fileIds = array_filter(array_map('intval', $fileIds), fn ($id) => $id > 0); + $fileIds = array_filter(array_map('intval', $fileIds), static fn ($id) => $id > 0); // Check if we have any valid ids if (0 === \count($fileIds)) { diff --git a/lib/Controller/FoldersController.php b/lib/Controller/FoldersController.php index 874e87ad..6388f8c8 100644 --- a/lib/Controller/FoldersController.php +++ b/lib/Controller/FoldersController.php @@ -40,7 +40,7 @@ class FoldersController extends GenericApiController $folders = $view->getDirectoryContent($node->getPath(), FileInfo::MIMETYPE_FOLDER, $node); // Sort by name - usort($folders, fn ($a, $b) => strnatcmp($a->getName(), $b->getName())); + usort($folders, static fn ($a, $b) => strnatcmp($a->getName(), $b->getName())); // Process to response type $list = array_map(fn ($node) => [ diff --git a/lib/Controller/ImageController.php b/lib/Controller/ImageController.php index e02bc464..4153443e 100644 --- a/lib/Controller/ImageController.php +++ b/lib/Controller/ImageController.php @@ -84,7 +84,7 @@ class ImageController extends GenericApiController $files = json_decode($body, true); // Filter files with valid parameters - $files = array_filter($files, function ($file) { + $files = array_filter($files, static function ($file) { return isset($file['reqid'], $file['fileid'], $file['x'], $file['y'], $file['a']) && (int) $file['fileid'] > 0 && (int) $file['x'] > 0 @@ -92,7 +92,7 @@ class ImageController extends GenericApiController }); // Sort files by size, ascending - usort($files, function ($a, $b) { + usort($files, static function ($a, $b) { $aArea = (int) $a['x'] * (int) $a['y']; $bArea = (int) $b['x'] * (int) $b['y']; @@ -453,9 +453,9 @@ class ImageController extends GenericApiController /** @var \OCP\SystemTag\ISystemTag[] */ $tags = $tagManager->getTagsByIds($tagIds); - $visible = array_filter($tags, fn ($t) => $t->isUserVisible()); + $visible = array_filter($tags, static fn ($t) => $t->isUserVisible()); // Get the tag names - return array_map(fn ($t) => $t->getName(), $visible); + return array_map(static fn ($t) => $t->getName(), $visible); } } diff --git a/lib/Controller/MapController.php b/lib/Controller/MapController.php index 2c0ac165..b6f50cd4 100644 --- a/lib/Controller/MapController.php +++ b/lib/Controller/MapController.php @@ -50,7 +50,7 @@ class MapController extends GenericApiController $clusters = $this->timelineQuery->getMapClusters($gridLen, $bounds); // Get previews for each cluster - $clusterIds = array_map(fn ($cluster) => (int) $cluster['id'], $clusters); + $clusterIds = array_map(static fn ($cluster) => (int) $cluster['id'], $clusters); $previews = $this->timelineQuery->getMapClusterPreviews($clusterIds); // Merge the responses diff --git a/lib/Controller/OtherController.php b/lib/Controller/OtherController.php index f17ef0d0..b3a40755 100644 --- a/lib/Controller/OtherController.php +++ b/lib/Controller/OtherController.php @@ -125,7 +125,7 @@ class OtherController extends GenericApiController */ public function describeApi(): JSONResponse { - return Util::guardEx(function () { + return Util::guardEx(static function () { $appManager = \OC::$server->get(\OCP\App\IAppManager::class); $urlGenerator = \OC::$server->get(\OCP\IURLGenerator::class); diff --git a/lib/Controller/PageController.php b/lib/Controller/PageController.php index f8edee2a..bf52ff6e 100644 --- a/lib/Controller/PageController.php +++ b/lib/Controller/PageController.php @@ -69,7 +69,7 @@ class PageController extends Controller { // Image domains MUST be added to the connect domain list // because of the service worker fetch() call - $addImageDomain = function ($url) use (&$policy) { + $addImageDomain = static function ($url) use (&$policy) { $policy->addAllowedImageDomain($url); $policy->addAllowedConnectDomain($url); }; diff --git a/lib/Controller/PublicAlbumController.php b/lib/Controller/PublicAlbumController.php index 47261b99..08f5037f 100644 --- a/lib/Controller/PublicAlbumController.php +++ b/lib/Controller/PublicAlbumController.php @@ -129,7 +129,7 @@ class PublicAlbumController extends Controller // Get list of files $albumId = (int) $album['album_id']; $files = $this->albumsQuery->getAlbumPhotos($albumId, null) ?? []; - $fileIds = array_map(fn ($file) => (int) $file['file_id'], $files); + $fileIds = array_map(static fn ($file) => (int) $file['file_id'], $files); // Get download handle $downloadController = \OC::$server->get(\OCA\Memories\Controller\DownloadController::class); diff --git a/lib/Controller/ShareController.php b/lib/Controller/ShareController.php index 77bd9322..ed118e53 100644 --- a/lib/Controller/ShareController.php +++ b/lib/Controller/ShareController.php @@ -93,7 +93,7 @@ class ShareController extends GenericApiController */ public function deleteShare(string $id): Http\Response { - return Util::guardEx(function () use ($id) { + return Util::guardEx(static function () use ($id) { $uid = Util::getUID(); /** @var \OCP\Share\IManager $shareManager */ diff --git a/lib/Controller/VideoController.php b/lib/Controller/VideoController.php index ab7889ad..06c12ca2 100644 --- a/lib/Controller/VideoController.php +++ b/lib/Controller/VideoController.php @@ -263,7 +263,7 @@ class VideoController extends GenericApiController // Stream the response to the browser without reading it into memory $headersWritten = false; - curl_setopt($ch, CURLOPT_WRITEFUNCTION, function ($curl, $data) use (&$headersWritten, $profile) { + curl_setopt($ch, CURLOPT_WRITEFUNCTION, static function ($curl, $data) use (&$headersWritten, $profile) { $returnCode = (int) curl_getinfo($curl, CURLINFO_HTTP_CODE); if (200 === $returnCode) { @@ -353,8 +353,8 @@ class VideoController extends GenericApiController // Get file paths for all live photos $liveFiles = array_map(fn ($r) => $this->rootFolder->getById((int) $r['fileid']), $liveRecords); - $liveFiles = array_filter($liveFiles, fn ($files) => \count($files) > 0 && $files[0] instanceof File); - $liveFiles = array_map(fn ($files) => $files[0], $liveFiles); + $liveFiles = array_filter($liveFiles, static fn ($files) => \count($files) > 0 && $files[0] instanceof File); + $liveFiles = array_map(static fn ($files) => $files[0], $liveFiles); // Should be filtered enough by now if (!\count($liveFiles)) { @@ -362,7 +362,7 @@ class VideoController extends GenericApiController } // All paths including the image and videos need to be processed - $paths = array_map(function (File $file) { + $paths = array_map(static function (File $file) { $path = $file->getPath(); $filename = strtolower($file->getName()); @@ -382,7 +382,7 @@ class VideoController extends GenericApiController // Find closest path match $imagePath = array_pop($paths); - $scores = array_map(function ($path) use ($imagePath) { + $scores = array_map(static function ($path) use ($imagePath) { $score = 0; $length = min(\count($path), \count($imagePath)); for ($i = 0; $i < $length; ++$i) { diff --git a/lib/Cron/IndexJob.php b/lib/Cron/IndexJob.php index f8c67971..caf74902 100644 --- a/lib/Cron/IndexJob.php +++ b/lib/Cron/IndexJob.php @@ -52,7 +52,7 @@ class IndexJob extends TimedJob // Run for a maximum of 5 minutes $startTime = microtime(true); - $this->service->continueCheck = function () use ($startTime) { + $this->service->continueCheck = static function () use ($startTime) { return (microtime(true) - $startTime) < MAX_RUN_TIME; }; diff --git a/lib/Db/FsManager.php b/lib/Db/FsManager.php index 4335228b..b85e076e 100644 --- a/lib/Db/FsManager.php +++ b/lib/Db/FsManager.php @@ -170,7 +170,7 @@ class FsManager ]); $search = $root->search(new SearchQuery($comp, 0, 0, [], Util::getUser())); - $paths = array_unique(array_map(fn (Node $node) => \dirname($node->getPath()), $search)); + $paths = array_unique(array_map(static fn (Node $node) => \dirname($node->getPath()), $search)); $this->nomediaCache->set($key, $paths, 60 * 60); // 1 hour return $paths; diff --git a/lib/Db/TimelineQuerySingleItem.php b/lib/Db/TimelineQuerySingleItem.php index 97925b9f..7af47047 100644 --- a/lib/Db/TimelineQuerySingleItem.php +++ b/lib/Db/TimelineQuerySingleItem.php @@ -92,7 +92,7 @@ trait TimelineQuerySingleItem $places = $qb->executeQuery()->fetchAll(); $lang = Util::getUserLang(); if (\count($places) > 0) { - $places = array_map(fn ($p) => PlacesBackend::choosePlaceLang($p, $lang)['name'], $places); + $places = array_map(static fn ($p) => PlacesBackend::choosePlaceLang($p, $lang)['name'], $places); $info['address'] = implode(', ', $places); } } diff --git a/lib/Db/TimelineWriteOrphans.php b/lib/Db/TimelineWriteOrphans.php index 08c7bf2b..6e842102 100644 --- a/lib/Db/TimelineWriteOrphans.php +++ b/lib/Db/TimelineWriteOrphans.php @@ -65,7 +65,7 @@ trait TimelineWriteOrphans } // Mark all files as not orphaned. - $fileIds = array_map(fn ($row) => $row['fileid'], $orphans); + $fileIds = array_map(static fn ($row) => $row['fileid'], $orphans); $this->orphanAll(false, $fileIds, true); $this->connection->commit(); diff --git a/lib/Db/TimelineWritePlaces.php b/lib/Db/TimelineWritePlaces.php index fb6e1390..57a7b24b 100644 --- a/lib/Db/TimelineWritePlaces.php +++ b/lib/Db/TimelineWritePlaces.php @@ -50,7 +50,7 @@ trait TimelineWritePlaces $rows = \OC::$server->get(\OCA\Memories\Service\Places::class)->queryPoint($lat, $lon); // Get last ID, i.e. the ID with highest admin_level but <= 8 - $crows = array_filter($rows, fn ($row) => $row['admin_level'] <= 8); + $crows = array_filter($rows, static fn ($row) => $row['admin_level'] <= 8); $markRow = array_pop($crows); // Insert records in transaction @@ -74,7 +74,7 @@ trait TimelineWritePlaces $this->connection->commit(); // Return list of osm_id - return array_map(fn ($row) => $row['osm_id'], $rows); + return array_map(static fn ($row) => $row['osm_id'], $rows); } /** diff --git a/lib/Service/Index.php b/lib/Service/Index.php index 0e5aea93..2a0e1dd6 100644 --- a/lib/Service/Index.php +++ b/lib/Service/Index.php @@ -131,10 +131,10 @@ class Index // Filter files that are supported $mimes = self::getMimeList(); - $files = array_filter($nodes, fn ($n) => $n instanceof File && \in_array($n->getMimeType(), $mimes, true)); + $files = array_filter($nodes, static fn ($n) => $n instanceof File && \in_array($n->getMimeType(), $mimes, true)); // Create an associative array with file ID as key - $files = array_combine(array_map(fn ($n) => $n->getId(), $files), $files); + $files = array_combine(array_map(static fn ($n) => $n->getId(), $files), $files); // Chunk array into some files each (DBs have limitations on IN clause) $chunks = array_chunk($files, 250, true); @@ -151,7 +151,7 @@ class Index ; // Filter out files that are already indexed - $addFilter = function (string $table, string $alias) use (&$query) { + $addFilter = static function (string $table, string $alias) use (&$query) { $query->leftJoin('f', $table, $alias, $query->expr()->andX( $query->expr()->eq('f.fileid', "{$alias}.fileid"), $query->expr()->eq('f.mtime', "{$alias}.mtime"), @@ -174,7 +174,7 @@ class Index } // All folders - $folders = array_filter($nodes, fn ($n) => $n instanceof Folder); + $folders = array_filter($nodes, static fn ($n) => $n instanceof Folder); foreach ($folders as $folder) { $this->ensureContinueOk(); @@ -250,7 +250,7 @@ class Index { $preview = \OC::$server->get(IPreview::class); - return array_filter($source, fn ($m) => $preview->isMimeSupported($m)); + return array_filter($source, static fn ($m) => $preview->isMimeSupported($m)); } /** diff --git a/lib/Service/Places.php b/lib/Service/Places.php index 0fcf2a45..534adfea 100644 --- a/lib/Service/Places.php +++ b/lib/Service/Places.php @@ -315,7 +315,7 @@ class Places } if (GIS_TYPE_MYSQL === $gis) { - $points = implode(',', array_map(function ($point) { + $points = implode(',', array_map(static function ($point) { $x = $point[0]; $y = $point[1]; @@ -324,7 +324,7 @@ class Places $geometry = "POLYGON(({$points}))"; } elseif (GIS_TYPE_POSTGRES === $gis) { - $geometry = implode(',', array_map(function ($point) { + $geometry = implode(',', array_map(static function ($point) { $x = $point[0]; $y = $point[1]; diff --git a/lib/Util.php b/lib/Util.php index bd50a32a..e06e56c4 100644 --- a/lib/Util.php +++ b/lib/Util.php @@ -318,7 +318,7 @@ class Util $config = \OC::$server->get(IConfig::class); $paths = $config->getUserValue($uid, Application::APPNAME, 'timelinePath', null) ?? 'Photos/'; - return array_map(fn ($p) => self::sanitizePath(trim($p)), explode(';', $paths)); + return array_map(static fn ($p) => self::sanitizePath(trim($p)), explode(';', $paths)); } /**