diff --git a/lib/AppInfo/Application.php b/lib/AppInfo/Application.php index da2e6f211..99610728f 100644 --- a/lib/AppInfo/Application.php +++ b/lib/AppInfo/Application.php @@ -25,7 +25,7 @@ use OCP\Share\Events\ShareCreatedEvent; use OCP\Share\Events\ShareDeletedEvent; -class Application extends App implements IBootstrap { +final class Application extends App implements IBootstrap { public const APP_ID = 'recognize'; public function __construct() { diff --git a/lib/BackgroundJobs/ClassifierJob.php b/lib/BackgroundJobs/ClassifierJob.php index d4d43a45e..52c7f5a93 100644 --- a/lib/BackgroundJobs/ClassifierJob.php +++ b/lib/BackgroundJobs/ClassifierJob.php @@ -106,7 +106,7 @@ protected function runClassifier(string $model, array $argument): void { abstract protected function getBatchSize(): int; /** - * @param array $files + * @param list $files * @return void * @throws \RuntimeException|\ErrorException */ diff --git a/lib/BackgroundJobs/ClassifyFacesJob.php b/lib/BackgroundJobs/ClassifyFacesJob.php index 6932062a8..2695dc2f5 100644 --- a/lib/BackgroundJobs/ClassifyFacesJob.php +++ b/lib/BackgroundJobs/ClassifyFacesJob.php @@ -15,7 +15,7 @@ use OCP\BackgroundJob\IJobList; use OCP\Files\Config\IUserMountCache; -class ClassifyFacesJob extends ClassifierJob { +final class ClassifyFacesJob extends ClassifierJob { public const MODEL_NAME = 'faces'; private SettingsService $settingsService; diff --git a/lib/BackgroundJobs/ClassifyImagenetJob.php b/lib/BackgroundJobs/ClassifyImagenetJob.php index 062fd1db9..fc250e713 100644 --- a/lib/BackgroundJobs/ClassifyImagenetJob.php +++ b/lib/BackgroundJobs/ClassifyImagenetJob.php @@ -15,7 +15,7 @@ use OCP\BackgroundJob\IJobList; use OCP\Files\Config\IUserMountCache; -class ClassifyImagenetJob extends ClassifierJob { +final class ClassifyImagenetJob extends ClassifierJob { public const MODEL_NAME = 'imagenet'; private SettingsService $settingsService; diff --git a/lib/BackgroundJobs/ClassifyLandmarksJob.php b/lib/BackgroundJobs/ClassifyLandmarksJob.php index accb41a7b..68c53e743 100644 --- a/lib/BackgroundJobs/ClassifyLandmarksJob.php +++ b/lib/BackgroundJobs/ClassifyLandmarksJob.php @@ -15,7 +15,7 @@ use OCP\BackgroundJob\IJobList; use OCP\Files\Config\IUserMountCache; -class ClassifyLandmarksJob extends ClassifierJob { +final class ClassifyLandmarksJob extends ClassifierJob { public const MODEL_NAME = 'landmarks'; private SettingsService $settingsService; diff --git a/lib/BackgroundJobs/ClassifyMovinetJob.php b/lib/BackgroundJobs/ClassifyMovinetJob.php index cc1f13f79..e9be3e120 100644 --- a/lib/BackgroundJobs/ClassifyMovinetJob.php +++ b/lib/BackgroundJobs/ClassifyMovinetJob.php @@ -15,7 +15,7 @@ use OCP\BackgroundJob\IJobList; use OCP\Files\Config\IUserMountCache; -class ClassifyMovinetJob extends ClassifierJob { +final class ClassifyMovinetJob extends ClassifierJob { public const MODEL_NAME = 'movinet'; private SettingsService $settingsService; diff --git a/lib/BackgroundJobs/ClassifyMusicnnJob.php b/lib/BackgroundJobs/ClassifyMusicnnJob.php index 73073047a..9767ab7b0 100644 --- a/lib/BackgroundJobs/ClassifyMusicnnJob.php +++ b/lib/BackgroundJobs/ClassifyMusicnnJob.php @@ -15,7 +15,7 @@ use OCP\BackgroundJob\IJobList; use OCP\Files\Config\IUserMountCache; -class ClassifyMusicnnJob extends ClassifierJob { +final class ClassifyMusicnnJob extends ClassifierJob { public const MODEL_NAME = 'musicnn'; private SettingsService $settingsService; diff --git a/lib/BackgroundJobs/ClusterFacesJob.php b/lib/BackgroundJobs/ClusterFacesJob.php index 5f486b3bb..ab81e4796 100644 --- a/lib/BackgroundJobs/ClusterFacesJob.php +++ b/lib/BackgroundJobs/ClusterFacesJob.php @@ -16,7 +16,7 @@ use OCP\DB\Exception; use Psr\Log\LoggerInterface; -class ClusterFacesJob extends QueuedJob { +final class ClusterFacesJob extends QueuedJob { private FaceClusterAnalyzer $clusterAnalyzer; private IJobList $jobList; private LoggerInterface $logger; diff --git a/lib/BackgroundJobs/MaintenanceJob.php b/lib/BackgroundJobs/MaintenanceJob.php index 52bfd3590..bc1729ef7 100644 --- a/lib/BackgroundJobs/MaintenanceJob.php +++ b/lib/BackgroundJobs/MaintenanceJob.php @@ -14,7 +14,7 @@ use OCP\DB\Exception; use Psr\Log\LoggerInterface; -class MaintenanceJob extends TimedJob { +final class MaintenanceJob extends TimedJob { public function __construct( ITimeFactory $time, diff --git a/lib/BackgroundJobs/SchedulerJob.php b/lib/BackgroundJobs/SchedulerJob.php index e2f0928e6..8297c3d85 100644 --- a/lib/BackgroundJobs/SchedulerJob.php +++ b/lib/BackgroundJobs/SchedulerJob.php @@ -19,7 +19,7 @@ use OCP\BackgroundJob\QueuedJob; use Psr\Log\LoggerInterface; -class SchedulerJob extends QueuedJob { +final class SchedulerJob extends QueuedJob { public const INTERVAL = 30 * 60; // 30 minutes public const ALLOWED_MOUNT_TYPES = [ 'OC\Files\Mount\LocalHomeMountProvider', diff --git a/lib/BackgroundJobs/StorageCrawlJob.php b/lib/BackgroundJobs/StorageCrawlJob.php index 5d68f3258..0e9a7bbcb 100644 --- a/lib/BackgroundJobs/StorageCrawlJob.php +++ b/lib/BackgroundJobs/StorageCrawlJob.php @@ -23,7 +23,7 @@ use OCP\DB\Exception; use Psr\Log\LoggerInterface; -class StorageCrawlJob extends QueuedJob { +final class StorageCrawlJob extends QueuedJob { public const BATCH_SIZE = 2000; private LoggerInterface $logger; private QueueService $queue; diff --git a/lib/Classifiers/Audio/MusicnnClassifier.php b/lib/Classifiers/Audio/MusicnnClassifier.php index d48cce1cd..72f655e4f 100644 --- a/lib/Classifiers/Audio/MusicnnClassifier.php +++ b/lib/Classifiers/Audio/MusicnnClassifier.php @@ -16,7 +16,7 @@ use OCP\IPreview; use OCP\ITempManager; -class MusicnnClassifier extends Classifier { +final class MusicnnClassifier extends Classifier { public const AUDIO_TIMEOUT = 40; // seconds public const AUDIO_PUREJS_TIMEOUT = 420; // seconds public const MODEL_NAME = 'musicnn'; diff --git a/lib/Classifiers/Classifier.php b/lib/Classifiers/Classifier.php index 823bd61c7..a4b475472 100644 --- a/lib/Classifiers/Classifier.php +++ b/lib/Classifiers/Classifier.php @@ -102,16 +102,19 @@ public function classifyFiles(string $model, array $queueFiles, int $timeout): \ $path = $this->getConvertedFilePath($files[0]); if (in_array($model, [ImagenetClassifier::MODEL_NAME, LandmarksClassifier::MODEL_NAME, ClusteringFaceClassifier::MODEL_NAME], true)) { // Check file data size - $filesizeMb = filesize($path) / (1024 * 1024); - if ($filesizeMb > 8) { - $this->logger->debug('File is too large for classifier: ' . $files[0]->getPath()); - try { - $this->logger->debug('removing ' . $queueFile->getFileId() . ' from ' . $model . ' queue'); - $this->queue->removeFromQueue($model, $queueFile); - } catch (Exception $e) { - $this->logger->warning($e->getMessage(), ['exception' => $e]); + $filesize = filesize($path); + if ($filesize !== false) { + $filesizeMb = $filesize / (1024 * 1024); + if ($filesizeMb > 8) { + $this->logger->debug('File is too large for classifier: ' . $files[0]->getPath()); + try { + $this->logger->debug('removing ' . $queueFile->getFileId() . ' from ' . $model . ' queue'); + $this->queue->removeFromQueue($model, $queueFile); + } catch (Exception $e) { + $this->logger->warning($e->getMessage(), ['exception' => $e]); + } + continue; } - continue; } // Check file dimensions $dimensions = @getimagesize($path); @@ -183,7 +186,7 @@ public function classifyFiles(string $model, array $queueFiles, int $timeout): \ $proc->start(); if ($cores !== '0') { - @exec('taskset -cp ' . implode(',', range(0, (int)$cores, 1)) . ' ' . $proc->getPid()); + @exec('taskset -cp ' . implode(',', range(0, (int)$cores, 1)) . ' ' . ((string)$proc->getPid())); } $i = 0; @@ -340,7 +343,14 @@ public function generatePreviewWithProvider(File $file): string { $imagetype = exif_imagetype($tmpname); if (in_array($imagetype, [IMAGETYPE_WEBP, IMAGETYPE_AVIF, false])) { // To troubleshoot if it is a webp or avif. - $previewImage = imagecreatefromstring(file_get_contents($tmpname)); + $imageString = file_get_contents($tmpname); + if ($imageString === false) { + throw new \OCA\Recognize\Exception\Exception('Could not load preview file from temp folder'); + } + $previewImage = imagecreatefromstring($imageString); + if ($previewImage === false) { + throw new \OCA\Recognize\Exception\Exception('Could not load preview file from temp folder'); + } $use_gd_quality = (int)\OCP\Server::get(IConfig::class)->getSystemValue('recognize.preview.quality', '100'); if (imagejpeg($previewImage, $tmpname, $use_gd_quality) === false) { imagedestroy($previewImage); @@ -358,18 +368,26 @@ public function generatePreviewWithProvider(File $file): string { * @throws \OCA\Recognize\Exception\Exception */ public function generatePreviewWithGD(string $path): string { - $image = imagecreatefromstring(file_get_contents($path)); + $imageContents = file_get_contents($path); + if (!$imageContents) { + throw new \OCA\Recognize\Exception\Exception('Could not load image for preview with gdlib'); + } + $image = imagecreatefromstring($imageContents); if (!$image) { throw new \OCA\Recognize\Exception\Exception('Could not load image for preview with gdlib'); } $width = imagesx($image); $height = imagesy($image); - $maxWidth = self::TEMP_FILE_DIMENSION; - $maxHeight = self::TEMP_FILE_DIMENSION; + if ($width === false || $height === false) { + throw new \OCA\Recognize\Exception\Exception('Could not get image dimensions for preview with gdlib'); + } + + $maxWidth = (float) self::TEMP_FILE_DIMENSION; + $maxHeight = (float) self::TEMP_FILE_DIMENSION; if ($width > $maxWidth || $height > $maxHeight) { - $aspectRatio = $width / $height; + $aspectRatio = (float) ($width / $height); if ($width > $height) { $newWidth = $maxWidth; $newHeight = $maxWidth / $aspectRatio; diff --git a/lib/Classifiers/Images/ClusteringFaceClassifier.php b/lib/Classifiers/Images/ClusteringFaceClassifier.php index 858396435..2dbd36cbf 100644 --- a/lib/Classifiers/Images/ClusteringFaceClassifier.php +++ b/lib/Classifiers/Images/ClusteringFaceClassifier.php @@ -26,7 +26,7 @@ use OCP\ITempManager; use OCP\Share\IManager; -class ClusteringFaceClassifier extends Classifier { +final class ClusteringFaceClassifier extends Classifier { public const IMAGE_TIMEOUT = 120; // seconds public const IMAGE_PUREJS_TIMEOUT = 360; // seconds public const MIN_FACE_RECOGNITION_SCORE = 0.9; diff --git a/lib/Classifiers/Images/ImagenetClassifier.php b/lib/Classifiers/Images/ImagenetClassifier.php index 498a8112d..38cc4135e 100644 --- a/lib/Classifiers/Images/ImagenetClassifier.php +++ b/lib/Classifiers/Images/ImagenetClassifier.php @@ -17,7 +17,7 @@ use OCP\IPreview; use OCP\ITempManager; -class ImagenetClassifier extends Classifier { +final class ImagenetClassifier extends Classifier { public const IMAGE_TIMEOUT = 480; // seconds public const IMAGE_PUREJS_TIMEOUT = 600; // seconds public const MODEL_NAME = 'imagenet'; diff --git a/lib/Classifiers/Images/LandmarksClassifier.php b/lib/Classifiers/Images/LandmarksClassifier.php index ded3d60c5..c9d2f2b7d 100644 --- a/lib/Classifiers/Images/LandmarksClassifier.php +++ b/lib/Classifiers/Images/LandmarksClassifier.php @@ -16,7 +16,7 @@ use OCP\IPreview; use OCP\ITempManager; -class LandmarksClassifier extends Classifier { +final class LandmarksClassifier extends Classifier { public const IMAGE_TIMEOUT = 480; // seconds public const IMAGE_PUREJS_TIMEOUT = 600; // seconds public const MODEL_NAME = 'landmarks'; diff --git a/lib/Classifiers/Video/MovinetClassifier.php b/lib/Classifiers/Video/MovinetClassifier.php index f4e864062..dbf8a6a9c 100644 --- a/lib/Classifiers/Video/MovinetClassifier.php +++ b/lib/Classifiers/Video/MovinetClassifier.php @@ -17,7 +17,7 @@ use OCP\IPreview; use OCP\ITempManager; -class MovinetClassifier extends Classifier { +final class MovinetClassifier extends Classifier { public const VIDEO_TIMEOUT = 480; // seconds public const MODEL_NAME = 'movinet'; diff --git a/lib/Clustering/DualTreeBall.php b/lib/Clustering/DualTreeBall.php index de8746058..351ea47e2 100644 --- a/lib/Clustering/DualTreeBall.php +++ b/lib/Clustering/DualTreeBall.php @@ -13,7 +13,7 @@ use \OCA\Recognize\Vendor\Rubix\ML\Kernels\Distance\Distance; use function \OCA\Recognize\Vendor\Rubix\ML\argmax; -class DualTreeBall extends Ball { +final class DualTreeBall extends Ball { protected float $longestDistanceInNode = INF; protected bool $fullyConnected = false; protected $setId; diff --git a/lib/Clustering/DualTreeClique.php b/lib/Clustering/DualTreeClique.php index 826fc8977..e37192565 100644 --- a/lib/Clustering/DualTreeClique.php +++ b/lib/Clustering/DualTreeClique.php @@ -13,7 +13,7 @@ use \OCA\Recognize\Vendor\Rubix\ML\Kernels\Distance\Distance; use function \OCA\Recognize\Vendor\Rubix\ML\argmax; -class DualTreeClique extends Clique { +final class DualTreeClique extends Clique { protected float $longestDistanceInNode = INF; protected bool $fullyConnected = false; /** @@ -63,8 +63,11 @@ public function propagateSetChanges(array &$labelToSetId) { } $labels = $this->dataset->labels(); - - $setId = $labelToSetId[array_pop($labels)]; + $lastLabel = array_pop($labels); + if (!isset($labelToSetId[$lastLabel])) { + return null; + } + $setId = $labelToSetId[$lastLabel]; foreach ($labels as $label) { if ($setId !== $labelToSetId[$label]) { diff --git a/lib/Clustering/HDBSCAN.php b/lib/Clustering/HDBSCAN.php index 71d65edc5..dcc285892 100644 --- a/lib/Clustering/HDBSCAN.php +++ b/lib/Clustering/HDBSCAN.php @@ -32,7 +32,7 @@ * * @author Sami Finnilä */ -class HDBSCAN { +final class HDBSCAN { /** * The minimum number of samples that can be considered to form a cluster. * Larger values will generate more stable clusters. diff --git a/lib/Clustering/MrdBallTree.php b/lib/Clustering/MrdBallTree.php index a9b0f1717..15b59598d 100644 --- a/lib/Clustering/MrdBallTree.php +++ b/lib/Clustering/MrdBallTree.php @@ -13,10 +13,16 @@ use \OCA\Recognize\Vendor\Rubix\ML\Graph\Trees\BallTree; use \OCA\Recognize\Vendor\Rubix\ML\Kernels\Distance\Distance; -class MrdBallTree extends BallTree { +final class MrdBallTree extends BallTree { private ?Labeled $dataset = null; private array $nativeInterpointCache = []; + /** + * @var array> + */ private array $coreDistances = []; + /** + * @var array> + */ private array $coreNeighborDistances = []; private int $sampleSize; private array $nodeDistances; @@ -122,7 +128,7 @@ public function getDataset(): Labeled { * @param \OCA\Recognize\Clustering\DualTreeBall|\OCA\Recognize\Clustering\DualTreeClique $referenceNode * @param int $k * @param float $maxRange - * @param array $bestDistances + * @param array $bestDistances * @return void */ private function updateNearestNeighbors($queryNode, $referenceNode, $k, $maxRange, &$bestDistances): void { @@ -157,7 +163,7 @@ private function updateNearestNeighbors($queryNode, $referenceNode, $k, $maxRang if (count($coreNeighborDistances) >= $k) { asort($coreNeighborDistances); $coreNeighborDistances = array_slice($coreNeighborDistances, 0, $k, true); - $bestDistance = min(end($coreNeighborDistances), $maxRange); + $bestDistance = (float) min(end($coreNeighborDistances), $maxRange); } } } @@ -173,9 +179,9 @@ private function updateNearestNeighbors($queryNode, $referenceNode, $k, $maxRang } if ($this->kernel instanceof SquaredDistance) { - $longestDistance = min($longestDistance, (2 * sqrt($queryNode->radius()) + sqrt($shortestDistance)) ** 2); + $longestDistance = min($longestDistance, (2.0 * sqrt($queryNode->radius()) + sqrt($shortestDistance)) ** 2.0); } else { - $longestDistance = min($longestDistance, 2 * $queryNode->radius() + $shortestDistance); + $longestDistance = (float) min($longestDistance, 2.0 * $queryNode->radius() + $shortestDistance); } $queryNode->setLongestDistance($longestDistance); } @@ -234,14 +240,14 @@ private function findNearestNeighbors($queryNode, $referenceNode, $k, $maxRange, // TODO: min($longestLeft, $longestRight) + 2 * ($queryNode->radius()) <--- Can be made tighter by using the shortest distance from child. if ($this->kernel instanceof SquaredDistance) { $longestDistance = max($longestLeft, $longestRight); - $longestLeft = (sqrt($longestLeft) + 2 * (sqrt($queryNode->radius()) - sqrt($queryLeft->radius()))) ** 2; - $longestRight = (sqrt($longestRight) + 2 * (sqrt($queryNode->radius()) - sqrt($queryRight->radius()))) ** 2; - $longestDistance = min($longestDistance, min($longestLeft, $longestRight), (sqrt(min($longestLeft, $longestRight)) + 2 * (sqrt($queryNode->radius()))) ** 2); + $longestLeft = (sqrt($longestLeft) + 2.0 * (sqrt($queryNode->radius()) - sqrt($queryLeft->radius()))) ** 2.0; + $longestRight = (sqrt($longestRight) + 2.0 * (sqrt($queryNode->radius()) - sqrt($queryRight->radius()))) ** 2.0; + $longestDistance = (float) min($longestDistance, min($longestLeft, $longestRight), (sqrt(min($longestLeft, $longestRight)) + 2.0 * (sqrt($queryNode->radius()))) ** 2.0); } else { $longestDistance = max($longestLeft, $longestRight); $longestLeft = $longestLeft + 2 * ($queryNode->radius() - $queryLeft->radius()); $longestRight = $longestRight + 2 * ($queryNode->radius() - $queryRight->radius()); - $longestDistance = min($longestDistance, min($longestLeft, $longestRight), min($longestLeft, $longestRight) + 2 * ($queryNode->radius())); + $longestDistance = (float) min($longestDistance, min($longestLeft, $longestRight), min($longestLeft, $longestRight) + 2.0 * ($queryNode->radius())); } $queryNode->setLongestDistance($longestDistance); @@ -573,7 +579,7 @@ public function cachedRange($sampleLabel, float $radius): array { $childRadius = sqrt($child->radius()); $minDistance = $distance - $childRadius; $minDistance = abs($minDistance) * $minDistance; - $maxDistance = ($distance + $childRadius) ** 2; + $maxDistance = ($distance + $childRadius) ** 2.0; } else { $childRadius = $child->radius(); $minDistance = $distance - $childRadius; diff --git a/lib/Clustering/MstClusterer.php b/lib/Clustering/MstClusterer.php index 0dde0057b..6558f3aeb 100644 --- a/lib/Clustering/MstClusterer.php +++ b/lib/Clustering/MstClusterer.php @@ -8,7 +8,7 @@ namespace OCA\Recognize\Clustering; // TODO: store vertex lambda length (relative to cluster lambda length) for all vertices for improved soft clustering (see https://hdbscan.readthedocs.io/en/latest/soft_clustering.html) -class MstClusterer { +final class MstClusterer { /** * @var array */ @@ -115,6 +115,9 @@ public function processCluster(): array { } $currentLongestEdgeKey = array_key_last($this->remainingEdges); + /** + * @var $currentLongestEdge array{vertexFrom: int, vertexTo:int, distance:float, finalLambda?: float} + */ $currentLongestEdge = array_pop($this->remainingEdges); $vertexConnectedFrom = $currentLongestEdge["vertexFrom"]; @@ -127,9 +130,9 @@ public function processCluster(): array { if ($edgeLength > $this->maxEdgeLength) { // Prevent formation of clusters with edges longer than the maximum edge length // This is done by forcing the weight of the current cluster to zero - $lastLambda = $currentLambda = 1 / $edgeLength; + $lastLambda = $currentLambda = 1.0 / $edgeLength; } elseif ($edgeLength > 0.0) { - $currentLambda = 1 / $edgeLength; + $currentLambda = 1.0 / $edgeLength; } $this->clusterWeight += ($currentLambda - $lastLambda) * $edgeCount; diff --git a/lib/Clustering/MstSolver.php b/lib/Clustering/MstSolver.php index 27564e649..3ab829df0 100644 --- a/lib/Clustering/MstSolver.php +++ b/lib/Clustering/MstSolver.php @@ -10,7 +10,7 @@ use \OCA\Recognize\Vendor\Rubix\ML\Datasets\Labeled; use \OCA\Recognize\Vendor\Rubix\ML\Kernels\Distance\Distance; -class MstSolver { +final class MstSolver { private MrdBallTree $tree; private Distance $kernel; private bool $useTrueMst; @@ -83,9 +83,9 @@ private function updateEdges($queryNode, $referenceNode, array &$newEdges, array // Update the bound of the query node if ($this->kernel instanceof SquaredDistance) { - $longestDistance = min($longestDistance, (2 * sqrt($queryNode->radius()) + sqrt($shortestDistance)) ** 2); + $longestDistance = min($longestDistance, (2.0 * sqrt($queryNode->radius()) + sqrt($shortestDistance)) ** 2.0); } else { - $longestDistance = min($longestDistance, 2 * $queryNode->radius() + $shortestDistance); + $longestDistance = min($longestDistance, 2.0 * $queryNode->radius() + $shortestDistance); } $queryNode->setLongestDistance($longestDistance); @@ -163,14 +163,14 @@ private function findSetNeighbors($queryNode, $referenceNode, array &$newEdges, // TODO: min($longestLeft, $longestRight) + 2 * ($queryNode->radius()) <--- Can be made tighter? if ($this->kernel instanceof SquaredDistance) { $longestDistance = max($longestLeft, $longestRight); - $longestLeft = (sqrt($longestLeft) + 2 * (sqrt($queryNode->radius()) - sqrt($queryLeft->radius()))) ** 2; - $longestRight = (sqrt($longestRight) + 2 * (sqrt($queryNode->radius()) - sqrt($queryRight->radius()))) ** 2; - $longestDistance = min($longestDistance, min($longestLeft, $longestRight), (sqrt(min($longestLeft, $longestRight)) + 2 * (sqrt($queryNode->radius()))) ** 2); + $longestLeft = (sqrt($longestLeft) + 2.0 * (sqrt($queryNode->radius()) - sqrt($queryLeft->radius()))) ** 2.0; + $longestRight = (sqrt($longestRight) + 2.0 * (sqrt($queryNode->radius()) - sqrt($queryRight->radius()))) ** 2.0; + $longestDistance = (float) min($longestDistance, min($longestLeft, $longestRight), (sqrt(min($longestLeft, $longestRight)) + 2.0 * (sqrt($queryNode->radius()))) ** 2.0); } else { $longestDistance = max($longestLeft, $longestRight); - $longestLeft = $longestLeft + 2 * ($queryNode->radius() - $queryLeft->radius()); - $longestRight = $longestRight + 2 * ($queryNode->radius() - $queryRight->radius()); - $longestDistance = min($longestDistance, min($longestLeft, $longestRight), min($longestLeft, $longestRight) + 2 * ($queryNode->radius())); + $longestLeft = $longestLeft + 2.0 * ($queryNode->radius() - $queryLeft->radius()); + $longestRight = $longestRight + 2.0 * ($queryNode->radius() - $queryRight->radius()); + $longestDistance = (float) min($longestDistance, min($longestLeft, $longestRight), min($longestLeft, $longestRight) + 2.0 * ($queryNode->radius())); } $queryNode->setLongestDistance($longestDistance); @@ -179,7 +179,7 @@ private function findSetNeighbors($queryNode, $referenceNode, array &$newEdges, } /** - * @return array + * @return list */ public function getMst(): array { $edges = []; diff --git a/lib/Clustering/SquaredDistance.php b/lib/Clustering/SquaredDistance.php index 7d3d0e2cc..b5709f675 100644 --- a/lib/Clustering/SquaredDistance.php +++ b/lib/Clustering/SquaredDistance.php @@ -19,7 +19,7 @@ * @package Rubix/ML * @author Sami Finnilä */ -class SquaredDistance implements Distance { +final class SquaredDistance implements Distance { /** * Return the data types that this kernel is compatible with. * diff --git a/lib/Command/Classify.php b/lib/Command/Classify.php index a6b47b326..e1bbafb13 100644 --- a/lib/Command/Classify.php +++ b/lib/Command/Classify.php @@ -27,7 +27,7 @@ use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; -class Classify extends Command { +final class Classify extends Command { /** @var array */ private array $classifiers = []; diff --git a/lib/Command/CleanupTags.php b/lib/Command/CleanupTags.php index e0b1973df..8686e2aa4 100644 --- a/lib/Command/CleanupTags.php +++ b/lib/Command/CleanupTags.php @@ -12,7 +12,7 @@ use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; -class CleanupTags extends Command { +final class CleanupTags extends Command { private TagManager $tagManager; public function __construct(TagManager $tagManager) { diff --git a/lib/Command/ClearBackgroundJobs.php b/lib/Command/ClearBackgroundJobs.php index f99ec4702..e00bd575c 100644 --- a/lib/Command/ClearBackgroundJobs.php +++ b/lib/Command/ClearBackgroundJobs.php @@ -21,7 +21,7 @@ use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; -class ClearBackgroundJobs extends Command { +final class ClearBackgroundJobs extends Command { private IJobList $jobList; private LoggerInterface $logger; diff --git a/lib/Command/ClusterFaces.php b/lib/Command/ClusterFaces.php index 2c8c172f5..feaca44da 100644 --- a/lib/Command/ClusterFaces.php +++ b/lib/Command/ClusterFaces.php @@ -17,7 +17,7 @@ use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; -class ClusterFaces extends Command { +final class ClusterFaces extends Command { private Logger $logger; private FaceDetectionMapper $detectionMapper; diff --git a/lib/Command/DownloadModels.php b/lib/Command/DownloadModels.php index f5914657b..7dcafabe5 100644 --- a/lib/Command/DownloadModels.php +++ b/lib/Command/DownloadModels.php @@ -12,7 +12,7 @@ use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; -class DownloadModels extends Command { +final class DownloadModels extends Command { private DownloadModelsService $downloader; diff --git a/lib/Command/Recrawl.php b/lib/Command/Recrawl.php index 72151e564..01990d888 100644 --- a/lib/Command/Recrawl.php +++ b/lib/Command/Recrawl.php @@ -22,7 +22,7 @@ use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; -class Recrawl extends Command { +final class Recrawl extends Command { private IJobList $jobList; private LoggerInterface $logger; private QueueService $queue; diff --git a/lib/Command/RemoveLegacyTags.php b/lib/Command/RemoveLegacyTags.php index edd42b16f..73fd2dffd 100644 --- a/lib/Command/RemoveLegacyTags.php +++ b/lib/Command/RemoveLegacyTags.php @@ -12,7 +12,7 @@ use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; -class RemoveLegacyTags extends Command { +final class RemoveLegacyTags extends Command { private TagManager $tagManager; public function __construct(TagManager $tagManager) { diff --git a/lib/Command/ResetFaceClusters.php b/lib/Command/ResetFaceClusters.php index 30a632125..c85432c96 100644 --- a/lib/Command/ResetFaceClusters.php +++ b/lib/Command/ResetFaceClusters.php @@ -13,7 +13,7 @@ use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; -class ResetFaceClusters extends Command { +final class ResetFaceClusters extends Command { private FaceDetectionMapper $faceDetectionMapper; private FaceClusterMapper $clusterMapper; diff --git a/lib/Command/ResetFaces.php b/lib/Command/ResetFaces.php index c96fc2113..188c540e4 100644 --- a/lib/Command/ResetFaces.php +++ b/lib/Command/ResetFaces.php @@ -13,7 +13,7 @@ use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; -class ResetFaces extends Command { +final class ResetFaces extends Command { private FaceDetectionMapper $faceDetectionMapper; private FaceClusterMapper $clusterMapper; diff --git a/lib/Command/ResetTags.php b/lib/Command/ResetTags.php index 981851afa..7e8b4dc90 100644 --- a/lib/Command/ResetTags.php +++ b/lib/Command/ResetTags.php @@ -12,7 +12,7 @@ use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; -class ResetTags extends Command { +final class ResetTags extends Command { private TagManager $tagManager; public function __construct(TagManager $tagManager) { diff --git a/lib/Constants.php b/lib/Constants.php index 2ae082739..934adde37 100644 --- a/lib/Constants.php +++ b/lib/Constants.php @@ -7,7 +7,7 @@ declare(strict_types=1); namespace OCA\Recognize; -class Constants { +final class Constants { public const IMAGE_FORMATS = ['image/jpeg', 'image/png', 'image/bmp', 'image/heic', 'image/heif', 'image/tiff', 'image/webp']; public const AUDIO_FORMATS = ['audio/mpeg', 'audio/mp4', 'audio/ogg', 'audio/vnd.wav', 'audio/flac']; public const VIDEO_FORMATS = ['image/gif', 'video/mp4', 'video/MP2T', 'video/x-msvideo', 'video/x-ms-wmv', 'video/quicktime', 'video/ogg', 'video/mpeg', 'video/webm', 'video/x-matroska']; diff --git a/lib/Controller/AdminController.php b/lib/Controller/AdminController.php index 6c99eb027..54b08e9d2 100644 --- a/lib/Controller/AdminController.php +++ b/lib/Controller/AdminController.php @@ -33,7 +33,7 @@ use OCP\IBinaryFinder; use OCP\IRequest; -class AdminController extends Controller { +final class AdminController extends Controller { private TagManager $tagManager; private IJobList $jobList; private SettingsService $settingsService; diff --git a/lib/Dav/Faces/FaceRoot.php b/lib/Dav/Faces/FaceRoot.php index 187ef3800..b78d1ff51 100644 --- a/lib/Dav/Faces/FaceRoot.php +++ b/lib/Dav/Faces/FaceRoot.php @@ -22,7 +22,7 @@ use Sabre\DAV\IMoveTarget; use Sabre\DAV\INode; -class FaceRoot implements ICollection, IMoveTarget { +final class FaceRoot implements ICollection, IMoveTarget { private FaceClusterMapper $clusterMapper; private FaceCluster $cluster; private IUser $user; diff --git a/lib/Dav/Faces/FacesHome.php b/lib/Dav/Faces/FacesHome.php index 62c4896e3..576a423f2 100644 --- a/lib/Dav/Faces/FacesHome.php +++ b/lib/Dav/Faces/FacesHome.php @@ -19,7 +19,7 @@ use Sabre\DAV\Exception\NotFound; use Sabre\DAV\ICollection; -class FacesHome implements ICollection { +final class FacesHome implements ICollection { private FaceClusterMapper $faceClusterMapper; private IUser $user; private FaceDetectionMapper $faceDetectionMapper; diff --git a/lib/Dav/Faces/PropFindPlugin.php b/lib/Dav/Faces/PropFindPlugin.php index 568199e2a..14a0fa4bf 100644 --- a/lib/Dav/Faces/PropFindPlugin.php +++ b/lib/Dav/Faces/PropFindPlugin.php @@ -19,7 +19,7 @@ use Sabre\DAV\Server; use Sabre\DAV\ServerPlugin; -class PropFindPlugin extends ServerPlugin { +final class PropFindPlugin extends ServerPlugin { public const FACE_DETECTIONS_PROPERTYNAME = '{http://nextcloud.org/ns}face-detections'; public const FILE_NAME_PROPERTYNAME = '{http://nextcloud.org/ns}file-name'; public const REALPATH_PROPERTYNAME = '{http://nextcloud.org/ns}realpath'; diff --git a/lib/Dav/Faces/UnassignedFacePhoto.php b/lib/Dav/Faces/UnassignedFacePhoto.php index 67570f149..346d0bb95 100644 --- a/lib/Dav/Faces/UnassignedFacePhoto.php +++ b/lib/Dav/Faces/UnassignedFacePhoto.php @@ -14,7 +14,7 @@ use OCP\ITagManager; use Sabre\DAV\Exception\Forbidden; -class UnassignedFacePhoto extends FacePhoto { +final class UnassignedFacePhoto extends FacePhoto { public function __construct(FaceDetectionMapper $detectionMapper, FaceDetection $faceDetection, Folder $userFolder, ITagManager $tagManager, IPreview $preview) { parent::__construct($detectionMapper, $faceDetection, $userFolder, $tagManager, $preview); diff --git a/lib/Dav/Faces/UnassignedFacesHome.php b/lib/Dav/Faces/UnassignedFacesHome.php index 94b8e390a..3193843e3 100644 --- a/lib/Dav/Faces/UnassignedFacesHome.php +++ b/lib/Dav/Faces/UnassignedFacesHome.php @@ -18,7 +18,7 @@ use Sabre\DAV\Exception\NotFound; use Sabre\DAV\ICollection; -class UnassignedFacesHome implements ICollection { +final class UnassignedFacesHome implements ICollection { private IUser $user; private FaceDetectionMapper $faceDetectionMapper; private IRootFolder $rootFolder; diff --git a/lib/Dav/RecognizeHome.php b/lib/Dav/RecognizeHome.php index 82e96f76e..6b288ee05 100644 --- a/lib/Dav/RecognizeHome.php +++ b/lib/Dav/RecognizeHome.php @@ -19,7 +19,7 @@ use Sabre\DAV\Exception\NotFound; use Sabre\DAV\ICollection; -class RecognizeHome implements ICollection { +final class RecognizeHome implements ICollection { private array $principalInfo; private FaceClusterMapper $faceClusterMapper; private IUser $user; diff --git a/lib/Dav/RootCollection.php b/lib/Dav/RootCollection.php index 85bf9bc93..e88a7db3a 100644 --- a/lib/Dav/RootCollection.php +++ b/lib/Dav/RootCollection.php @@ -17,7 +17,7 @@ use OCP\IUserSession; use Sabre\DAV\Exception\Forbidden; -class RootCollection extends AbstractPrincipalCollection { +final class RootCollection extends AbstractPrincipalCollection { private IUserSession $userSession; private FaceClusterMapper $faceClusterMapper; private FaceDetectionMapper $faceDetectionMapper; diff --git a/lib/Db/FaceCluster.php b/lib/Db/FaceCluster.php index 271650d5e..d14e98c5f 100644 --- a/lib/Db/FaceCluster.php +++ b/lib/Db/FaceCluster.php @@ -18,7 +18,7 @@ * @method string getUserId() * @method setUserId(string $userId) */ -class FaceCluster extends Entity { +final class FaceCluster extends Entity { protected $title; protected $userId; diff --git a/lib/Db/FaceClusterMapper.php b/lib/Db/FaceClusterMapper.php index 99692c8f4..b71be4d06 100644 --- a/lib/Db/FaceClusterMapper.php +++ b/lib/Db/FaceClusterMapper.php @@ -15,7 +15,7 @@ /** * @psalm-extends QBMapper */ -class FaceClusterMapper extends QBMapper { +final class FaceClusterMapper extends QBMapper { public function __construct(IDBConnection $db) { parent::__construct($db, 'recognize_face_clusters', FaceCluster::class); $this->db = $db; diff --git a/lib/Db/FaceDetectionMapper.php b/lib/Db/FaceDetectionMapper.php index 9f7cbb38a..386f6d816 100644 --- a/lib/Db/FaceDetectionMapper.php +++ b/lib/Db/FaceDetectionMapper.php @@ -18,7 +18,7 @@ /** * @psalm-extends QBMapper */ -class FaceDetectionMapper extends QBMapper { +final class FaceDetectionMapper extends QBMapper { private IConfig $config; public function __construct(IDBConnection $db, IConfig $config) { diff --git a/lib/Db/FaceDetectionWithTitle.php b/lib/Db/FaceDetectionWithTitle.php index fe4336291..b29882cde 100644 --- a/lib/Db/FaceDetectionWithTitle.php +++ b/lib/Db/FaceDetectionWithTitle.php @@ -12,7 +12,7 @@ * @method setTitle(string $title) * @method static self fromRow(array $array) */ -class FaceDetectionWithTitle extends FaceDetection { +final class FaceDetectionWithTitle extends FaceDetection { protected $title; public static $columns = ['id', 'user_id', 'file_id', 'x', 'y', 'height', 'width', 'vector', 'cluster_id', 'title']; diff --git a/lib/Db/QueueFile.php b/lib/Db/QueueFile.php index abc0adeb5..a0cc6713c 100644 --- a/lib/Db/QueueFile.php +++ b/lib/Db/QueueFile.php @@ -22,7 +22,7 @@ * @method setUpdate(boolean $update) * @method bool getUpdate() */ -class QueueFile extends Entity { +final class QueueFile extends Entity { public $id; protected $fileId; protected $storageId; diff --git a/lib/Db/QueueMapper.php b/lib/Db/QueueMapper.php index c56479f55..794f29aec 100644 --- a/lib/Db/QueueMapper.php +++ b/lib/Db/QueueMapper.php @@ -22,7 +22,7 @@ /** * @psalm-extends QBMapper */ -class QueueMapper extends QBMapper { +final class QueueMapper extends QBMapper { public const MODELS = [ ImagenetClassifier::MODEL_NAME, ClusteringFaceClassifier::MODEL_NAME, diff --git a/lib/Exception/Exception.php b/lib/Exception/Exception.php index 4cee5ac34..73800c24e 100644 --- a/lib/Exception/Exception.php +++ b/lib/Exception/Exception.php @@ -7,5 +7,5 @@ declare(strict_types=1); namespace OCA\Recognize\Exception; -class Exception extends \Exception { +final class Exception extends \Exception { } diff --git a/lib/Helper/TAR.php b/lib/Helper/TAR.php index 41e09af5b..5b069b16e 100644 --- a/lib/Helper/TAR.php +++ b/lib/Helper/TAR.php @@ -35,7 +35,7 @@ use Icewind\Streams\CallbackWrapper; -class TAR extends Archive { +final class TAR extends Archive { public const PLAIN = 0; public const GZIP = 1; public const BZIP = 2; diff --git a/lib/Hooks/FileListener.php b/lib/Hooks/FileListener.php index 3bd736d9b..44a2545ba 100644 --- a/lib/Hooks/FileListener.php +++ b/lib/Hooks/FileListener.php @@ -46,7 +46,7 @@ /** * @template-implements IEventListener */ -class FileListener implements IEventListener { +final class FileListener implements IEventListener { private ?bool $movingFromIgnoredTerritory; private ?array $movingDirFromIgnoredTerritory; /** @var list */ diff --git a/lib/Migration/InstallDeps.php b/lib/Migration/InstallDeps.php index 7e477b239..d51a432a0 100644 --- a/lib/Migration/InstallDeps.php +++ b/lib/Migration/InstallDeps.php @@ -33,7 +33,7 @@ use OCP\Migration\IRepairStep; use Psr\Log\LoggerInterface; -class InstallDeps implements IRepairStep { +final class InstallDeps implements IRepairStep { public const NODE_VERSION = 'v20.9.0'; public const NODE_SERVER_OFFICIAL = 'https://nodejs.org/dist/'; public const NODE_SERVER_UNOFFICIAL = 'https://unofficial-builds.nodejs.org/download/release/'; diff --git a/lib/Migration/Version002002000Date20220614094721.php b/lib/Migration/Version002002000Date20220614094721.php index 746e5df1b..17879ff48 100644 --- a/lib/Migration/Version002002000Date20220614094721.php +++ b/lib/Migration/Version002002000Date20220614094721.php @@ -16,7 +16,7 @@ /** * Auto-generated migration step: Please modify to your needs! */ -class Version002002000Date20220614094721 extends SimpleMigrationStep { +final class Version002002000Date20220614094721 extends SimpleMigrationStep { /** * @param IOutput $output * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` diff --git a/lib/Migration/Version002003000Date20220713094721.php b/lib/Migration/Version002003000Date20220713094721.php index 499df7b36..72c4ec920 100644 --- a/lib/Migration/Version002003000Date20220713094721.php +++ b/lib/Migration/Version002003000Date20220713094721.php @@ -15,7 +15,7 @@ /** * Auto-generated migration step: Please modify to your needs! */ -class Version002003000Date20220713094721 extends SimpleMigrationStep { +final class Version002003000Date20220713094721 extends SimpleMigrationStep { /** * @param IOutput $output * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` diff --git a/lib/Migration/Version003001000Date20221017094721.php b/lib/Migration/Version003001000Date20221017094721.php index e2270438f..9d2569586 100644 --- a/lib/Migration/Version003001000Date20221017094721.php +++ b/lib/Migration/Version003001000Date20221017094721.php @@ -16,7 +16,7 @@ /** * Auto-generated migration step: Please modify to your needs! */ -class Version003001000Date20221017094721 extends SimpleMigrationStep { +final class Version003001000Date20221017094721 extends SimpleMigrationStep { /** * @param IOutput $output * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` diff --git a/lib/Migration/Version003004000Date20230107094721.php b/lib/Migration/Version003004000Date20230107094721.php index 3b8408c48..242640d45 100644 --- a/lib/Migration/Version003004000Date20230107094721.php +++ b/lib/Migration/Version003004000Date20230107094721.php @@ -12,7 +12,7 @@ use OCP\Migration\IOutput; use OCP\Migration\SimpleMigrationStep; -class Version003004000Date20230107094721 extends SimpleMigrationStep { +final class Version003004000Date20230107094721 extends SimpleMigrationStep { /** * @param IOutput $output * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` diff --git a/lib/Service/DownloadModelsService.php b/lib/Service/DownloadModelsService.php index fa2a7637a..64e422382 100644 --- a/lib/Service/DownloadModelsService.php +++ b/lib/Service/DownloadModelsService.php @@ -13,7 +13,7 @@ use RecursiveDirectoryIterator; use RecursiveIteratorIterator; -class DownloadModelsService { +final class DownloadModelsService { private IClientService $clientService; private bool $isCLI; diff --git a/lib/Service/FaceClusterAnalyzer.php b/lib/Service/FaceClusterAnalyzer.php index 17643d2d6..03e12ef1f 100644 --- a/lib/Service/FaceClusterAnalyzer.php +++ b/lib/Service/FaceClusterAnalyzer.php @@ -15,7 +15,7 @@ use OCA\Recognize\Db\FaceDetection; use OCA\Recognize\Db\FaceDetectionMapper; -class FaceClusterAnalyzer { +final class FaceClusterAnalyzer { public const MIN_DATASET_SIZE = 120; public const MIN_DETECTION_SIZE = 0.03; public const MIN_CLUSTER_SEPARATION = 0.35; @@ -191,7 +191,7 @@ public static function calculateCentroidOfDetections(array $detections): array { /** @var list $sum */ $sum = []; for ($i = 0; $i < self::DIMENSIONS; $i++) { - $sum[] = 0; + $sum[] = 0.0; } if (count($detections) === 0) { @@ -205,7 +205,7 @@ public static function calculateCentroidOfDetections(array $detections): array { } $centroid = array_map(static function ($el) use ($detections) { - return $el / count($detections); + return $el / (float) count($detections); }, $sum); return $centroid; @@ -252,7 +252,7 @@ private static function distance(array $v1, array $v2): float { * @return int */ private function getMinClusterSize(int $batchSize) : int { - return (int)round(max(2, min(5, $batchSize ** (1 / 4.7)))); + return (int)round(max(2.0, min(5.0, $batchSize ** (1.0 / 4.7)))); } /** @@ -261,7 +261,7 @@ private function getMinClusterSize(int $batchSize) : int { * @return int */ private function getMinSampleSize(int $batchSize) : int { - return (int)round(max(2, min(4, $batchSize ** (1 / 5.6)))); + return (int)round(max(2, min(4, $batchSize ** (1.0 / 5.6)))); } /** @@ -271,10 +271,10 @@ private function getMinSampleSize(int $batchSize) : int { * @return int */ private function getReferenceSampleSize(int $numberClusters) : int { - return (int)round(75 * 2 ** (-0.007 * $numberClusters) + 5); + return (int)round(75.0 * 2.0 ** (-0.007 * $numberClusters) + 5.0); } private function getRejectSampleSize(int $batchSize): int { - return (int) min(($batchSize / 4), 12 * $batchSize ** (0.55)); // I love maths. Slap me. + return (int) min(($batchSize / 4.0), 12.0 * $batchSize ** (0.55)); // I love maths. Slap me. } } diff --git a/lib/Service/IgnoreService.php b/lib/Service/IgnoreService.php index 38b8c407e..022d09177 100644 --- a/lib/Service/IgnoreService.php +++ b/lib/Service/IgnoreService.php @@ -14,7 +14,7 @@ use OCP\ICacheFactory; use OCP\IDBConnection; -class IgnoreService { +final class IgnoreService { private array $inMemoryCache = []; private ICache $localCache; diff --git a/lib/Service/Logger.php b/lib/Service/Logger.php index d54465e73..9f50011a3 100644 --- a/lib/Service/Logger.php +++ b/lib/Service/Logger.php @@ -10,7 +10,7 @@ use Psr\Log\LoggerInterface; use Symfony\Component\Console\Output\OutputInterface; -class Logger implements LoggerInterface { +final class Logger implements LoggerInterface { private LoggerInterface $logger; private ?OutputInterface $cliOutput = null; @@ -31,7 +31,7 @@ public function setCliOutput(OutputInterface $out): Logger { /** * @inheritDoc */ - public function emergency($message, array $context = array()): void { + public function emergency(string|\Stringable $message, array $context = array()): void { if (isset($this->cliOutput)) { $this->cliOutput->writeln((string)$message); } @@ -41,7 +41,7 @@ public function emergency($message, array $context = array()): void { /** * @inheritDoc */ - public function alert($message, array $context = array()): void { + public function alert(string|\Stringable$message, array $context = array()): void { if (isset($this->cliOutput)) { $this->cliOutput->writeln((string)$message); } @@ -51,7 +51,7 @@ public function alert($message, array $context = array()): void { /** * @inheritDoc */ - public function critical($message, array $context = array()): void { + public function critical(string|\Stringable $message, array $context = array()): void { if (isset($this->cliOutput)) { $this->cliOutput->writeln((string)$message); } @@ -61,7 +61,7 @@ public function critical($message, array $context = array()): void { /** * @inheritDoc */ - public function error($message, array $context = array()): void { + public function error(string|\Stringable $message, array $context = array()): void { if (isset($this->cliOutput)) { $this->cliOutput->writeln((string)$message); } @@ -71,7 +71,7 @@ public function error($message, array $context = array()): void { /** * @inheritDoc */ - public function warning($message, array $context = array()): void { + public function warning(string|\Stringable $message, array $context = array()): void { if (isset($this->cliOutput)) { $this->cliOutput->writeln((string)$message); } @@ -81,7 +81,7 @@ public function warning($message, array $context = array()): void { /** * @inheritDoc */ - public function notice($message, array $context = array()): void { + public function notice(string|\Stringable $message, array $context = array()): void { if (isset($this->cliOutput)) { $this->cliOutput->writeln((string)$message); } @@ -91,7 +91,7 @@ public function notice($message, array $context = array()): void { /** * @inheritDoc */ - public function info($message, array $context = array()): void { + public function info(string|\Stringable $message, array $context = array()): void { if (isset($this->cliOutput) && !$this->cliOutput->isQuiet()) { $this->cliOutput->writeln((string)$message); } @@ -101,7 +101,7 @@ public function info($message, array $context = array()): void { /** * @inheritDoc */ - public function debug($message, array $context = array()): void { + public function debug(string|\Stringable $message, array $context = array()): void { if (isset($this->cliOutput) && !$this->cliOutput->isQuiet()) { $this->cliOutput->writeln((string)$message); } @@ -111,7 +111,7 @@ public function debug($message, array $context = array()): void { /** * @inheritDoc */ - public function log($level, $message, array $context = array()): void { + public function log($level, string|\Stringable $message, array $context = array()): void { if (isset($this->cliOutput)) { $this->cliOutput->writeln((string)$message); } diff --git a/lib/Service/QueueService.php b/lib/Service/QueueService.php index 9f94dc554..e62750d8f 100644 --- a/lib/Service/QueueService.php +++ b/lib/Service/QueueService.php @@ -22,7 +22,7 @@ use OCP\AppFramework\Services\IAppConfig; use OCP\BackgroundJob\IJobList; -class QueueService { +final class QueueService { /** * @const array JOB_CLASSES */ diff --git a/lib/Service/SettingsService.php b/lib/Service/SettingsService.php index b2f30c7d0..3f1a296e4 100644 --- a/lib/Service/SettingsService.php +++ b/lib/Service/SettingsService.php @@ -19,7 +19,7 @@ use OCP\AppFramework\Services\IAppConfig; use OCP\BackgroundJob\IJobList; -class SettingsService { +final class SettingsService { /** @var array */ private const DEFAULTS = [ 'tensorflow.cores' => '0', diff --git a/lib/Service/StorageService.php b/lib/Service/StorageService.php index b06dce4a5..12c2c796f 100644 --- a/lib/Service/StorageService.php +++ b/lib/Service/StorageService.php @@ -20,7 +20,7 @@ use OCP\FilesMetadata\IFilesMetadataManager; use OCP\IDBConnection; -class StorageService { +final class StorageService { public const ALLOWED_MOUNT_TYPES = [ 'OC\Files\Mount\LocalHomeMountProvider', 'OC\Files\Mount\ObjectHomeMountProvider', diff --git a/lib/Service/TagManager.php b/lib/Service/TagManager.php index fa784f1f2..46459d006 100644 --- a/lib/Service/TagManager.php +++ b/lib/Service/TagManager.php @@ -12,7 +12,7 @@ use OCP\SystemTag\ISystemTagObjectMapper; use OCP\SystemTag\TagNotFoundException; -class TagManager { +final class TagManager { public const RECOGNIZED_TAG = 'Tagged by recognize v3.0.0'; private ISystemTagManager $tagManager; diff --git a/lib/Settings/AdminSection.php b/lib/Settings/AdminSection.php index d3161a357..7932f4a0f 100644 --- a/lib/Settings/AdminSection.php +++ b/lib/Settings/AdminSection.php @@ -11,7 +11,7 @@ use OCP\IURLGenerator; use OCP\Settings\IIconSection; -class AdminSection implements IIconSection { +final class AdminSection implements IIconSection { private IL10N $l; private IURLGenerator $urlgen; diff --git a/lib/Settings/AdminSettings.php b/lib/Settings/AdminSettings.php index 0b9428232..e8166610a 100644 --- a/lib/Settings/AdminSettings.php +++ b/lib/Settings/AdminSettings.php @@ -12,7 +12,7 @@ use OCP\AppFramework\Services\IInitialState; use OCP\Settings\ISettings; -class AdminSettings implements ISettings { +final class AdminSettings implements ISettings { private IInitialState $initialState; private SettingsService $settingsService; diff --git a/psalm-baseline.xml b/psalm-baseline.xml index d2818a79f..2ffdfb346 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -1,5 +1,5 @@ - + getContainer()]]> @@ -12,6 +12,9 @@ + + + @@ -21,61 +24,64 @@ + + ]]> + + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - @@ -84,9 +90,6 @@ - - - @@ -108,15 +111,22 @@ - - getPid()]]> - + + + + + - - - + + + + + + + + @@ -161,10 +171,6 @@ longestDistanceInNode]]> - - - - setId]]> setId]]> @@ -191,13 +197,14 @@ - + - + + @@ -223,9 +230,29 @@ + + coreDistances[$label]]]> + coreDistances[$queryLabel] ?? INF]]> + + + coreDistances]]> + coreDistances]]> + coreDistances]]> + coreDistances]]> + coreDistances]]> + coreDistances]]> + + + coreDistances[$label]]]> + coreDistances[$queryLabel] ?? INF]]> + + + + + root]]> @@ -242,12 +269,9 @@ - - - @@ -261,22 +285,8 @@ - - coreNeighborDistances[$label]]]> coreNeighborDistances[$label]]]> coreNeighborDistances[$label]]]> - coreNeighborDistances[$queryLabel]]]> - coreNeighborDistances[$queryLabel]]]> - coreNeighborDistances[$queryLabel]]]> - coreNeighborDistances[$queryLabel]]]> - coreNeighborDistances[$queryLabel]]]> - coreNeighborDistances[$referenceLabel]]]> - coreNeighborDistances[$referenceLabel]]]> - coreNeighborDistances[$referenceLabel]]]> - coreNeighborDistances[$referenceLabel]]]> - coreNeighborDistances[$referenceLabel]]]> - coreNeighborDistances[$sampleLabel]]]> - coreNeighborDistances[$sampleLabel]]]> @@ -293,12 +303,7 @@ nativeInterpointCache[$smallIndex][$largeIndex]]]> - coreNeighborDistances[$neighborLabel][$label]]]> - coreNeighborDistances[$queryLabel][$referenceLabel]]]> - coreNeighborDistances[$queryLabel][$referenceLabel]]]> - coreNeighborDistances[$referenceLabel][$queryLabel]]]> - coreNeighborDistances[$referenceLabel][$queryLabel]]]> nativeInterpointCache[$smallIndex][$largeIndex]]]> nodeDistances[$smallIndex][$largeIndex]]]> @@ -359,8 +364,6 @@ nodeDistances[$smallIndex]]]> - - @@ -373,11 +376,6 @@ - - - - - @@ -403,19 +401,12 @@ - - - - - - - @@ -451,24 +442,19 @@ radius()]]> radius() - $queryLeft->radius()]]> radius() - $queryRight->radius()]]> - + + coreDistances]]> + coreDistances]]> + coreDistances]]> + coreNeighborDistances]]> + - coreDistances[$label]]]> - coreDistances[$label]]]> - coreDistances[$queryLabel] ?? INF]]> - coreDistances[$queryLabel] ?? INF]]> - coreNeighborDistances[$a][$b]]]> - coreNeighborDistances[$b][$a]]]> nativeInterpointCache[$smallIndex][$largeIndex]]]> - - coreNeighborDistances[$sampleLabel]), array_values($this->coreNeighborDistances[$sampleLabel])]]]> - ,list}]]> - @@ -492,6 +478,25 @@ + + coreNeighborDistances]]> + coreNeighborDistances]]> + coreNeighborDistances]]> + coreNeighborDistances]]> + coreNeighborDistances]]> + coreNeighborDistances]]> + coreNeighborDistances]]> + coreNeighborDistances]]> + coreNeighborDistances]]> + coreNeighborDistances]]> + coreNeighborDistances]]> + + + radius() + $shortestDistance)]]> + + + + @@ -499,11 +504,14 @@ coreNeighborDistances[$queryLabel]]]> - - - + + + + + + getCoreEdges()]]> @@ -546,6 +554,9 @@ + + + @@ -582,8 +593,6 @@ - - @@ -591,10 +600,8 @@ - - @@ -607,8 +614,6 @@ - - @@ -648,13 +653,12 @@ radius()]]> - radius()]]> + radius()]]> - - - ]]> - + + ]]> + @@ -693,10 +697,10 @@ - - - - + + + + @@ -753,7 +757,7 @@ - + findEntities($qb)]]> @@ -770,9 +774,6 @@ - - - @@ -794,7 +795,7 @@ - + findEntities($qb)]]> @@ -828,9 +829,6 @@ - - - @@ -855,7 +853,7 @@ - + findEntities($qb)]]> @@ -863,9 +861,6 @@ - - - fetchOne()]]> fetchOne()]]> @@ -917,19 +912,6 @@ tar]]> tar]]> - - - - - - - - - - - ]]> - - @@ -982,6 +964,11 @@ + + + + + getPathname()]]> getPathname()]]> @@ -994,6 +981,13 @@ + + + + + getPathname())]]> + getPathname())]]> + @@ -1011,9 +1005,6 @@ - - - @@ -1022,6 +1013,9 @@ + + + @@ -1030,6 +1024,13 @@ getVector()]]> + + + + + + + @@ -1038,9 +1039,6 @@ - - ]]> - @@ -1056,22 +1054,6 @@ - - - - - - - - - - - - - - - - @@ -1081,12 +1063,6 @@ - - - - - - @@ -1135,4 +1111,9 @@ + + + + + diff --git a/psalm.xml b/psalm.xml index a88c55e6e..f8d3b502c 100644 --- a/psalm.xml +++ b/psalm.xml @@ -7,6 +7,8 @@ xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd" errorBaseline="psalm-baseline.xml" phpVersion="8.1" + findUnusedCode="false" + ensureOverrideAttribute="false" > diff --git a/vendor-bin/php-cs-fixer/composer.json b/vendor-bin/php-cs-fixer/composer.json index 5f2618cfe..6aaae3d15 100644 --- a/vendor-bin/php-cs-fixer/composer.json +++ b/vendor-bin/php-cs-fixer/composer.json @@ -1,6 +1,6 @@ { "require": { - "friendsofphp/php-cs-fixer": "^3", - "nextcloud/coding-standard": "^1" + "friendsofphp/php-cs-fixer": "3.x", + "nextcloud/coding-standard": "1.x" } } diff --git a/vendor-bin/php-scoper/composer.lock b/vendor-bin/php-scoper/composer.lock index f78e54b33..151dcd4be 100644 --- a/vendor-bin/php-scoper/composer.lock +++ b/vendor-bin/php-scoper/composer.lock @@ -140,22 +140,21 @@ }, { "name": "fidry/filesystem", - "version": "1.2.1", + "version": "1.2.3", "source": { "type": "git", "url": "https://github.com/theofidry/filesystem.git", - "reference": "8303225d289da1c434f6009743fbe9aad852de0c" + "reference": "3e1f9cac40f807b7c4196013ab77cc1b9416e3e5" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/theofidry/filesystem/zipball/8303225d289da1c434f6009743fbe9aad852de0c", - "reference": "8303225d289da1c434f6009743fbe9aad852de0c", + "url": "https://api.github.com/repos/theofidry/filesystem/zipball/3e1f9cac40f807b7c4196013ab77cc1b9416e3e5", + "reference": "3e1f9cac40f807b7c4196013ab77cc1b9416e3e5", "shasum": "" }, "require": { "php": "^8.1", - "symfony/filesystem": "^6.4 || ^7.0", - "thecodingmachine/safe": "^2.0" + "symfony/filesystem": "^6.4 || ^7.0" }, "require-dev": { "bamarni/composer-bin-plugin": "^1.4", @@ -195,7 +194,7 @@ ], "support": { "issues": "https://github.com/theofidry/filesystem/issues", - "source": "https://github.com/theofidry/filesystem/tree/1.2.1" + "source": "https://github.com/theofidry/filesystem/tree/1.2.3" }, "funding": [ { @@ -203,7 +202,7 @@ "type": "github" } ], - "time": "2023-12-10T13:29:09+00:00" + "time": "2025-02-13T22:58:51+00:00" }, { "name": "humbug/php-scoper", diff --git a/vendor-bin/psalm/composer.json b/vendor-bin/psalm/composer.json index 89710153c..f5109395d 100644 --- a/vendor-bin/psalm/composer.json +++ b/vendor-bin/psalm/composer.json @@ -1,5 +1,5 @@ { "require": { - "psalm/phar": "5.*" + "psalm/phar": "6.*" } }