Skip to content

Commit f52c226

Browse files
authored
Merge pull request #1487 from nextcloud/strictTypesProm
refactor: Strict types and property promotions
2 parents b2113cc + 62f7cdb commit f52c226

30 files changed

Lines changed: 137 additions & 162 deletions

lib/AppConfigOverwrite.php

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?php
22

33
declare(strict_types=1);
4+
45
/**
56
* SPDX-FileCopyrightText: 2019 Nextcloud GmbH and Nextcloud contributors
67
* SPDX-License-Identifier: AGPL-3.0-or-later
@@ -11,22 +12,17 @@
1112
use OC\AppConfig;
1213

1314
class AppConfigOverwrite extends AppConfig {
14-
1515
/** @var string[][] */
1616
private array $overWrite = [];
1717

18+
/**
19+
* @param string[][] $overwrite
20+
*/
1821
public function setOverwrite(array $overwrite): void {
1922
$this->overWrite = $overwrite;
2023
}
2124

22-
23-
/**
24-
* @param $app
25-
* @param $key
26-
* @param $default
27-
* @return string
28-
*/
29-
public function getValue($app, $key, $default = '') {
25+
public function getValue($app, $key, $default = ''): string {
3026
if (isset($this->overWrite[$app]) && isset($this->overWrite[$app][$key])) {
3127
return $this->overWrite[$app][$key];
3228
}

lib/AppWhitelist.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
/**
46
* SPDX-FileCopyrightText: 2017-2024 Nextcloud GmbH and Nextcloud contributors
57
* SPDX-FileCopyrightText: 2017 ownCloud GmbH
@@ -29,9 +31,6 @@ class AppWhitelist {
2931

3032
public const DEFAULT_WHITELIST = 'files_trashbin,files_versions,files_sharing,files_texteditor,text,activity,firstrunwizard,photos,notifications,dashboard,user_status,weather_status';
3133

32-
/**
33-
* AppWhitelist constructor.
34-
*/
3534
public function __construct(
3635
IURLGenerator $urlGenerator,
3736
private readonly Config $config,
@@ -70,9 +69,9 @@ public function isUrlAllowed(IUser $user, string|false $url): bool {
7069
$this->logger->notice("Blocking access to non-whitelisted app ($app) for guest", ['app' => 'guests']);
7170
return false;
7271
}
73-
} else {
74-
return true;
7572
}
73+
74+
return true;
7675
}
7776

7877
public function verifyAccess(IUser $user, IRequest $request): void {
@@ -130,6 +129,9 @@ private function getRequestedApp(string|false $url): string {
130129
return 'core';
131130
}
132131

132+
/**
133+
* @return list<string>
134+
*/
133135
public function getWhitelistAbleApps(): array {
134136
return array_values(array_diff(
135137
$this->appManager->getInstalledApps(),

lib/BackgroundJob/TransferJob.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ private function notifyFailure(Transfer $transfer): void {
4848
'source' => $transfer->getSource(),
4949
'target' => $transfer->getTarget(),
5050
]);
51+
5152
$this->notificationManager->notify($notification);
5253
}
5354

@@ -63,13 +64,14 @@ private function notifySuccess(Transfer $transfer): void {
6364
'source' => $transfer->getSource(),
6465
'target' => $transfer->getTarget(),
6566
]);
67+
6668
$this->notificationManager->notify($notification);
6769
}
6870

6971
private function fail(Transfer $transfer, ?IUser $targetUser = null): void {
7072
$this->notifyFailure($transfer);
7173
$this->transferMapper->delete($transfer);
72-
if (!($targetUser instanceof IUser)) {
74+
if (!$targetUser instanceof IUser) {
7375
return;
7476
}
7577
$result = $targetUser->delete(); // Rollback created user
@@ -90,7 +92,7 @@ public function run($argument): void {
9092
$target = $transfer->getTarget();
9193

9294
$sourceUser = $this->userManager->get($source);
93-
if (!($sourceUser instanceof IUser)) {
95+
if (!$sourceUser instanceof IUser) {
9496
$this->logger->error('Failed to transfer missing guest user: ' . $source);
9597
$this->fail($transfer);
9698
return;
@@ -107,7 +109,7 @@ public function run($argument): void {
107109
$this->secureRandom->generate(20), // Password hash will be copied to target user from source user
108110
);
109111

110-
if (!($targetUser instanceof IUser)) {
112+
if (!$targetUser instanceof IUser) {
111113
$this->logger->error('Failed to create new user: ' . $target);
112114
$this->fail($transfer);
113115
return;
@@ -141,6 +143,7 @@ public function run($argument): void {
141143
if (!$result) {
142144
$this->logger->error('Failed to delete guest user', ['user' => $sourceUser->getUID()]);
143145
}
146+
144147
$this->notifySuccess($transfer);
145148
$this->transferMapper->delete($transfer);
146149
}

lib/Capabilities.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
/**
46
* SPDX-FileCopyrightText: 2022 Nextcloud GmbH and Nextcloud contributors
57
* SPDX-License-Identifier: AGPL-3.0-or-later

lib/Command/AddCommand.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?php
22

33
declare(strict_types=1);
4+
45
/**
56
* SPDX-FileCopyrightText: 2020 Nextcloud GmbH and Nextcloud contributors
67
* SPDX-License-Identifier: AGPL-3.0-or-later

lib/Config.php

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?php
22

33
declare(strict_types=1);
4+
45
/**
56
* SPDX-FileCopyrightText: 2019 Nextcloud GmbH and Nextcloud contributors
67
* SPDX-License-Identifier: AGPL-3.0-or-later
@@ -28,21 +29,15 @@ public function allowExternalStorage(): bool {
2829
return $this->appConfig->getAppValueBool('allow_external_storage', false);
2930
}
3031

31-
/**
32-
* @param string|bool $allow
33-
*/
34-
public function setAllowExternalStorage($allow): void {
32+
public function setAllowExternalStorage(string|bool $allow): void {
3533
$this->appConfig->setAppValueBool('allow_external_storage', $allow === true || $allow === 'true') ;
3634
}
3735

3836
public function hideOtherUsers(): bool {
3937
return $this->appConfig->getAppValueBool('hide_users', true);
4038
}
4139

42-
/**
43-
* @param string|bool $hide
44-
*/
45-
public function setHideOtherUsers($hide): void {
40+
public function setHideOtherUsers(string|bool $hide): void {
4641
$this->appConfig->setAppValueBool('hide_users', $hide === true || $hide === 'true') ;
4742
}
4843

@@ -54,25 +49,19 @@ public function useWhitelist(): bool {
5449
return $this->appConfig->getAppValueBool('usewhitelist', true);
5550
}
5651

57-
/**
58-
* @param string|bool $use
59-
*/
60-
public function setUseWhitelist($use): void {
52+
public function setUseWhitelist(string|bool $use): void {
6153
$this->appConfig->setAppValueBool('usewhitelist', $use === true || $use === 'true') ;
6254
}
6355

6456
/**
65-
* @return string[]
57+
* @return list<string>
6658
*/
6759
public function getAppWhitelist(): array {
6860
$whitelist = $this->appConfig->getAppValueString('whitelist', AppWhitelist::DEFAULT_WHITELIST);
6961
return explode(',', $whitelist);
7062
}
7163

72-
/**
73-
* @param array|string $whitelist
74-
*/
75-
public function setAppWhitelist($whitelist): void {
64+
public function setAppWhitelist(array|string $whitelist): void {
7665
if (is_array($whitelist)) {
7766
$whitelist = implode(',', $whitelist);
7867
}
@@ -106,12 +95,11 @@ public function canCreateGuests(): bool {
10695
}
10796
}
10897

109-
11098
return !$this->isSharingRestrictedToGroup();
11199
}
112100

113101
/**
114-
* @return string[]
102+
* @return list<string>
115103
*/
116104
public function getCreateRestrictedToGroup(): array {
117105
$groups = $this->appConfig->getAppValueArray('create_restricted_to_group', []);
@@ -127,7 +115,7 @@ public function getCreateRestrictedToGroup(): array {
127115
}
128116

129117
/**
130-
* @param string[] $groups
118+
* @param list<string> $groups
131119
*/
132120
public function setCreateRestrictedToGroup(array $groups): void {
133121
$this->appConfig->setAppValueArray('create_restricted_to_group', $groups);

lib/Controller/APIController.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?php
22

33
declare(strict_types=1);
4+
45
/**
56
* SPDX-FileCopyrightText: 2020 Nextcloud GmbH and Nextcloud contributors
67
* SPDX-License-Identifier: AGPL-3.0-or-later
@@ -44,7 +45,7 @@ public function languages(): DataResponse {
4445
$l = $this->l10nFactory->get('lib', $lang);
4546
// TRANSLATORS this is the language name for the language switcher in the personal settings and should be the localized version
4647
$potentialName = $l->t('__language_name__');
47-
if ($l->getLanguageCode() === $lang && $potentialName[0] !== '_') {//first check if the language name is in the translation file
48+
if ($l->getLanguageCode() === $lang && $potentialName[0] !== '_') { // first check if the language name is in the translation file
4849
$ln = [
4950
'code' => $lang,
5051
'name' => $potentialName,
@@ -54,14 +55,14 @@ public function languages(): DataResponse {
5455
'code' => $lang,
5556
'name' => 'English (US)',
5657
];
57-
} else {//fallback to language code
58+
} else { // fallback to language code
5859
$ln = [
5960
'code' => $lang,
6061
'name' => $lang,
6162
];
6263
}
6364

64-
// put appropriate languages into appropriate arrays, to print them sorted
65+
// Put appropriate languages into appropriate arrays, to print them sorted
6566
// common languages -> divider -> other languages
6667
if (in_array($lang, Factory::COMMON_LANGUAGE_CODES)) {
6768
$commonLanguages[array_search($lang, Factory::COMMON_LANGUAGE_CODES)] = $ln;

lib/Controller/SettingsController.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
/**
46
* SPDX-FileCopyrightText: 2017-2024 Nextcloud GmbH and Nextcloud contributors
57
* SPDX-FileCopyrightText: 2017 ownCloud GmbH
@@ -41,6 +43,7 @@ public function getConfig(): DataResponse {
4143
$allowExternalStorage = $this->config->allowExternalStorage();
4244
$hideUsers = $this->config->hideOtherUsers();
4345
$whitelist = $this->config->getAppWhitelist();
46+
4447
return new DataResponse([
4548
'useWhitelist' => $useWhitelist,
4649
'whitelist' => $whitelist,
@@ -53,21 +56,20 @@ public function getConfig(): DataResponse {
5356
}
5457

5558
/**
56-
* @param $useWhitelist bool
57-
* @param $whitelist string[]
58-
* @param $allowExternalStorage bool
59-
* @param $hideUsers bool
59+
* @param list<string> $whitelist
6060
*/
6161
public function setConfig(bool $useWhitelist, array $whitelist, bool $allowExternalStorage, bool $hideUsers, array $createRestrictedToGroup): DataResponse {
6262
$newWhitelist = [];
6363
foreach ($whitelist as $app) {
6464
$newWhitelist[] = trim((string)$app);
6565
}
66+
6667
$this->config->setUseWhitelist($useWhitelist);
6768
$this->config->setAppWhitelist($newWhitelist);
6869
$this->config->setAllowExternalStorage($allowExternalStorage);
6970
$this->config->setHideOtherUsers($hideUsers);
7071
$this->config->setCreateRestrictedToGroup($createRestrictedToGroup);
72+
7173
return new DataResponse();
7274
}
7375

@@ -81,6 +83,7 @@ public function setConfig(bool $useWhitelist, array $whitelist, bool $allowExter
8183
public function getWhitelist(): DataResponse {
8284
$useWhitelist = $this->config->useWhitelist();
8385
$whitelist = $this->config->getAppWhitelist();
86+
8487
return new DataResponse([
8588
'useWhitelist' => $useWhitelist,
8689
'whitelist' => $whitelist,
@@ -94,6 +97,7 @@ public function getWhitelist(): DataResponse {
9497
*/
9598
public function resetWhitelist(): DataResponse {
9699
$this->config->setAppWhitelist(AppWhitelist::DEFAULT_WHITELIST);
100+
97101
return new DataResponse([
98102
'whitelist' => explode(',', AppWhitelist::DEFAULT_WHITELIST),
99103
]);

lib/Controller/UsersController.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,7 @@ public function transfer(string $guestUserId, string $targetUserId): DataRespons
226226
}
227227

228228
$this->transferService->addTransferJob($author, $sourceUser, $targetUserId);
229+
229230
return new DataResponse([], Http::STATUS_CREATED);
230231
}
231232
}

lib/Db/Transfer.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,13 @@ class Transfer extends Entity {
3030

3131
/** @var string */
3232
protected $author;
33+
3334
/** @var string */
3435
protected $source;
36+
3537
/** @var string */
3638
protected $target;
39+
3740
/** @var string */
3841
protected $status;
3942

0 commit comments

Comments
 (0)