Skip to content

Commit 80fe0ca

Browse files
authored
Merge pull request #1431 from nextcloud/carl/modern-event
Improve psalm for DAV
2 parents 9c79c02 + a7deb89 commit 80fe0ca

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+8867
-432
lines changed

composer.json

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,6 @@
1313
"OCA\\Recognize\\": "lib/"
1414
}
1515
},
16-
"require-dev": {
17-
"nextcloud/ocp": "dev-master",
18-
"symfony/console": "^6.4",
19-
"symfony/process": "^6.4"
20-
},
2116
"scripts": {
2217
"lint": "find . -name \\*.php -not -path './vendor/*' -print0 | xargs -0 -n1 php -l",
2318
"cs:check": "php-cs-fixer fix --dry-run --diff",

lib/AppInfo/Application.php

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
namespace OCA\Recognize\AppInfo;
99

1010
use OCA\DAV\Connector\Sabre\Principal;
11+
use OCA\DAV\Events\SabrePluginAddEvent;
1112
use OCA\Recognize\Dav\Faces\PropFindPlugin;
1213
use OCA\Recognize\Hooks\FileListener;
1314
use OCP\AppFramework\App;
@@ -22,7 +23,6 @@
2223
use OCP\Files\Events\Node\NodeDeletedEvent;
2324
use OCP\Files\Events\Node\NodeRenamedEvent;
2425
use OCP\Files\Events\NodeRemovedFromCache;
25-
use OCP\SabrePluginEvent;
2626

2727
final class Application extends App implements IBootstrap {
2828
public const APP_ID = 'recognize';
@@ -60,15 +60,13 @@ public function register(IRegistrationContext $context): void {
6060
*/
6161
public function boot(IBootContext $context): void {
6262
$eventDispatcher = \OCP\Server::get(IEventDispatcher::class);
63-
$eventDispatcher->addListener('OCA\DAV\Connector\Sabre::addPlugin', function (SabrePluginEvent $event): void {
63+
$eventDispatcher->addListener(SabrePluginAddEvent::class, function (SabrePluginAddEvent $event): void {
6464
$server = $event->getServer();
6565

66-
if ($server !== null) {
67-
// We have to register the PropFindPlugin here and not info.xml,
68-
// because info.xml plugins are loaded, after the
69-
// beforeMethod:* hook has already been emitted.
70-
$server->addPlugin($this->getContainer()->get(PropFindPlugin::class));
71-
}
66+
// We have to register the PropFindPlugin here and not info.xml,
67+
// because info.xml plugins are loaded, after the
68+
// beforeMethod:* hook has already been emitted.
69+
$server->addPlugin($this->getContainer()->get(PropFindPlugin::class));
7270
});
7371
}
7472
}

lib/BackgroundJobs/ClassifierJob.php

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

10+
use OCA\Recognize\Db\QueueFile;
1011
use OCA\Recognize\Service\QueueService;
1112
use OCA\Recognize\Service\SettingsService;
1213
use OCP\AppFramework\Utility\ITimeFactory;
@@ -33,16 +34,16 @@ public function __construct(
3334
$this->setAllowParallelRuns($settingsService->getSetting('concurrency.enabled') === 'true');
3435
}
3536

37+
/**
38+
* @param array{storageId: int, rootId: int} $argument
39+
*/
3640
protected function runClassifier(string $model, array $argument): void {
3741
sleep(10);
3842
if ($this->settingsService->getSetting('concurrency.enabled') !== 'true' && $this->anyOtherClassifierJobsRunning()) {
3943
$this->logger->debug('Stalling job '.static::class.' with argument ' . var_export($argument, true) . ' because other classifiers are already reserved');
4044
return;
4145
}
4246

43-
/**
44-
* @var int $storageId
45-
*/
4647
$storageId = $argument['storageId'];
4748
$rootId = $argument['rootId'];
4849
if ($this->settingsService->getSetting($model.'.enabled') !== 'true') {
@@ -100,22 +101,15 @@ protected function runClassifier(string $model, array $argument): void {
100101
}
101102
}
102103

103-
/**
104-
* @return int
105-
*/
106104
abstract protected function getBatchSize(): int;
107105

108106
/**
109-
* @param list<OCA\Recognize\Db\QueueFile> $files
110-
* @return void
107+
* @param list<QueueFile> $files
111108
* @throws \RuntimeException|\ErrorException
112109
*/
113110
abstract protected function classify(array $files) : void;
114111

115-
/**
116-
* @return bool
117-
*/
118-
private function anyOtherClassifierJobsRunning() {
112+
private function anyOtherClassifierJobsRunning(): bool {
119113
foreach ([
120114
ClassifyFacesJob::class,
121115
ClassifyImagenetJob::class,

lib/BackgroundJobs/ClassifyFacesJob.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public function __construct(ITimeFactory $time, Logger $logger, QueueService $qu
2828
}
2929

3030
/**
31-
* @inheritDoc
31+
* @param array{storageId: int, rootId: int} $argument
3232
*/
3333
protected function run($argument): void {
3434
$this->runClassifier(self::MODEL_NAME, $argument);

lib/BackgroundJobs/ClassifyImagenetJob.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public function __construct(ITimeFactory $time, Logger $logger, QueueService $qu
2828
}
2929

3030
/**
31-
* @inheritDoc
31+
* @param array{storageId: int, rootId: int} $argument
3232
*/
3333
protected function run($argument): void {
3434
$this->runClassifier(self::MODEL_NAME, $argument);

lib/BackgroundJobs/ClassifyLandmarksJob.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
namespace OCA\Recognize\BackgroundJobs;
99

1010
use OCA\Recognize\Classifiers\Images\LandmarksClassifier;
11+
use OCA\Recognize\Db\QueueFile;
1112
use OCA\Recognize\Service\Logger;
1213
use OCA\Recognize\Service\QueueService;
1314
use OCA\Recognize\Service\SettingsService;
@@ -28,14 +29,14 @@ public function __construct(ITimeFactory $time, Logger $logger, QueueService $qu
2829
}
2930

3031
/**
31-
* @inheritDoc
32+
* @param array{storageId: int, rootId: int} $argument
3233
*/
3334
protected function run($argument): void {
3435
$this->runClassifier(self::MODEL_NAME, $argument);
3536
}
3637

3738
/**
38-
* @param list<\OCA\Recognize\Db\QueueFile> $files
39+
* @param list<QueueFile> $files
3940
* @return void
4041
*/
4142
protected function classify(array $files) : void {

lib/BackgroundJobs/ClassifyMovinetJob.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ public function __construct(ITimeFactory $time, Logger $logger, QueueService $qu
2828
}
2929

3030
/**
31-
* @inheritDoc
31+
* @param array{storageId: int, rootId: int} $argument
3232
*/
33-
protected function run($argument):void {
33+
protected function run($argument): void {
3434
$this->runClassifier(self::MODEL_NAME, $argument);
3535
}
3636

lib/BackgroundJobs/ClassifyMusicnnJob.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,9 @@ public function __construct(ITimeFactory $time, Logger $logger, QueueService $qu
2828
}
2929

3030
/**
31-
* @inheritDoc
32-
*
33-
* @return void
31+
* @param array{storageId: int, rootId: int} $argument
3432
*/
35-
protected function run($argument) {
33+
protected function run($argument): void {
3634
$this->runClassifier(self::MODEL_NAME, $argument);
3735
}
3836

lib/BackgroundJobs/ClusterFacesJob.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,10 @@ public function __construct(ITimeFactory $time, Logger $logger, IJobList $jobLis
3131
}
3232

3333
/**
34-
* @inheritDoc
35-
*
36-
* @return void
34+
* @param array{storageId: int, rootId: int, userId: string} $argument
3735
*/
38-
protected function run($argument) {
39-
$userId = (string) $argument['userId'];
36+
protected function run($argument): void {
37+
$userId = $argument['userId'];
4038
try {
4139
$this->clusterAnalyzer->calculateClusters($userId, self::BATCH_SIZE);
4240
} catch (\Throwable $e) {

lib/BackgroundJobs/MaintenanceJob.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,9 @@ public function __construct(
2828
}
2929

3030
/**
31-
* @param mixed $argument
32-
* @return void
31+
* @param array{storageId: int, rootId: int} $argument
3332
*/
34-
protected function run($argument) {
33+
protected function run($argument): void {
3534
// Trigger clustering in case it's stuck
3635
try {
3736
$users = $this->faceDetectionMapper->getUsersForUnclustered();

0 commit comments

Comments
 (0)