Skip to content

Commit 96a1bd3

Browse files
authored
Merge pull request #3405 from nextcloud/chore/rector
chore: install rector
2 parents dc5a68e + e054900 commit 96a1bd3

52 files changed

Lines changed: 982 additions & 452 deletions

Some content is hidden

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

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020
"test:unit": "phpunit --display-all-issues -c tests/phpunit.xml",
2121
"test:integration": "phpunit --display-all-issues -c tests/phpunit.integration.xml",
2222
"psalm": "psalm --no-cache",
23-
"openapi": "generate-spec"
23+
"openapi": "generate-spec",
24+
"rector": "./vendor/bin/rector process"
2425
},
2526
"require-dev": {
2627
"bamarni/composer-bin-plugin": "^1.8"

lib/Activity/ActivityManager.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ class ActivityManager {
1616

1717
public function __construct(
1818
protected string $appName,
19-
private ?string $userId,
20-
private IManager $manager,
21-
private IGroupManager $groupManager,
22-
private CirclesService $circlesService,
19+
private readonly ?string $userId,
20+
private readonly IManager $manager,
21+
private readonly IGroupManager $groupManager,
22+
private readonly CirclesService $circlesService,
2323
) {
2424
}
2525

lib/Activity/Filter.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
class Filter implements IFilter {
1515
public function __construct(
1616
protected string $appName,
17-
private IL10N $l10n,
18-
private IURLGenerator $urlGenerator,
17+
private readonly IL10N $l10n,
18+
private readonly IURLGenerator $urlGenerator,
1919
) {
2020
}
2121

lib/Activity/Provider.php

Lines changed: 37 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -20,21 +20,19 @@
2020
use OCP\IURLGenerator;
2121
use OCP\IUserManager;
2222
use OCP\L10N\IFactory;
23-
use OCP\RichObjectStrings\IValidator;
2423
use Psr\Log\LoggerInterface;
2524

2625
class Provider implements IProvider {
2726
public function __construct(
2827
protected string $appName,
29-
private FormMapper $formMapper,
30-
private IEventMerger $eventMerger,
31-
private IGroupManager $groupManager,
32-
private LoggerInterface $logger,
33-
private IURLGenerator $urlGenerator,
34-
private IUserManager $userManager,
35-
private IFactory $l10nFactory,
36-
private IValidator $validator,
37-
private CirclesService $circlesService,
28+
private readonly FormMapper $formMapper,
29+
private readonly IEventMerger $eventMerger,
30+
private readonly IGroupManager $groupManager,
31+
private readonly LoggerInterface $logger,
32+
private readonly IURLGenerator $urlGenerator,
33+
private readonly IUserManager $userManager,
34+
private readonly IFactory $l10nFactory,
35+
private readonly CirclesService $circlesService,
3836
) {
3937
}
4038

@@ -113,32 +111,27 @@ public function parseSubjectString(string $subjectString, array $parameters): st
113111
* @return array
114112
*/
115113
public function getRichParams(IL10N $l10n, string $subject, array $params): array {
116-
switch ($subject) {
117-
case ActivityConstants::SUBJECT_NEWSHARE:
118-
return [
119-
'user' => $this->getRichUser($l10n, $params['userId']),
120-
'formTitle' => $this->getRichFormTitle($params['formTitle'], $params['formHash'])
121-
];
122-
case ActivityConstants::SUBJECT_NEWGROUPSHARE:
123-
return [
124-
'user' => $this->getRichUser($l10n, $params['userId']),
125-
'formTitle' => $this->getRichFormTitle($params['formTitle'], $params['formHash']),
126-
'group' => $this->getRichGroup($params['groupId'])
127-
];
128-
case ActivityConstants::SUBJECT_NEWCIRCLESHARE:
129-
return [
130-
'user' => $this->getRichUser($l10n, $params['userId']),
131-
'formTitle' => $this->getRichFormTitle($params['formTitle'], $params['formHash']),
132-
'circle' => $this->getRichCircle($params['circleId'])
133-
];
134-
case ActivityConstants::SUBJECT_NEWSUBMISSION:
135-
return [
136-
'user' => $this->getRichUser($l10n, $params['userId']),
137-
'formTitle' => $this->getRichFormTitle($params['formTitle'], $params['formHash'], 'results')
138-
];
139-
default:
140-
return [];
141-
}
114+
return match ($subject) {
115+
ActivityConstants::SUBJECT_NEWSHARE => [
116+
'user' => $this->getRichUser($l10n, $params['userId']),
117+
'formTitle' => $this->getRichFormTitle($params['formTitle'], $params['formHash'])
118+
],
119+
ActivityConstants::SUBJECT_NEWGROUPSHARE => [
120+
'user' => $this->getRichUser($l10n, $params['userId']),
121+
'formTitle' => $this->getRichFormTitle($params['formTitle'], $params['formHash']),
122+
'group' => $this->getRichGroup($params['groupId'])
123+
],
124+
ActivityConstants::SUBJECT_NEWCIRCLESHARE => [
125+
'user' => $this->getRichUser($l10n, $params['userId']),
126+
'formTitle' => $this->getRichFormTitle($params['formTitle'], $params['formHash']),
127+
'circle' => $this->getRichCircle($params['circleId'])
128+
],
129+
ActivityConstants::SUBJECT_NEWSUBMISSION => [
130+
'user' => $this->getRichUser($l10n, $params['userId']),
131+
'formTitle' => $this->getRichFormTitle($params['formTitle'], $params['formHash'], 'results')
132+
],
133+
default => [],
134+
};
142135
}
143136

144137
/**
@@ -148,7 +141,7 @@ public function getRichParams(IL10N $l10n, string $subject, array $params): arra
148141
*/
149142
public function getRichUser(IL10N $l10n, string $userId): array {
150143
// Special handling for anonyomous users
151-
if (substr($userId, 0, 10) === 'anon-user-') {
144+
if (str_starts_with($userId, 'anon-user-')) {
152145
return [
153146
'type' => 'highlight',
154147
'id' => $userId,
@@ -198,7 +191,7 @@ public function getRichGroup(string $groupId): array {
198191
/**
199192
* Turn a circleId into a rich-circle array.
200193
*
201-
* @param string $groupId
194+
* @param string $circleId
202195
* @return array
203196
*/
204197
public function getRichCircle(string $circleId): array {
@@ -240,7 +233,7 @@ public function getRichFormTitle(string $formTitle, string $formHash, string $ro
240233
if ($route !== '') {
241234
$formLink .= '/' . $route;
242235
}
243-
} catch (IMapperException $e) {
236+
} catch (IMapperException) {
244237
// Ignore if not found, just use stored title
245238
}
246239

@@ -260,14 +253,10 @@ public function getRichFormTitle(string $formTitle, string $formHash, string $ro
260253
* @return string
261254
*/
262255
public function getEventIcon(string $subject): string {
263-
switch ($subject) {
264-
case ActivityConstants::SUBJECT_NEWSHARE:
265-
case ActivityConstants::SUBJECT_NEWGROUPSHARE:
266-
return $this->urlGenerator->getAbsoluteURL($this->urlGenerator->imagePath('core', 'actions/shared.svg'));
267-
case ActivityConstants::SUBJECT_NEWSUBMISSION:
268-
return $this->urlGenerator->getAbsoluteURL($this->urlGenerator->imagePath('core', 'actions/add.svg'));
269-
default:
270-
return $this->urlGenerator->getAbsoluteURL($this->urlGenerator->imagePath('forms', 'forms-dark.svg'));
271-
}
256+
return match ($subject) {
257+
ActivityConstants::SUBJECT_NEWSHARE, ActivityConstants::SUBJECT_NEWGROUPSHARE => $this->urlGenerator->getAbsoluteURL($this->urlGenerator->imagePath('core', 'actions/shared.svg')),
258+
ActivityConstants::SUBJECT_NEWSUBMISSION => $this->urlGenerator->getAbsoluteURL($this->urlGenerator->imagePath('core', 'actions/add.svg')),
259+
default => $this->urlGenerator->getAbsoluteURL($this->urlGenerator->imagePath('forms', 'forms-dark.svg')),
260+
};
272261
}
273262
}

lib/Analytics/AnalyticsDatasource.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ class AnalyticsDatasource implements IDatasource {
1818

1919
public function __construct(
2020
protected ?string $userId,
21-
private IL10N $l10n,
22-
private FormMapper $formMapper,
23-
private FormsService $formsService,
24-
private SubmissionService $submissionService,
21+
private readonly IL10N $l10n,
22+
private readonly FormMapper $formMapper,
23+
private readonly FormsService $formsService,
24+
private readonly SubmissionService $submissionService,
2525
) {
2626
}
2727

lib/BackgroundJob/CleanupUploadedFilesJob.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ class CleanupUploadedFilesJob extends TimedJob {
2121
private const FILE_LIFETIME = '-1 hour';
2222

2323
public function __construct(
24-
private IRootFolder $rootFolder,
25-
private FormMapper $formMapper,
26-
private UploadedFileMapper $uploadedFileMapper,
27-
private LoggerInterface $logger,
24+
private readonly IRootFolder $rootFolder,
25+
private readonly FormMapper $formMapper,
26+
private readonly UploadedFileMapper $uploadedFileMapper,
27+
private readonly LoggerInterface $logger,
2828
ITimeFactory $time,
2929
) {
3030
parent::__construct($time);

lib/BackgroundJob/DeleteQuestionFoldersJob.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
class DeleteQuestionFoldersJob extends QueuedJob {
1818
public function __construct(
1919
ITimeFactory $time,
20-
private FilePathHelper $filePathHelper,
21-
private LoggerInterface $logger,
20+
private readonly FilePathHelper $filePathHelper,
21+
private readonly LoggerInterface $logger,
2222
) {
2323
parent::__construct($time);
2424
}
@@ -56,7 +56,7 @@ public function run($argument): void {
5656
continue;
5757
}
5858
foreach ($submissionFolder->getDirectoryListing() as $questionFolder) {
59-
if (str_starts_with($questionFolder->getName(), $questionFolderPrefix)) {
59+
if (str_starts_with((string)$questionFolder->getName(), $questionFolderPrefix)) {
6060
$questionFolder->delete();
6161
$deletedCount++;
6262
}

lib/BackgroundJob/SendConfirmationMailJob.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@
1818
class SendConfirmationMailJob extends QueuedJob {
1919
public function __construct(
2020
ITimeFactory $time,
21-
private IMailer $mailer,
22-
private LoggerInterface $logger,
23-
private Defaults $defaults,
21+
private readonly IMailer $mailer,
22+
private readonly LoggerInterface $logger,
23+
private readonly Defaults $defaults,
2424
) {
2525
parent::__construct($time);
2626
}

lib/BackgroundJob/SyncSubmissionsWithLinkedFileJob.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@ class SyncSubmissionsWithLinkedFileJob extends QueuedJob {
2424

2525
public function __construct(
2626
ITimeFactory $time,
27-
private FormMapper $formMapper,
28-
private FormsService $formsService,
29-
private SubmissionService $submissionService,
30-
private LoggerInterface $logger,
31-
private IUserManager $userManager,
32-
private IUserSession $userSession,
33-
private IJobList $jobList,
27+
private readonly FormMapper $formMapper,
28+
private readonly FormsService $formsService,
29+
private readonly SubmissionService $submissionService,
30+
private readonly LoggerInterface $logger,
31+
private readonly IUserManager $userManager,
32+
private readonly IUserSession $userSession,
33+
private readonly IJobList $jobList,
3434
) {
3535
parent::__construct($time);
3636
}
@@ -54,7 +54,7 @@ public function run($argument): void {
5454
$filePath = $this->formsService->getFilePath($form);
5555

5656
$this->submissionService->writeFileToCloud($form, $filePath, $fileFormat, $ownerId);
57-
} catch (NotFoundException $e) {
57+
} catch (NotFoundException) {
5858
$this->logger->notice('Form {formId} linked to a file that doesn\'t exist anymore', [
5959
'formId' => $formId
6060
]);
@@ -85,6 +85,6 @@ public function run($argument): void {
8585
* Calculates exponential delay (cubic growth) in seconds.
8686
*/
8787
private function nextAttempt(int $numberOfAttempt): int {
88-
return $this->time->getTime() + pow($numberOfAttempt, 3) * 60;
88+
return $this->time->getTime() + $numberOfAttempt ** 3 * 60;
8989
}
9090
}

lib/BackgroundJob/UserDeletedJob.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@
1515
class UserDeletedJob extends QueuedJob {
1616

1717
public function __construct(
18-
private FormMapper $formMapper,
18+
private readonly FormMapper $formMapper,
1919
ITimeFactory $time,
20-
private LoggerInterface $logger,
20+
private readonly LoggerInterface $logger,
2121
) {
2222
parent::__construct($time);
2323
}

0 commit comments

Comments
 (0)