Skip to content

Commit e75ec7c

Browse files
committed
fix: Add psalm configuration, fix some of the errors, add stubs, add baseline
Signed-off-by: Côme Chilliet <[email protected]>
1 parent a3da881 commit e75ec7c

File tree

57 files changed

+3845
-255
lines changed

Some content is hidden

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

57 files changed

+3845
-255
lines changed

composer.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@
1111
"cs:fix": "php-cs-fixer fix",
1212
"cs:check": "php-cs-fixer fix --dry-run --diff",
1313
"lint": "find . -name \\*.php -not -path './vendor/*' -print0 | xargs -0 -n1 php -l",
14+
"psalm": "psalm.phar --threads=1",
15+
"psalm:update-baseline": "psalm.phar --threads=1 --update-baseline",
16+
"psalm:clear": "psalm.phar --clear-cache && psalm.phar --clear-global-cache",
17+
"psalm:fix": "psalm.phar --alter --issues=InvalidReturnType,InvalidNullableReturnType,MissingParamType,InvalidFalsableReturnType",
1418
"test:integration": "phpunit -c tests/phpunit.integration.xml --fail-on-warning",
1519
"test:integration:dev": "phpunit -c tests/phpunit.integration.xml --no-coverage --order-by=defects --stop-on-defect --fail-on-warning --stop-on-error --stop-on-failure",
1620
"test:unit": "phpunit -c tests/phpunit.unit.xml --fail-on-warning",

lib/AppInfo/Application.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@ public function boot(IBootContext $context): void {
7474
$context->getAppContainer()->registerService('FileHooks', function ($c) {
7575
return new FileHooks(
7676
$c->query(IServerContainer::class)->getRootFolder(),
77-
\OC::$server->query(PhotofilesService::class),
78-
\OC::$server->query(TracksService::class),
77+
\OCP\Server::get(PhotofilesService::class),
78+
\OCP\Server::get(TracksService::class),
7979
$c->query(IServerContainer::class)->getLogger(),
8080
$c->query('AppName'),
8181
$c->query(IServerContainer::class)->getLockingProvider()

lib/BackgroundJob/AddPhotoJob.php

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,27 +42,29 @@ class AddPhotoJob extends QueuedJob {
4242
* @param ITimeFactory $timeFactory
4343
* @param PhotofilesService $photofilesService
4444
*/
45-
public function __construct(ITimeFactory $timeFactory,
45+
public function __construct(
46+
ITimeFactory $timeFactory,
4647
IRootFolder $root,
4748
PhotofilesService $photofilesService,
48-
ICacheFactory $cacheFactory) {
49+
ICacheFactory $cacheFactory,
50+
) {
4951
parent::__construct($timeFactory);
5052
$this->photofilesService = $photofilesService;
5153
$this->root = $root;
5254
$this->cacheFactory = $cacheFactory;
5355
$this->backgroundJobCache = $this->cacheFactory->createDistributed('maps:background-jobs');
5456
}
5557

56-
public function run($arguments) {
57-
$userFolder = $this->root->getUserFolder($arguments['userId']);
58-
$files = $userFolder->getById($arguments['photoId']);
58+
public function run($argument) {
59+
$userFolder = $this->root->getUserFolder($argument['userId']);
60+
$files = $userFolder->getById($argument['photoId']);
5961
if (empty($files)) {
6062
return;
6163
}
6264
$file = array_shift($files);
63-
$this->photofilesService->addPhotoNow($file, $arguments['userId']);
65+
$this->photofilesService->addPhotoNow($file, $argument['userId']);
6466

65-
$counter = $this->backgroundJobCache->get('recentlyAdded:'.$arguments['userId']) ?? 0;
66-
$this->backgroundJobCache->set('recentlyAdded:'.$arguments['userId'], (int)$counter + 1, 60 * 60 * 3);
67+
$counter = $this->backgroundJobCache->get('recentlyAdded:'.$argument['userId']) ?? 0;
68+
$this->backgroundJobCache->set('recentlyAdded:'.$argument['userId'], (int)$counter + 1, 60 * 60 * 3);
6769
}
6870
}

lib/BackgroundJob/LaunchUsersInstallScanJob.php

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,26 +17,27 @@
1717
use OCP\BackgroundJob\QueuedJob;
1818
use OCP\IUser;
1919
use OCP\IUserManager;
20+
use Psr\Log\LoggerInterface;
2021

2122
class LaunchUsersInstallScanJob extends QueuedJob {
2223

23-
private $jobList;
24-
2524
/**
2625
* LaunchUsersInstallScanJob constructor.
2726
*
2827
* A QueuedJob to launch a scan job for each user
2928
*
3029
* @param IJobList $jobList
3130
*/
32-
public function __construct(ITimeFactory $timeFactory, IJobList $jobList, IUserManager $userManager) {
31+
public function __construct(
32+
ITimeFactory $timeFactory,
33+
private IJobList $jobList,
34+
private IUserManager $userManager,
35+
) {
3336
parent::__construct($timeFactory);
34-
$this->jobList = $jobList;
35-
$this->userManager = $userManager;
3637
}
3738

38-
public function run($arguments) {
39-
\OC::$server->getLogger()->debug('Launch users install scan jobs cronjob executed');
39+
public function run($argument) {
40+
\OCP\Server::get(LoggerInterface::class)->debug('Launch users install scan jobs cronjob executed');
4041
$this->userManager->callForSeenUsers(function (IUser $user) {
4142
$this->jobList->add(UserInstallScanJob::class, ['userId' => $user->getUID()]);
4243
});

lib/BackgroundJob/LookupMissingGeoJob.php

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,31 +16,25 @@
1616
use OCP\AppFramework\Utility\ITimeFactory;
1717
use OCP\BackgroundJob\IJobList;
1818
use OCP\BackgroundJob\QueuedJob;
19+
use Psr\Log\LoggerInterface;
1920

2021
class LookupMissingGeoJob extends QueuedJob {
2122

22-
/** @var AddressService */
23-
private $addressService;
24-
25-
/** @var AddressService */
26-
private $jobList;
27-
2823
/**
2924
* LookupMissingGeoJob constructor.
3025
*
3126
* A QueuedJob to lookup missing geo information of addresses
32-
*
33-
* @param AddressService $service
34-
* @param IJobList $jobList
3527
*/
36-
public function __construct(ITimeFactory $timeFactory, AddressService $service, IJobList $jobList) {
28+
public function __construct(
29+
ITimeFactory $timeFactory,
30+
private AddressService $addressService,
31+
private IJobList $jobList,
32+
) {
3733
parent::__construct($timeFactory);
38-
$this->addressService = $service;
39-
$this->jobList = $jobList;
4034
}
4135

42-
public function run($arguments) {
43-
\OC::$server->getLogger()->debug('Maps address lookup cronjob executed');
36+
public function run($argument) {
37+
\OCP\Server::get(LoggerInterface::class)->debug('Maps address lookup cronjob executed');
4438
// lookup at most 200 addresses
4539
if (!$this->addressService->lookupMissingGeo(200)) {
4640
// if not all addresses where looked up successfully add a new job for next time

lib/BackgroundJob/UpdatePhotoByFileJob.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,30 +39,30 @@ class UpdatePhotoByFileJob extends QueuedJob {
3939
*
4040
* A QueuedJob to scan user storage for photos and tracks
4141
*
42-
* @param ITimeFactory $timeFactory
43-
* @param PhotofilesService $photofilesService
4442
*/
45-
public function __construct(ITimeFactory $timeFactory,
43+
public function __construct(
44+
ITimeFactory $timeFactory,
4645
IRootFolder $root,
4746
PhotofilesService $photofilesService,
48-
ICacheFactory $cacheFactory) {
47+
ICacheFactory $cacheFactory,
48+
) {
4949
parent::__construct($timeFactory);
5050
$this->photofilesService = $photofilesService;
5151
$this->root = $root;
5252
$this->cacheFactory = $cacheFactory;
5353
$this->backgroundJobCache = $this->cacheFactory->createDistributed('maps:background-jobs');
5454
}
5555

56-
public function run($arguments) {
57-
$userFolder = $this->root->getUserFolder($arguments['userId']);
58-
$files = $userFolder->getById($arguments['fileId']);
56+
public function run($argument) {
57+
$userFolder = $this->root->getUserFolder($argument['userId']);
58+
$files = $userFolder->getById($argument['fileId']);
5959
if (empty($files)) {
6060
return;
6161
}
6262
$file = array_shift($files);
6363
$this->photofilesService->updateByFileNow($file);
6464

65-
$counter = $this->backgroundJobCache->get('recentlyUpdated:'.$arguments['userId']) ?? 0;
66-
$this->backgroundJobCache->set('recentlyUpdated:'.$arguments['userId'], (int)$counter + 1, 60 * 60 * 3);
65+
$counter = $this->backgroundJobCache->get('recentlyUpdated:'.$argument['userId']) ?? 0;
66+
$this->backgroundJobCache->set('recentlyUpdated:'.$argument['userId'], (int)$counter + 1, 60 * 60 * 3);
6767
}
6868
}

lib/BackgroundJob/UserInstallScanJob.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
use OCP\IConfig;
2222
use OCP\IUserManager;
23+
use Psr\Log\LoggerInterface;
2324

2425
class UserInstallScanJob extends QueuedJob {
2526

@@ -49,9 +50,9 @@ public function __construct(ITimeFactory $timeFactory, IJobList $jobList,
4950
$this->tracksService = $tracksService;
5051
}
5152

52-
public function run($arguments) {
53-
$userId = $arguments['userId'];
54-
\OC::$server->getLogger()->debug('Launch user install scan job for '.$userId.' cronjob executed');
53+
public function run($argument) {
54+
$userId = $argument['userId'];
55+
\OCP\Server::get(LoggerInterface::class)->debug('Launch user install scan job for '.$userId.' cronjob executed');
5556
// scan photos and tracks for given user
5657
$this->rescanUserPhotos($userId);
5758
$this->rescanUserTracks($userId);

lib/Command/RegisterMimetypes.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ protected function configure() {
4040
* @return int
4141
*/
4242
protected function execute(InputInterface $input, OutputInterface $output): int {
43-
$this->output = $output;
4443
$output->writeln('Register mimetypes for existing files');
4544
$this->mimetypeService->registerForExistingFiles();
4645
$output->writeln('Register mimetypes for new files');

lib/Controller/ContactsController.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212

1313
namespace OCA\Maps\Controller;
1414

15-
use OC\Files\Node\Node;
1615
use OCA\DAV\CardDAV\CardDavBackend;
1716
use OCA\Maps\Service\AddressService;
1817
use OCP\AppFramework\Controller;
@@ -21,6 +20,7 @@
2120
use OCP\Contacts\IManager;
2221
use OCP\DB\QueryBuilder\IQueryBuilder;
2322
use OCP\Files\IRootFolder;
23+
use OCP\Files\Node;
2424
use OCP\Files\NotFoundException;
2525
use OCP\IAvatarManager;
2626
use OCP\IDBConnection;
@@ -83,7 +83,7 @@ public function __construct(
8383
/**
8484
* Converts a geo string as a float array
8585
* @param string formatted as "lat;lon"
86-
* @return float array containing [lat;lon]
86+
* @return float[] array containing [lat;lon]
8787
*/
8888
private function geoAsFloatArray($geo) {
8989
$res = array_map(function ($value) {return floatval($value);}, explode(';', $geo));
@@ -116,7 +116,7 @@ private function isNewAddress($prevGeo, $geo) {
116116
* get distance between two geo points
117117
* @param GPS coordinates of first point
118118
* @param GPS coordinates of second point
119-
* @return Distance in meters between these two points
119+
* @return float Distance in meters between these two points
120120
*/
121121
private function getDistance($coordsA, $coordsB) {
122122
if (empty($coordsA) || empty($coordsB)) {

lib/Controller/DevicesController.php

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,15 @@
1111

1212
namespace OCA\Maps\Controller;
1313

14-
use OCA\Files_External\NotFoundException;
1514
use OCA\Maps\DB\DeviceShareMapper;
1615
use OCA\Maps\Service\DevicesService;
17-
1816
use OCP\App\IAppManager;
1917
use OCP\AppFramework\Controller;
2018
use OCP\AppFramework\Db\DoesNotExistException;
2119
use OCP\AppFramework\Http;
2220
use OCP\AppFramework\Http\DataResponse;
23-
2421
use OCP\Files\IRootFolder;
25-
26-
22+
use OCP\Files\NotFoundException;
2723
use OCP\Files\NotPermittedException;
2824
use OCP\IConfig;
2925
use OCP\IDateTimeZone;
@@ -229,11 +225,10 @@ public function deleteDevice($id): DataResponse {
229225

230226
/**
231227
* @NoAdminRequired
232-
* @param null $deviceIdList
233-
* @param $begin
234-
* @param $end
228+
* @param ?array $deviceIdList
229+
* @param int $begin
230+
* @param int $end
235231
* @param bool $all=false
236-
* @return DataResponse
237232
* @throws \OCP\Files\NotFoundException
238233
* @throws \OCP\Files\NotPermittedException
239234
*/

0 commit comments

Comments
 (0)