Skip to content

Commit 84d28ae

Browse files
committed
fix: fix psalm issues
Signed-off-by: Marcel Klehr <mklehr@gmx.net>
1 parent 4c457c4 commit 84d28ae

6 files changed

Lines changed: 45 additions & 66 deletions

File tree

lib/BackgroundJobs/StorageCrawlJob.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ protected function run($argument): void {
7878
$this->queue->insertIntoQueue(ImagenetClassifier::MODEL_NAME, $queueFile);
7979
}
8080
if (!in_array(ImagenetClassifier::MODEL_NAME, $models) && in_array(LandmarksClassifier::MODEL_NAME, $models)) {
81-
$tags = $this->tagManager->getTagsForFiles([$queueFile->getFileId()]);
81+
$tags = $this->tagManager->getTagsForFiles([(string)$queueFile->getFileId()]);
8282
$fileTags = $tags[$queueFile->getFileId()];
8383
$landmarkTags = array_filter($fileTags, function ($tag) {
8484
return in_array($tag->getName(), LandmarksClassifier::PRECONDITION_TAGS);

lib/Command/Classify.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
123123
}
124124
// if retry flag is set, skip other classifiers for tagged files
125125
if ($input->getOption('retry')) {
126-
$fileTags = $this->tagManager->getTagsForFiles([$lastFileId]);
126+
$fileTags = $this->tagManager->getTagsForFiles([(string)$lastFileId]);
127127
// check if processed tag is already in the tags
128128
if (in_array($processedTag, $fileTags[$lastFileId])) {
129129
continue;

lib/Dav/Faces/PropFindPlugin.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,12 +78,12 @@ public function propFind(PropFind $propFind, INode $node): void {
7878
$propFind->handle(TagsPlugin::FAVORITE_PROPERTYNAME, fn () => $node->isFavorite() ? 1 : 0);
7979
$propFind->handle(FilesPlugin::HAS_PREVIEW_PROPERTYNAME, fn () => json_encode($this->previewManager->isAvailable($node->getFile()->getFileInfo())));
8080
$propFind->handle(FilesPlugin::PERMISSIONS_PROPERTYNAME, function () use ($node): string {
81-
$permissions = DavUtil::getDavPermissions($node->getFile()->getFileInfo());
81+
$permissions = DavUtil::getDavPermissions($node->getFile(), $node->getFile()->getParent());
8282
$filteredPermissions = str_replace('R', '', $permissions);
8383
return $filteredPermissions;
8484
});
8585

86-
foreach ($node->getFile()->getFileInfo()->getMetadata() as $metadataKey => $metadataValue) {
86+
foreach ($node->getFile()->getMetadata() as $metadataKey => $metadataValue) {
8787
/** @var string $metadataKey */
8888
$propFind->handle(FilesPlugin::FILE_METADATA_PREFIX.$metadataKey, $metadataValue);
8989
}

lib/Service/StorageService.php

Lines changed: 6 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use OCA\Recognize\Constants;
1717
use OCP\DB\Exception;
1818
use OCP\DB\QueryBuilder\IQueryBuilder;
19+
use OCP\Files\Cache\IFileAccess;
1920
use OCP\Files\IMimeTypeLoader;
2021
use OCP\FilesMetadata\IFilesMetadataManager;
2122
use OCP\IDBConnection;
@@ -39,6 +40,7 @@ public function __construct(
3940
private IgnoreService $ignoreService,
4041
private IMimeTypeLoader $mimeTypes,
4142
private IFilesMetadataManager $metadataManager,
43+
private IFileAccess $fileAccess,
4244
) {
4345
}
4446

@@ -47,46 +49,13 @@ public function __construct(
4749
* @throws \OCP\DB\Exception
4850
*/
4951
public function getMounts(): \Generator {
50-
$qb = $this->db->getQueryBuilder();
51-
$qb->selectDistinct(['root_id', 'storage_id', 'mount_provider_class']) // to avoid scanning each occurrence of a groupfolder
52-
->from('mounts')
53-
->where($qb->expr()->in('mount_provider_class', $qb->createPositionalParameter(self::ALLOWED_MOUNT_TYPES, IQueryBuilder::PARAM_STR_ARRAY)));
54-
$result = $qb->executeQuery();
55-
56-
57-
while (
58-
/** @var array{storage_id:int, root_id:int,mount_provider_class:string} $row */
59-
$row = $result->fetch()
60-
) {
61-
$storageId = (int)$row['storage_id'];
62-
$rootId = (int)$row['root_id'];
63-
$overrideRoot = $rootId;
64-
if (in_array($row['mount_provider_class'], self::HOME_MOUNT_TYPES)) {
65-
// Only crawl files, not cache or trashbin
66-
$qb = new CacheQueryBuilder($this->db->getQueryBuilder(), $this->metadataManager);
67-
try {
68-
$res = $qb->selectFileCache()
69-
->andWhere($qb->expr()->eq('filecache.storage', $qb->createNamedParameter($storageId, IQueryBuilder::PARAM_INT)))
70-
->andWhere($qb->expr()->eq('filecache.path', $qb->createNamedParameter('files')))
71-
->executeQuery();
72-
/** @var array|false $root */
73-
$root = $res->fetch();
74-
$res->closeCursor();
75-
if ($root !== false) {
76-
$overrideRoot = intval($root['fileid']);
77-
}
78-
} catch (Exception $e) {
79-
$this->logger->error('Could not fetch home storage files root for storage '.$storageId, ['exception' => $e]);
80-
continue;
81-
}
82-
}
52+
foreach ($this->fileAccess->getDistinctMounts(self::ALLOWED_MOUNT_TYPES) as $mount) {
8353
yield [
84-
'storage_id' => $storageId,
85-
'root_id' => $rootId,
86-
'override_root' => $overrideRoot,
54+
'storage_id' => $mount['storage_id'],
55+
'root_id' => $mount['root_id'],
56+
'override_root' => $mount['overridden_root'],
8757
];
8858
}
89-
$result->closeCursor();
9059
}
9160

9261
/**

lib/Service/TagManager.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ public function getTagsForFiles(array $fileIds): array {
9191
}
9292

9393
/**
94-
* @return array<string>
94+
* @return list<string>
9595
*/
9696
public function findClassifiedFiles(): array {
9797
return $this->objectMapper->getObjectIdsForTags($this->getProcessedTag()->getId(), 'files');
@@ -107,7 +107,7 @@ public function findMissedClassifications(): array {
107107
$processedId = $this->getProcessedTag()->getId();
108108
foreach ($classifiedChunks as $classifiedChunk) {
109109
/** @var array<string,string[]> $tagIdsByFile */
110-
$tagIdsByFile = $this->objectMapper->getTagIdsForObjects($classifiedChunk, 'files');
110+
$tagIdsByFile = $this->objectMapper->getTagIdsForObjects(array_values($classifiedChunk), 'files');
111111
$missedChunk = array_keys(array_filter($tagIdsByFile, function ($tags) use ($processedId) : bool {
112112
return count($tags) === 1 && $tags[0] !== $processedId;
113113
}));

psalm-baseline.xml

Lines changed: 33 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<files psalm-version="6.14.2@bbd217fc98c0daa0a13aea2a7f119d03ba3fc9a0">
2+
<files psalm-version="6.16.1@f1f5de594dc76faf8784e02d3dc4716c91c6f6ac">
33
<file src="lib/AppInfo/Application.php">
44
<DeprecatedInterface>
55
<code><![CDATA[$this->getContainer()]]></code>
@@ -645,17 +645,9 @@
645645
</file>
646646
<file src="lib/Dav/Faces/PropFindPlugin.php">
647647
<MixedArgument>
648-
<code><![CDATA[$node->getFile()->getFileInfo()]]></code>
649648
<code><![CDATA[$node->getFile()->getFileInfo()]]></code>
650649
<code><![CDATA[TagsPlugin::FAVORITE_PROPERTYNAME]]></code>
651650
</MixedArgument>
652-
<MixedAssignment>
653-
<code><![CDATA[$metadataKey]]></code>
654-
<code><![CDATA[$metadataValue]]></code>
655-
</MixedAssignment>
656-
<MixedMethodCall>
657-
<code><![CDATA[getMetadata]]></code>
658-
</MixedMethodCall>
659651
<PropertyNotSetInConstructor>
660652
<code><![CDATA[$server]]></code>
661653
</PropertyNotSetInConstructor>
@@ -665,8 +657,6 @@
665657
</UndefinedClass>
666658
<UndefinedInterfaceMethod>
667659
<code><![CDATA[getFileInfo]]></code>
668-
<code><![CDATA[getFileInfo]]></code>
669-
<code><![CDATA[getFileInfo]]></code>
670660
</UndefinedInterfaceMethod>
671661
</file>
672662
<file src="lib/Dav/RecognizeHome.php">
@@ -690,6 +680,9 @@
690680
<MixedAssignment>
691681
<code><![CDATA[$array[$field]]]></code>
692682
</MixedAssignment>
683+
<PropertyNotSetInConstructor>
684+
<code><![CDATA[FaceCluster]]></code>
685+
</PropertyNotSetInConstructor>
693686
</file>
694687
<file src="lib/Db/FaceDetection.php">
695688
<MissingPropertyType>
@@ -709,11 +702,22 @@
709702
<MixedReturnStatement>
710703
<code><![CDATA[$this->getter('faceVector')]]></code>
711704
</MixedReturnStatement>
705+
<PropertyNotSetInConstructor>
706+
<code><![CDATA[FaceDetection]]></code>
707+
</PropertyNotSetInConstructor>
712708
</file>
713709
<file src="lib/Db/FaceDetectionWithTitle.php">
714710
<MissingPropertyType>
715711
<code><![CDATA[$title]]></code>
716712
</MissingPropertyType>
713+
<PropertyNotSetInConstructor>
714+
<code><![CDATA[FaceDetectionWithTitle]]></code>
715+
</PropertyNotSetInConstructor>
716+
</file>
717+
<file src="lib/Db/FsAccessUpdate.php">
718+
<PropertyNotSetInConstructor>
719+
<code><![CDATA[FsAccessUpdate]]></code>
720+
</PropertyNotSetInConstructor>
717721
</file>
718722
<file src="lib/Db/FsActionMapper.php">
719723
<MixedAssignment>
@@ -724,6 +728,21 @@
724728
<code><![CDATA[\call_user_func($className. '::fromRow', $row)]]></code>
725729
</MixedReturnStatement>
726730
</file>
731+
<file src="lib/Db/FsCreation.php">
732+
<PropertyNotSetInConstructor>
733+
<code><![CDATA[FsCreation]]></code>
734+
</PropertyNotSetInConstructor>
735+
</file>
736+
<file src="lib/Db/FsDeletion.php">
737+
<PropertyNotSetInConstructor>
738+
<code><![CDATA[FsDeletion]]></code>
739+
</PropertyNotSetInConstructor>
740+
</file>
741+
<file src="lib/Db/FsMove.php">
742+
<PropertyNotSetInConstructor>
743+
<code><![CDATA[FsMove]]></code>
744+
</PropertyNotSetInConstructor>
745+
</file>
727746
<file src="lib/Db/QueueFile.php">
728747
<MissingPropertyType>
729748
<code><![CDATA[$fileId]]></code>
@@ -734,6 +753,9 @@
734753
<MixedAssignment>
735754
<code><![CDATA[$array[$field]]]></code>
736755
</MixedAssignment>
756+
<PropertyNotSetInConstructor>
757+
<code><![CDATA[QueueFile]]></code>
758+
</PropertyNotSetInConstructor>
737759
</file>
738760
<file src="lib/Helper/Archive.php">
739761
<MissingParamType>
@@ -943,7 +965,6 @@
943965
<code><![CDATA[$ignoreFileidsExpr[]]]></code>
944966
<code><![CDATA[$ignoreFileidsExpr[]]]></code>
945967
<code><![CDATA[$ignoreFileidsExpr[]]]></code>
946-
<code><![CDATA[$res]]></code>
947968
<code><![CDATA[$result]]></code>
948969
</MixedAssignment>
949970
<MixedMethodCall>
@@ -952,23 +973,16 @@
952973
<code><![CDATA[andWhere]]></code>
953974
<code><![CDATA[andWhere]]></code>
954975
<code><![CDATA[andWhere]]></code>
955-
<code><![CDATA[andWhere]]></code>
956-
<code><![CDATA[andWhere]]></code>
957976
<code><![CDATA[andX]]></code>
958977
<code><![CDATA[andX]]></code>
959978
<code><![CDATA[andX]]></code>
960979
<code><![CDATA[andX]]></code>
961980
<code><![CDATA[closeCursor]]></code>
962981
<code><![CDATA[closeCursor]]></code>
963-
<code><![CDATA[closeCursor]]></code>
964-
<code><![CDATA[eq]]></code>
965-
<code><![CDATA[eq]]></code>
966982
<code><![CDATA[eq]]></code>
967983
<code><![CDATA[eq]]></code>
968984
<code><![CDATA[executeQuery]]></code>
969985
<code><![CDATA[executeQuery]]></code>
970-
<code><![CDATA[executeQuery]]></code>
971-
<code><![CDATA[fetch]]></code>
972986
<code><![CDATA[fetch]]></code>
973987
<code><![CDATA[fetch]]></code>
974988
<code><![CDATA[gt]]></code>
@@ -989,10 +1003,6 @@
9891003
<code><![CDATA[$qb->expr()->notLike('path', $qb->createNamedParameter($path ? $path . '/%' : '%'))]]></code>
9901004
<code><![CDATA[$qb->expr()->notLike('path', $qb->createNamedParameter($path ? $path . '/%' : '%'))]]></code>
9911005
</MixedReturnStatement>
992-
<RedundantCastGivenDocblockType>
993-
<code><![CDATA[(int)$row['root_id']]]></code>
994-
<code><![CDATA[(int)$row['storage_id']]]></code>
995-
</RedundantCastGivenDocblockType>
9961006
</file>
9971007
<file src="lib/Service/TagManager.php">
9981008
<PossiblyFalseArgument>

0 commit comments

Comments
 (0)