diff --git a/lib/ClustersBackend/FaceRecognitionBackend.php b/lib/ClustersBackend/FaceRecognitionBackend.php index 92c6c8b4..ef10284c 100644 --- a/lib/ClustersBackend/FaceRecognitionBackend.php +++ b/lib/ClustersBackend/FaceRecognitionBackend.php @@ -125,7 +125,7 @@ class FaceRecognitionBackend extends Backend // Post process foreach ($faces as &$row) { - $row['id'] = \array_key_exists('name', $row) ? $row['name'] : (int) $row['id']; + $row['id'] = $row['name'] ?? (int) $row['id']; $row['count'] = (int) $row['count']; } diff --git a/lib/ClustersBackend/Manager.php b/lib/ClustersBackend/Manager.php index aec74324..73463959 100644 --- a/lib/ClustersBackend/Manager.php +++ b/lib/ClustersBackend/Manager.php @@ -27,7 +27,11 @@ use OCP\IRequest; class Manager { - /** Mapping of backend name to className */ + /** + * Mapping of backend name to className. + * + * @var array + */ public static array $backends = []; /** @@ -39,20 +43,20 @@ class Manager */ public static function get(string $name): Backend { - if (!\array_key_exists($name, self::$backends)) { - throw new \Exception("Invalid clusters backend '{$name}'"); + if ($className = self::$backends[$name] ?? null) { + /** @var Backend */ + return \OC::$server->get($className); } - return \OC::$server->get(self::$backends[$name]); + throw new \Exception("Invalid clusters backend '{$name}'"); } /** * Register a new backend. * - * @param mixed $name - * @param mixed $className + * @param class-string $className */ - public static function register($name, $className): void + public static function register(string $name, string $className): void { self::$backends[$name] = $className; } diff --git a/lib/ClustersBackend/PlacesBackend.php b/lib/ClustersBackend/PlacesBackend.php index bdef23dd..499e24ee 100644 --- a/lib/ClustersBackend/PlacesBackend.php +++ b/lib/ClustersBackend/PlacesBackend.php @@ -211,8 +211,8 @@ class PlacesBackend extends Backend $json = json_decode($otherNames, true); // Check if the language is available - if (\array_key_exists($lang, $json) && \is_string($json[$lang])) { - return $json[$lang]; + if ($translated = ($json[$lang] ?? null)) { + return (string) $translated; } } catch (\Error) { // Ignore errors, just use original name diff --git a/lib/Controller/DaysController.php b/lib/Controller/DaysController.php index 187c5966..15afe22c 100644 --- a/lib/Controller/DaysController.php +++ b/lib/Controller/DaysController.php @@ -187,11 +187,11 @@ class DaysController extends GenericApiController // Load details into map byref foreach ($details as $photo) { $dayId = (int) $photo['dayid']; - if (!\array_key_exists($dayId, $drefMap)) { + if (!($drefMap[$dayId] ?? null)) { continue; } - if (!\array_key_exists('detail', $drefMap[$dayId])) { + if (!($drefMap[$dayId]['detail'] ?? null)) { $drefMap[$dayId]['detail'] = []; } diff --git a/lib/Db/LivePhoto.php b/lib/Db/LivePhoto.php index 175096cc..74c1f93e 100644 --- a/lib/Db/LivePhoto.php +++ b/lib/Db/LivePhoto.php @@ -18,21 +18,20 @@ class LivePhoto */ public function isVideoPart(array $exif): bool { - return \array_key_exists('MIMEType', $exif) - && 'video/quicktime' === $exif['MIMEType'] - && \array_key_exists('ContentIdentifier', $exif); + return 'video/quicktime' === ($exif['MIMEType'] ?? null) + && !empty($exif['ContentIdentifier'] ?? null); } /** Get liveid from photo part */ public function getLivePhotoId(File $file, array $exif): string { // Apple JPEG (MOV has ContentIdentifier) - if (\array_key_exists('MediaGroupUUID', $exif)) { - return (string) $exif['MediaGroupUUID']; + if ($uuid = ($exif['MediaGroupUUID'] ?? null)) { + return (string) $uuid; } // Google MVIMG and Samsung JPEG - if (\array_key_exists('MicroVideoOffset', $exif) && ($videoLength = $exif['MicroVideoOffset']) > 0) { + if (($offset = ($exif['MicroVideoOffset'] ?? null)) && ($offset > 0)) { // As explained in the following issue, // https://github.com/pulsejet/memories/issues/468 // @@ -48,14 +47,14 @@ class LivePhoto // and subsequently extract the video file using the // EmbeddedVideoFile binary prop, but setting the offset // is faster for the same reason mentioned above. - $videoOffset = $file->getSize() - $videoLength; + $videoOffset = $file->getSize() - $offset; return "self__traileroffset={$videoOffset}"; } // Google JPEG and Samsung HEIC / JPEG (Apple?) - if (\array_key_exists('MotionPhoto', $exif)) { - if ('image/jpeg' === $exif['MIMEType']) { + if ($exif['MotionPhoto'] ?? null) { + if ('image/jpeg' === ($exif['MIMEType'] ?? null)) { // Google Motion Photo JPEG // We need to read the DirectoryItemLength key to get the length of the video @@ -90,7 +89,7 @@ class LivePhoto return 'self__trailer'; } - if ('image/heic' === $exif['MIMEType']) { + if ('image/heic' === ($exif['MIMEType'] ?? null)) { // Samsung HEIC -- no way to get this out yet (DirectoryItemLength is senseless) // The reason this is above the MotionPhotoVideo check is because extracting binary // EXIF fields on the fly is extremely expensive compared to trailer extraction. @@ -98,7 +97,7 @@ class LivePhoto } // Samsung HEIC (at least S21) - if (\array_key_exists('MotionPhotoVideo', $exif) && !empty($exif['MotionPhotoVideo'])) { + if (!empty($exif['MotionPhotoVideo'] ?? null)) { // It's a binary exif field, decode when the user requests it return 'self__exifbin=MotionPhotoVideo'; } diff --git a/lib/Db/TimelineQueryDays.php b/lib/Db/TimelineQueryDays.php index fc20dce7..2e0737df 100644 --- a/lib/Db/TimelineQueryDays.php +++ b/lib/Db/TimelineQueryDays.php @@ -276,13 +276,13 @@ trait TimelineQueryDays } // Favorite field, may not be present - if (\array_key_exists('categoryid', $row) && $row['categoryid']) { + if ($row['categoryid'] ?? null) { $row['isfavorite'] = 1; } unset($row['categoryid']); // Get hidden field if present - if (\array_key_exists('hidden', $row) && $row['hidden']) { + if ($row['hidden'] ?? null) { $row['ishidden'] = 1; } unset($row['hidden']); @@ -294,11 +294,10 @@ trait TimelineQueryDays unset($row['datetaken']); // Calculate the AUID if we can - if (\array_key_exists('epoch', $row) && \array_key_exists('size', $row) - && ($epoch = (int) $row['epoch']) && ($size = (int) $row['size'])) { + if (($epoch = $row['epoch'] ?? null) && ($size = $row['size'] ?? null)) { // compute AUID and discard size // epoch is used for ordering, so we keep it - $row['auid'] = Exif::getAUID($epoch, $size); + $row['auid'] = Exif::getAUID((int) $epoch, (int) $size); unset($row['size']); } @@ -337,8 +336,8 @@ trait TimelineQueryDays private function dayIdToMonthId(int $dayId): int { static $memoize = []; - if (\array_key_exists($dayId, $memoize)) { - return $memoize[$dayId]; + if ($cache = $memoize[$dayId] ?? null) { + return $cache; } return $memoize[$dayId] = strtotime(date('Ym', $dayId * 86400).'01') / 86400; diff --git a/lib/Db/TimelineQueryMap.php b/lib/Db/TimelineQueryMap.php index 190264f5..3b0c3320 100644 --- a/lib/Db/TimelineQueryMap.php +++ b/lib/Db/TimelineQueryMap.php @@ -64,22 +64,14 @@ trait TimelineQueryMap $res = $this->executeQueryWithCTEs($query)->fetchAll(); // Post-process results - $clusters = []; - foreach ($res as &$cluster) { - $c = [ - 'center' => [ - (float) $cluster['lat'], - (float) $cluster['lon'], - ], - 'count' => (float) $cluster['count'], - ]; - if (\array_key_exists('id', $cluster)) { - $c['id'] = (int) $cluster['id']; - } - $clusters[] = $c; - } - - return $clusters; + return array_map(static fn ($row) => [ + 'id' => (int) $row['id'], + 'center' => [ + (float) $row['lat'], + (float) $row['lon'], + ], + 'count' => (float) $row['count'], + ], $res); } /** diff --git a/lib/Db/TimelineWrite.php b/lib/Db/TimelineWrite.php index 5647d0ef..68004b1e 100644 --- a/lib/Db/TimelineWrite.php +++ b/lib/Db/TimelineWrite.php @@ -137,8 +137,7 @@ class TimelineWrite // Get BUID from ImageUniqueId if not present $buid = $prevRow ? $prevRow['buid'] : ''; if (empty($buid)) { - $imageUniqueId = \array_key_exists('ImageUniqueID', $exif) ? $exif['ImageUniqueID'] : null; - $buid = Exif::getBUID($file->getName(), $imageUniqueId, (int) $file->getSize()); + $buid = Exif::getBUID($file->getName(), $exif['ImageUniqueID'] ?? null, (int) $file->getSize()); } // Get exif json diff --git a/lib/Exif.php b/lib/Exif.php index fa4a5438..1011a061 100644 --- a/lib/Exif.php +++ b/lib/Exif.php @@ -161,9 +161,9 @@ class Exif // Get timezone from exif try { $tzStr = $exif['OffsetTimeOriginal'] - ?: $exif['OffsetTime'] - ?: $exif['LocationTZID'] - ?: throw new \Exception(); + ?? $exif['OffsetTime'] + ?? $exif['LocationTZID'] + ?? throw new \Exception(); $exifTz = new \DateTimeZone((string) $tzStr); } catch (\Exception) { $exifTz = null;