Skip to content

Commit 4f68ede

Browse files
committed
fix: Fix psalm issues and run cs:fix
Signed-off-by: Marcel Klehr <[email protected]>
1 parent 0e5f2e5 commit 4f68ede

File tree

6 files changed

+71
-50
lines changed

6 files changed

+71
-50
lines changed

lib/BackgroundJobs/ProcessFsActionsJob.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,11 @@
77
declare(strict_types=1);
88
namespace OCA\Recognize\BackgroundJobs;
99

10+
use OCA\Recognize\Db\FsAccessUpdate;
1011
use OCA\Recognize\Db\FsActionMapper;
12+
use OCA\Recognize\Db\FsCreation;
13+
use OCA\Recognize\Db\FsDeletion;
14+
use OCA\Recognize\Db\FsMove;
1115
use OCA\Recognize\Service\FsActionService;
1216
use OCP\AppFramework\Utility\ITimeFactory;
1317
use OCP\BackgroundJob\IJobList;
@@ -30,7 +34,7 @@ public function __construct(
3034
}
3135

3236
/**
33-
* @param array{storage_id:int, type: string} $argument
37+
* @param array{storage_id:int, type: class-string<FsAccessUpdate|FsCreation|FsDeletion|FsMove>} $argument
3438
* @return void
3539
*/
3640
protected function run($argument): void {

lib/Db/FsActionMapper.php

Lines changed: 38 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ public function __construct(
3030
}
3131

3232
/**
33-
* @template CLASS FsAccessUpdate|FsCreation|FsDeletion|FsMove
34-
* @template-param class-string<CLASS> $className
35-
* @return list<CLASS>
36-
* @throws \OCP\DB\Exception
33+
* @param class-string<FsCreation|FsDeletion|FsMove|FsAccessUpdate> $className
34+
* @param int $storageId
35+
* @param int $limit
36+
* @return list<FsCreation|FsDeletion|FsMove|FsAccessUpdate>
3737
* @throws \Exception
3838
*/
3939
public function findByStorageId(string $className, int $storageId, int $limit = 0): array {
@@ -51,9 +51,8 @@ public function findByStorageId(string $className, int $storageId, int $limit =
5151
}
5252

5353
/**
54-
* @template CLASS FsAccessUpdate|FsCreation|FsDeletion|FsMove
55-
* @template-param class-string<CLASS> $className
56-
* @return list<CLASS>
54+
* @param class-string<FsCreation|FsDeletion|FsMove|FsAccessUpdate> $className
55+
* @return list<FsCreation|FsDeletion|FsMove|FsAccessUpdate>
5756
* @throws \OCP\DB\Exception
5857
* @throws \Exception
5958
*/
@@ -71,11 +70,9 @@ public function find(string $className, int $limit = 0): array {
7170
}
7271

7372
/**
74-
* @template CLASS FsAccessUpdate|FsCreation|FsDeletion|FsMove
75-
* @template-param class-string<CLASS> $className
76-
* @param string $className
73+
* @param class-string<FsCreation|FsDeletion|FsMove|FsAccessUpdate> $className
7774
* @param int $nodeId
78-
* @return Entity
75+
* @return FsCreation|FsDeletion|FsMove|FsAccessUpdate
7976
* @throws DoesNotExistException
8077
* @throws Exception
8178
* @throws MultipleObjectsReturnedException
@@ -92,9 +89,7 @@ public function findByNodeId(string $className, int $nodeId): Entity {
9289
}
9390

9491
/**
95-
* @template CLASS FsAccessUpdate|FsCreation|FsDeletion|FsMove
96-
* @template-param class-string<CLASS> $className
97-
* @param string $className
92+
* @param class-string<FsCreation|FsDeletion|FsMove|FsAccessUpdate> $className
9893
* @param int $storageId
9994
* @return int
10095
* @throws Exception
@@ -115,9 +110,7 @@ public function countByStorageId(string $className, int $storageId): int {
115110
}
116111

117112
/**
118-
* @template CLASS FsAccessUpdate|FsCreation|FsDeletion|FsMove
119-
* @template-param class-string<CLASS> $className
120-
* @param string $className
113+
* @param class-string<FsCreation|FsDeletion|FsMove|FsAccessUpdate> $className
121114
* @return int
122115
* @throws Exception
123116
*/
@@ -136,12 +129,10 @@ public function count(string $className): int {
136129
}
137130

138131
/**
139-
* @template CLASS FsAccessUpdate|FsCreation|FsDeletion|FsMove
140-
* @template-param class-string<CLASS> $className
141-
* @param string $className
132+
* @param class-string<FsCreation|FsDeletion|FsMove|FsAccessUpdate> $className
142133
* @param int $storageId
143134
* @param int $rootId
144-
* @return FsAccessUpdate
135+
* @return FsCreation|FsDeletion|FsMove|FsAccessUpdate
145136
* @throws DoesNotExistException
146137
* @throws Exception
147138
* @throws MultipleObjectsReturnedException
@@ -161,7 +152,7 @@ public function findByStorageIdAndRootId(string $className, int $storageId, int
161152
/**
162153
* @param int $storageId
163154
* @param int $rootId
164-
* @return FsAccessUpdate
155+
* @return FsCreation|FsDeletion|FsMove|FsAccessUpdate
165156
* @throws Exception
166157
* @throws MultipleObjectsReturnedException
167158
*/
@@ -184,34 +175,34 @@ public function insertAccessUpdate(int $storageId, int $rootId): Entity {
184175
/**
185176
* @param int $storageId
186177
* @param int $rootId
187-
* @return FsAccessUpdate
178+
* @return FsCreation|FsDeletion|FsMove|FsAccessUpdate
188179
* @throws Exception
189180
* @throws MultipleObjectsReturnedException
190181
*/
191182
public function insertCreation(int $storageId, int $rootId): Entity {
192183
try {
193-
$accessUpdate = $this->findByStorageIdAndRootId(FsCreation::class, $storageId, $rootId);
184+
$creation = $this->findByStorageIdAndRootId(FsCreation::class, $storageId, $rootId);
194185
} catch (DoesNotExistException $e) {
195-
$accessUpdate = new FsCreation();
196-
$accessUpdate->setStorageId($storageId);
197-
$accessUpdate->setRootId($rootId);
198-
$this->insert($accessUpdate);
186+
$creation = new FsCreation();
187+
$creation->setStorageId($storageId);
188+
$creation->setRootId($rootId);
189+
$this->insert($creation);
199190
$arguments = [ 'type' => FsCreation::class, 'storage_id' => $storageId ];
200191
if (!$this->jobList->has(ProcessFsActionsJob::class, $arguments)) {
201192
$this->jobList->add(ProcessFsActionsJob::class, $arguments);
202193
}
203194
}
204-
return $accessUpdate;
195+
return $creation;
205196
}
206197

207198

208199
/**
209200
* @param int $storageId
210201
* @param int $nodeId
211-
* @return FsAccessUpdate
202+
* @return FsCreation|FsDeletion|FsMove|FsAccessUpdate
212203
* @throws Exception|MultipleObjectsReturnedException
213204
*/
214-
public function insertDeletion(int $storageId, int $nodeId): Entity {
205+
public function insertDeletion(int $storageId, int $nodeId): FsCreation|FsDeletion|FsMove|FsAccessUpdate {
215206
try {
216207
$deletion = $this->findByNodeId(FsDeletion::class, $nodeId);
217208
} catch (DoesNotExistException $e) {
@@ -230,9 +221,9 @@ public function insertDeletion(int $storageId, int $nodeId): Entity {
230221
/**
231222
* @param int $nodeId
232223
* @param string $owner
233-
* @param array $addedUsers
234-
* @param array $targetUsers
235-
* @return FsAccessUpdate
224+
* @param list<string> $addedUsers
225+
* @param list<string> $targetUsers
226+
* @return FsCreation|FsDeletion|FsMove|FsAccessUpdate
236227
* @throws Exception|MultipleObjectsReturnedException
237228
*/
238229
public function insertMove(int $nodeId, string $owner, array $addedUsers, array $targetUsers): Entity {
@@ -254,13 +245,14 @@ public function insertMove(int $nodeId, string $owner, array $addedUsers, array
254245
}
255246

256247
/**
257-
* @param Entity $entity
258-
* @return FsAccessUpdate
248+
* @param FsCreation|FsDeletion|FsMove|FsAccessUpdate $entity
249+
* @return FsCreation|FsDeletion|FsMove|FsAccessUpdate
259250
* @throws Exception
260251
*/
261252
public function insert(Entity $entity): Entity {
262253
// get updated fields to save, fields have to be set using a setter to
263254
// be saved
255+
/** @var array<string, mixed> $properties */
264256
$properties = $entity->getUpdatedFields();
265257

266258
$qb = $this->db->getQueryBuilder();
@@ -278,6 +270,7 @@ public function insert(Entity $entity): Entity {
278270

279271
$qb->executeStatement();
280272

273+
/** @psalm-suppress DocblockTypeContradiction */
281274
if ($entity->id === null) {
282275
// When autoincrement is used id is always an int
283276
$entity->setId($qb->getLastInsertId());
@@ -290,9 +283,9 @@ public function insert(Entity $entity): Entity {
290283
* Returns an db result and throws exceptions when there are more or less
291284
* results
292285
*
293-
* @param string $className
286+
* @param class-string<FsCreation|FsDeletion|FsMove|FsAccessUpdate> $className
294287
* @param IQueryBuilder $query
295-
* @return Entity the entity
288+
* @return FsCreation|FsDeletion|FsMove|FsAccessUpdate the entity
296289
* @throws DoesNotExistException if the item does not exist
297290
* @throws Exception
298291
* @throws MultipleObjectsReturnedException if more than one item exist
@@ -304,9 +297,9 @@ protected function findItem(string $className, IQueryBuilder $query): Entity {
304297
/**
305298
* Runs a sql query and returns an array of items
306299
*
307-
* @param string $className
300+
* @param class-string<FsCreation|FsDeletion|FsMove|FsAccessUpdate> $className
308301
* @param IQueryBuilder $query
309-
* @return list<Entity> all fetched entities
302+
* @return list<FsCreation|FsDeletion|FsMove|FsAccessUpdate> all fetched entities
310303
*/
311304
protected function findItems(string $className, IQueryBuilder $query): array {
312305
$result = $query->executeQuery();
@@ -321,6 +314,9 @@ protected function findItems(string $className, IQueryBuilder $query): array {
321314
}
322315
}
323316

317+
/**
318+
* @param class-string<FsCreation|FsDeletion|FsMove|FsAccessUpdate> $className
319+
*/
324320
protected function mapRowToItem(string $className, array $row): Entity {
325321
unset($row['DOCTRINE_ROWNUM']); // remove doctrine/dbal helper column
326322
return \call_user_func($className. '::fromRow', $row);
@@ -329,8 +325,8 @@ protected function mapRowToItem(string $className, array $row): Entity {
329325
/**
330326
* Deletes an item from the table
331327
*
332-
* @param Entity $entity the entity that should be deleted
333-
* @return Entity the deleted entity
328+
* @param FsCreation|FsDeletion|FsMove|FsAccessUpdate $entity the entity that should be deleted
329+
* @return FsCreation|FsDeletion|FsMove|FsAccessUpdate the deleted entity
334330
* @throws Exception
335331
*/
336332
public function delete(Entity $entity): Entity {

lib/Db/FsMove.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,18 @@ public function __construct() {
4545
$this->addType('targetUsers', 'string');
4646
}
4747

48+
/**
49+
* @return list<string>
50+
*/
4851
public function getAddedUsers(): array {
49-
return explode(',', $this->addedUsers);
52+
return explode(',', $this->addedUsers ?? '');
5053
}
5154

55+
/**
56+
* @return list<string>
57+
*/
5258
public function getTargetUsers(): array {
53-
return explode(',', $this->targetUsers);
59+
return explode(',', $this->targetUsers ?? '');
5460
}
5561

5662
/**

lib/Hooks/FileListener.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,12 +256,17 @@ public function postDelete(Node $node, bool $recurse = true, ?array $mimeTypes =
256256

257257
/**
258258
* @throws \OCP\Files\InvalidPathException
259+
* @throws NotFoundException
259260
*/
260261
public function postInsert(Node $node, bool $recurse = true, ?array $mimeTypes = null): void {
261262
if ($node->getType() !== FileInfo::TYPE_FOLDER && $mimeTypes !== null && !in_array($node->getMimetype(), $mimeTypes)) {
262263
return;
263264
}
264-
$this->fsActionMapper->insertCreation($node->getMountPoint()->getNumericStorageId(), $node->getId());
265+
$storageId = $node->getMountPoint()->getNumericStorageId();
266+
if ($storageId === null) {
267+
return;
268+
}
269+
$this->fsActionMapper->insertCreation($storageId, $node->getId());
265270
}
266271

267272
/**

lib/Migration/Version011000001Date20251215094821.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public function changeSchema(IOutput $output, Closure $schemaClosure, array $opt
4848
$changed = true;
4949
}
5050
if (!$schema->hasTable('recognize_fs_deletions')) {
51-
$table = $schema->createTable('recognize_fs_creations');
51+
$table = $schema->createTable('recognize_fs_deletions');
5252
$table->addColumn('id', Types::BIGINT, ['autoincrement' => true]);
5353
$table->addColumn('storage_id', Types::BIGINT, ['notnull' => true]);
5454
$table->addColumn('node_id', Types::BIGINT, ['notnull' => true]);

lib/Service/FsActionService.php

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
use OCP\Files\NotFoundException;
2828
use Psr\Log\LoggerInterface;
2929

30-
class FsActionService {
30+
final class FsActionService {
3131
public const BATCH_SIZE = 1000;
3232
public function __construct(
3333
private FsActionMapper $fsActionMapper,
@@ -42,6 +42,9 @@ public function __construct(
4242
) {
4343
}
4444

45+
/**
46+
* @param class-string<FsCreation|FsDeletion|FsMove|FsAccessUpdate> $className
47+
*/
4548
public function processActionsByClassAndStorageId(string $className, int $storageId): void {
4649
try {
4750
$actions = $this->fsActionMapper->findByStorageId($className, $storageId, self::BATCH_SIZE);
@@ -52,6 +55,9 @@ public function processActionsByClassAndStorageId(string $className, int $storag
5255
$this->processActions($actions);
5356
}
5457

58+
/**
59+
* @param class-string<FsCreation|FsDeletion|FsMove|FsAccessUpdate> $className
60+
*/
5561
public function processActionsByClass(string $className): void {
5662
try {
5763
$actions = $this->fsActionMapper->find($className, self::BATCH_SIZE);
@@ -62,6 +68,9 @@ public function processActionsByClass(string $className): void {
6268
$this->processActions($actions);
6369
}
6470

71+
/**
72+
* @param array<FsCreation|FsDeletion|FsMove|FsAccessUpdate> $actions
73+
*/
6574
public function processActions(array $actions): void {
6675
foreach ($actions as $action) {
6776
switch ($action::class) {
@@ -191,10 +200,11 @@ public function onCreation(Node $node, bool $recurse = true, ?array $mimeTypes =
191200
}
192201

193202
$queueFile = new QueueFile();
194-
if ($node->getMountPoint()->getNumericStorageId() === null) {
203+
$storageId = $node->getMountPoint()->getNumericStorageId();
204+
if ($storageId === null) {
195205
return;
196206
}
197-
$queueFile->setStorageId($node->getMountPoint()->getNumericStorageId());
207+
$queueFile->setStorageId($storageId);
198208
$queueFile->setRootId($node->getMountPoint()->getStorageRootId());
199209

200210
if ($this->isFileIgnored($node)) {

0 commit comments

Comments
 (0)