Skip to content

Commit 017c409

Browse files
committed
refactor(rector): Run with nextcloud set
Signed-off-by: Carl Schwan <carlschwan@kde.org>
1 parent 417a8e5 commit 017c409

23 files changed

Lines changed: 451 additions & 71 deletions

REUSE.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ SPDX-FileCopyrightText = "2018 Nextcloud GmbH and Nextcloud contributors"
3030
SPDX-License-Identifier = "AGPL-3.0-or-later"
3131

3232
[[annotations]]
33-
path = ["composer.json", "composer.lock"]
33+
path = ["composer.json", "composer.lock", "vendor-bin/*/composer.json", "vendor-bin/*/composer.lock"]
3434
precedence = "aggregate"
3535
SPDX-FileCopyrightText = "2019 Nextcloud GmbH and Nextcloud contributors"
3636
SPDX-License-Identifier = "AGPL-3.0-or-later"

lib/Controller/APIController.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
use OC\L10N\Factory;
1212
use OCA\Guests\AppInfo\Application;
13+
use OCA\Guests\Config;
1314
use OCP\AppFramework\Http\Attribute\NoAdminRequired;
1415
use OCP\AppFramework\Http\DataResponse;
1516
use OCP\AppFramework\OCSController;
@@ -24,7 +25,7 @@ class APIController extends OCSController {
2425
public function __construct(
2526
IRequest $request,
2627
private readonly IUserSession $userSession,
27-
private readonly \OCA\Guests\Config $config,
28+
private readonly Config $config,
2829
private readonly IFactory $l10nFactory,
2930
private readonly ISubAdmin $subAdmin,
3031
private readonly IGroupManager $groupManager,

lib/Controller/UsersController.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use OCA\Guests\TransferService;
1919
use OCP\AppFramework\Db\DoesNotExistException;
2020
use OCP\AppFramework\Http;
21+
use OCP\AppFramework\Http\Attribute\NoAdminRequired;
2122
use OCP\AppFramework\Http\DataResponse;
2223
use OCP\AppFramework\OCSController;
2324
use OCP\Group\ISubAdmin;
@@ -48,9 +49,7 @@ public function __construct(
4849
parent::__construct($appName, $request);
4950
}
5051

51-
/**
52-
* @NoAdminRequired
53-
*/
52+
#[NoAdminRequired]
5453
public function create(string $email, string $displayName, string $language, array $groups, bool $sendInvite = true): DataResponse {
5554
$errorMessages = [];
5655
$currentUser = $this->userSession->getUser();
@@ -208,7 +207,7 @@ public function transfer(string $guestUserId, string $targetUserId): DataRespons
208207

209208
try {
210209
$transfer = $this->transferMapper->getBySource($sourceUser->getUID());
211-
} catch (DoesNotExistException $e) {
210+
} catch (DoesNotExistException) {
212211
// Allow as this just means there is no pending transfer
213212
}
214213

lib/FilteredSettingsManager.php

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,21 @@
77

88
namespace OCA\Guests;
99

10+
use OC\AppFramework\App;
1011
use OCP\IUser;
1112
use OCP\Settings\IIconSection;
1213
use OCP\Settings\IManager;
1314

1415
class FilteredSettingsManager implements IManager {
1516

16-
/** @var IManager */
17-
private $manager;
18-
1917
public function __construct(
20-
IManager $manager,
21-
private readonly \OCA\Guests\AppWhitelist $appWhitelist,
18+
private readonly IManager $manager,
19+
private readonly AppWhitelist $appWhitelist,
2220
) {
23-
$this->manager = $manager;
2421
}
2522

2623
private function isSettingAllowed(string $setting): bool {
27-
$appId = \OC\AppFramework\App::getAppIdForClass($setting);
24+
$appId = App::getAppIdForClass($setting);
2825
return $this->appWhitelist->isAppWhitelisted($appId);
2926
}
3027

lib/GroupBackend.php

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,14 @@
2121
*/
2222
class GroupBackend extends ABackend implements ICountUsersBackend, IGroupDetailsBackend, IHideFromCollaborationBackend {
2323
/** @var string[] */
24-
private $guestMembers = [];
25-
26-
/** @var IUserSession */
27-
private $userSession;
24+
private array $guestMembers = [];
2825

2926
public function __construct(
30-
private readonly \OCA\Guests\GuestManager $guestManager,
31-
private readonly \OCA\Guests\Config $config,
32-
IUserSession $userSession,
27+
private readonly GuestManager $guestManager,
28+
private readonly Config $config,
29+
private readonly IUserSession $userSession,
3330
private readonly string $groupName = 'guest_app',
3431
) {
35-
$this->userSession = $userSession;
3632
}
3733

3834
private function getMembers(): array {

lib/Hooks.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public function setupReadonlyFilesystem(array $params): void {
8282
$user = $this->userManager->get($uid);
8383

8484
if ($user && $this->guestManager->isGuest($user)) {
85-
Filesystem::addStorageWrapper('guests.readonly', function ($mountPoint, IStorage $storage) use ($uid): \OCA\Guests\Storage\ReadOnlyJail|\OCP\Files\Storage\IStorage {
85+
Filesystem::addStorageWrapper('guests.readonly', function ($mountPoint, IStorage $storage) use ($uid): ReadOnlyJail|IStorage {
8686
if ($mountPoint === "/$uid/") {
8787
return new ReadOnlyJail([
8888
'storage' => $storage,

lib/Mail.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
use OCP\IUserSession;
1616
use OCP\L10N\IFactory;
1717
use OCP\Mail\IMailer;
18-
use OCP\Share;
18+
use OCP\Share\IShare;
1919
use OCP\Util;
2020

2121
class Mail {
@@ -37,7 +37,7 @@ public function __construct(
3737
* @param $uid
3838
* @throws \Exception
3939
*/
40-
public function sendGuestInviteMail(string $uid, string $guest, string $token, string $language = '', ?Share\IShare $share = null): void {
40+
public function sendGuestInviteMail(string $uid, string $guest, string $token, string $language = '', ?IShare $share = null): void {
4141
if ($language === '') {
4242
$language = null;
4343
}
@@ -56,7 +56,7 @@ public function sendGuestInviteMail(string $uid, string $guest, string $token, s
5656
$replyTo = $this->userManager->get($uid)->getEMailAddress();
5757
$senderDisplayName = $this->userSession->getUser()->getDisplayName();
5858

59-
if (!$share instanceof \OCP\Share\IShare) {
59+
if (!$share instanceof IShare) {
6060
[ $subject, $emailTemplate ] = $this->composeInviteMessage($senderDisplayName, $guestEmail, $passwordLink, $l10n);
6161
} else {
6262
[ $subject, $emailTemplate ] = $this->composeShareMessage($share, $senderDisplayName, $guestEmail, $passwordLink, $l10n);
@@ -88,7 +88,7 @@ public function sendGuestInviteMail(string $uid, string $guest, string $token, s
8888
}
8989
}
9090

91-
private function composeShareMessage(Share\IShare $share, string $senderDisplayName, string $guestEmail, string $passwordLink, IL10N $l10n): array {
91+
private function composeShareMessage(IShare $share, string $senderDisplayName, string $guestEmail, string $passwordLink, IL10N $l10n): array {
9292
$filename = trim($share->getTarget(), '/');
9393
$subject = $l10n->t('%s shared a file with you', [$senderDisplayName]);
9494
$expiration = $share->getExpirationDate();

lib/RestrictionManager.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@
1717
use OCP\IServerContainer;
1818
use OCP\IUser;
1919
use OCP\IUserSession;
20+
use OCP\Server;
2021
use OCP\Settings\IManager;
22+
use OCP\Util;
2123
use Psr\Log\LoggerInterface;
2224

2325
class RestrictionManager {
@@ -50,18 +52,18 @@ public function setupRestrictions(): void {
5052
}
5153

5254
if ($this->guestManager->isGuest($user)) {
53-
\OCP\Util::connectHook('OC_Filesystem', 'preSetup', $this->hooks, 'setupReadonlyFilesystem');
55+
Util::connectHook('OC_Filesystem', 'preSetup', $this->hooks, 'setupReadonlyFilesystem');
5456
if (!$this->config->allowExternalStorage()) {
5557
$this->mountProviderCollection->registerMountFilter(fn (IMountPoint $mountPoint, IUser $user): bool => !($mountPoint instanceof ExternalMountPoint && $this->guestManager->isGuest($user)));
5658
}
5759

5860
/** @var NavigationManager $navManager */
59-
$navManager = \OCP\Server::get(INavigationManager::class);
61+
$navManager = Server::get(INavigationManager::class);
6062

61-
$this->server->registerService(INavigationManager::class, fn (): \OCA\Guests\FilteredNavigationManager => new FilteredNavigationManager($user, $navManager, $this->whitelist));
63+
$this->server->registerService(INavigationManager::class, fn (): FilteredNavigationManager => new FilteredNavigationManager($user, $navManager, $this->whitelist));
6264

6365
$settingsManager = $this->server->get(IManager::class);
64-
$this->server->registerService(IManager::class, fn (): \OCA\Guests\FilteredSettingsManager => new FilteredSettingsManager($settingsManager, $this->whitelist));
66+
$this->server->registerService(IManager::class, fn (): FilteredSettingsManager => new FilteredSettingsManager($settingsManager, $this->whitelist));
6567
}
6668
}
6769

lib/Settings/Admin.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@
99
namespace OCA\Guests\Settings;
1010

1111
use OCP\AppFramework\Http\TemplateResponse;
12+
use OCP\Settings\ISettings;
1213
use OCP\Util;
1314

14-
class Admin implements \OCP\Settings\ISettings {
15+
class Admin implements ISettings {
1516
/**
1617
* {@inheritdoc}
1718
*/

lib/Storage/DirMask.php

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,20 +28,17 @@ class DirMask extends PermissionsMask {
2828
*/
2929
private readonly int $pathLength;
3030

31-
private $mask;
32-
3331
/**
34-
* @param array $arguments ['storage' => $storage, 'mask' => $mask, 'path' => $path]
32+
* @param array $parameters ['storage' => $storage, 'mask' => $mask, 'path' => $path]
3533
*
3634
* $storage: The storage the permissions mask should be applied on
3735
* $mask: The permission bits that should be kept, a combination of the \OCP\Constant::PERMISSION_ constants
3836
* $path: The path relative to the storage root that should be masked
3937
*/
40-
public function __construct($arguments) {
41-
parent::__construct($arguments);
42-
$this->path = rtrim((string)$arguments['path'], '/');
43-
$this->pathLength = strlen((string)$arguments['path']);
44-
$this->mask = $arguments['mask'];
38+
public function __construct($parameters) {
39+
parent::__construct($parameters);
40+
$this->path = rtrim((string)$parameters['path'], '/');
41+
$this->pathLength = strlen((string)$parameters['path']);
4542
}
4643

4744
protected function checkPath(string $path): bool {

0 commit comments

Comments
 (0)