From 8b06fe31011f9ff16f4dab60139a66f5c6f8333a Mon Sep 17 00:00:00 2001 From: nextcloud-command Date: Sun, 21 Jun 2026 15:17:22 +0000 Subject: [PATCH] refactor: Apply rector changes Signed-off-by: GitHub --- .../Federation/CalendarFederationConfig.php | 3 +- .../CalendarDelegateActionListener.php | 3 +- .../lib/FederatedShareProvider.php | 3 +- .../OCM/CloudFederationProviderFilesTest.php | 5 +-- apps/files_sharing/lib/External/Storage.php | 5 +-- .../Controller/AuthSettingsControllerTest.php | 3 +- apps/user_ldap/tests/User_LDAPTest.php | 33 ++++++++++--------- index.php | 2 +- lib/private/Files/Storage/DAV.php | 2 +- lib/private/Memcache/Memcached.php | 3 +- lib/private/Memcache/Redis.php | 2 +- lib/private/TaskProcessing/Manager.php | 5 +-- lib/private/legacy/OC_Util.php | 2 +- tests/Core/Command/User/LastSeenTest.php | 4 +-- tests/lib/BackgroundJob/DummyJob.php | 2 ++ tests/lib/OCM/OCMSignatoryManagerJwksTest.php | 3 +- .../OCM/OCMSignatoryManagerRotationTest.php | 5 +-- 17 files changed, 49 insertions(+), 36 deletions(-) diff --git a/apps/dav/lib/CalDAV/Federation/CalendarFederationConfig.php b/apps/dav/lib/CalDAV/Federation/CalendarFederationConfig.php index cfbbbe029e6de..c9d1e77dff2a4 100644 --- a/apps/dav/lib/CalDAV/Federation/CalendarFederationConfig.php +++ b/apps/dav/lib/CalDAV/Federation/CalendarFederationConfig.php @@ -9,12 +9,13 @@ namespace OCA\DAV\CalDAV\Federation; +use OCP\GlobalScale\IConfig; use OCP\IAppConfig; class CalendarFederationConfig { public function __construct( private readonly IAppConfig $appConfig, - private \OCP\GlobalScale\IConfig $gsConfig, + private IConfig $gsConfig, ) { } diff --git a/apps/dav/lib/Listener/CalendarDelegateActionListener.php b/apps/dav/lib/Listener/CalendarDelegateActionListener.php index 475f2fcd3ee35..eaa4d2861633e 100644 --- a/apps/dav/lib/Listener/CalendarDelegateActionListener.php +++ b/apps/dav/lib/Listener/CalendarDelegateActionListener.php @@ -18,6 +18,7 @@ use OCP\Calendar\Events\CalendarObjectUpdatedEvent; use OCP\EventDispatcher\Event; use OCP\EventDispatcher\IEventListener; +use OCP\IL10N; use OCP\IUser; use OCP\IUserManager; use OCP\IUserSession; @@ -210,7 +211,7 @@ private function sendNotification( /** * @return array{0: string, 1: string} [subject, heading] */ - private function subjectAndHeading(\OCP\IL10N $l, string $action, string $actorName, string $summary, string $calendarName): array { + private function subjectAndHeading(IL10N $l, string $action, string $actorName, string $summary, string $calendarName): array { return match ($action) { self::ACTION_CREATE => [ $l->t('%1$s created "%2$s" on your behalf', [$actorName, $summary]), diff --git a/apps/federatedfilesharing/lib/FederatedShareProvider.php b/apps/federatedfilesharing/lib/FederatedShareProvider.php index 63751fe26b06d..84d329e4f93c5 100644 --- a/apps/federatedfilesharing/lib/FederatedShareProvider.php +++ b/apps/federatedfilesharing/lib/FederatedShareProvider.php @@ -12,6 +12,7 @@ use OC\Share20\Exception\InvalidShare; use OC\Share20\Share; use OCA\CloudFederationAPI\Db\OcmTokenMapMapper; +use OCP\AppFramework\Db\DoesNotExistException; use OCP\Authentication\Exceptions\InvalidTokenException; use OCP\Authentication\Token\IToken; use OCP\Constants; @@ -749,7 +750,7 @@ public function getShareByToken(string $token): IShare { ->executeQuery(); $data = $cursor->fetch(); - } catch (InvalidTokenException|\OCP\AppFramework\Db\DoesNotExistException) { + } catch (InvalidTokenException|DoesNotExistException) { // Token is not a valid access token or has no mapping, share not found } } diff --git a/apps/federatedfilesharing/tests/OCM/CloudFederationProviderFilesTest.php b/apps/federatedfilesharing/tests/OCM/CloudFederationProviderFilesTest.php index be482490e9d10..d2e540849ce4e 100644 --- a/apps/federatedfilesharing/tests/OCM/CloudFederationProviderFilesTest.php +++ b/apps/federatedfilesharing/tests/OCM/CloudFederationProviderFilesTest.php @@ -24,6 +24,7 @@ use OCP\Federation\ICloudIdManager; use OCP\Files\IFilenameValidator; use OCP\Files\ISetupManager; +use OCP\Http\Client\IClient; use OCP\Http\Client\IClientService; use OCP\Http\Client\IResponse; use OCP\IAppConfig; @@ -261,7 +262,7 @@ public function testShareReceivedMustExchangeTokenStoresAccessToken(): void { 'token_type' => 'Bearer', ])); - $httpClient = $this->createMock(\OCP\Http\Client\IClient::class); + $httpClient = $this->createMock(IClient::class); $httpClient->method('post')->willReturn($response); $this->clientService->method('newClient')->willReturn($httpClient); @@ -343,7 +344,7 @@ public function testShareReceivedOptionalExchangeStoresAccessTokenOnSuccess(): v 'token_type' => 'Bearer', ])); - $httpClient = $this->createMock(\OCP\Http\Client\IClient::class); + $httpClient = $this->createMock(IClient::class); $httpClient->method('post')->willReturn($response); $this->clientService->method('newClient')->willReturn($httpClient); diff --git a/apps/files_sharing/lib/External/Storage.php b/apps/files_sharing/lib/External/Storage.php index d52e9945f0b0a..f1d1cef262546 100644 --- a/apps/files_sharing/lib/External/Storage.php +++ b/apps/files_sharing/lib/External/Storage.php @@ -12,6 +12,7 @@ use GuzzleHttp\Exception\ClientException; use GuzzleHttp\Exception\ConnectException; use GuzzleHttp\Exception\RequestException; +use OC\Files\Storage\BearerAuthAwareSabreClient; use OC\Files\Storage\DAV; use OC\ForbiddenException; use OC\Share\Share; @@ -95,7 +96,7 @@ public function __construct($options) { // Shares created before the exchange-token capability was introduced have no // stored token and must keep using basic auth for backwards compatibility. if (!empty($options['access_token'])) { - $authType = \OC\Files\Storage\BearerAuthAwareSabreClient::AUTH_BEARER; + $authType = BearerAuthAwareSabreClient::AUTH_BEARER; } $host = parse_url($remote, PHP_URL_HOST); @@ -130,7 +131,7 @@ public function __construct($options) { 'root' => $webDavEndpoint, 'user' => $options['token'], 'authType' => $authType, - 'password' => $authType === \OC\Files\Storage\BearerAuthAwareSabreClient::AUTH_BEARER + 'password' => $authType === BearerAuthAwareSabreClient::AUTH_BEARER ? (string)($options['access_token'] ?? '') : (string)($options['password'] ?? ''), 'discoveryService' => $discoveryService, diff --git a/apps/settings/tests/Controller/AuthSettingsControllerTest.php b/apps/settings/tests/Controller/AuthSettingsControllerTest.php index c2e20fdf8ad98..f3503e3c2d7f3 100644 --- a/apps/settings/tests/Controller/AuthSettingsControllerTest.php +++ b/apps/settings/tests/Controller/AuthSettingsControllerTest.php @@ -21,6 +21,7 @@ use OCP\Activity\IManager; use OCP\AppFramework\Http\JSONResponse; use OCP\AppFramework\Services\IAppConfig; +use OCP\Authentication\Exceptions\WipeTokenException; use OCP\IConfig; use OCP\IL10N; use OCP\IRequest; @@ -243,7 +244,7 @@ public function testDestroyWipePendingEmitsCancelledSubject(): void { $this->tokenProvider->expects($this->once()) ->method('getTokenById') ->with($tokenId) - ->willThrowException(new \OCP\Authentication\Exceptions\WipeTokenException($token)); + ->willThrowException(new WipeTokenException($token)); // The token is still invalidated (the user opted into cancelling the wipe). $this->tokenProvider->expects($this->once()) diff --git a/apps/user_ldap/tests/User_LDAPTest.php b/apps/user_ldap/tests/User_LDAPTest.php index 325f109ee6c50..b87b5fde55dec 100644 --- a/apps/user_ldap/tests/User_LDAPTest.php +++ b/apps/user_ldap/tests/User_LDAPTest.php @@ -21,6 +21,7 @@ use OCA\User_LDAP\User\User; use OCA\User_LDAP\User_LDAP; use OCA\User_LDAP\UserPluginManager; +use OCP\Accounts\IAccountManager; use OCP\HintException; use OCP\IConfig; use OCP\IGroupManager; @@ -1464,24 +1465,24 @@ public function testImplementsAction(string $configurable, string|int $value, in public static function canEditPropertyProvider(): array { return [ // Display name is always managed by LDAP - [\OCP\Accounts\IAccountManager::PROPERTY_DISPLAYNAME, '', false], - [\OCP\Accounts\IAccountManager::PROPERTY_DISPLAYNAME, 'cn', false], + [IAccountManager::PROPERTY_DISPLAYNAME, '', false], + [IAccountManager::PROPERTY_DISPLAYNAME, 'cn', false], // Fields with no LDAP attribute configured are user-editable - [\OCP\Accounts\IAccountManager::PROPERTY_EMAIL, '', true], - [\OCP\Accounts\IAccountManager::PROPERTY_PHONE, '', true], - [\OCP\Accounts\IAccountManager::PROPERTY_WEBSITE, '', true], - [\OCP\Accounts\IAccountManager::PROPERTY_ADDRESS, '', true], - [\OCP\Accounts\IAccountManager::PROPERTY_FEDIVERSE, '', true], - [\OCP\Accounts\IAccountManager::PROPERTY_ORGANISATION, '', true], - [\OCP\Accounts\IAccountManager::PROPERTY_ROLE, '', true], - [\OCP\Accounts\IAccountManager::PROPERTY_HEADLINE, '', true], - [\OCP\Accounts\IAccountManager::PROPERTY_BIOGRAPHY, '', true], - [\OCP\Accounts\IAccountManager::PROPERTY_BIRTHDATE, '', true], - [\OCP\Accounts\IAccountManager::PROPERTY_PRONOUNS, '', true], + [IAccountManager::PROPERTY_EMAIL, '', true], + [IAccountManager::PROPERTY_PHONE, '', true], + [IAccountManager::PROPERTY_WEBSITE, '', true], + [IAccountManager::PROPERTY_ADDRESS, '', true], + [IAccountManager::PROPERTY_FEDIVERSE, '', true], + [IAccountManager::PROPERTY_ORGANISATION, '', true], + [IAccountManager::PROPERTY_ROLE, '', true], + [IAccountManager::PROPERTY_HEADLINE, '', true], + [IAccountManager::PROPERTY_BIOGRAPHY, '', true], + [IAccountManager::PROPERTY_BIRTHDATE, '', true], + [IAccountManager::PROPERTY_PRONOUNS, '', true], // Fields with an LDAP attribute configured are managed by LDAP, not user-editable - [\OCP\Accounts\IAccountManager::PROPERTY_EMAIL, 'mail', false], - [\OCP\Accounts\IAccountManager::PROPERTY_PHONE, 'telephoneNumber', false], - [\OCP\Accounts\IAccountManager::PROPERTY_WEBSITE, 'labeledURI', false], + [IAccountManager::PROPERTY_EMAIL, 'mail', false], + [IAccountManager::PROPERTY_PHONE, 'telephoneNumber', false], + [IAccountManager::PROPERTY_WEBSITE, 'labeledURI', false], ]; } diff --git a/index.php b/index.php index d4bdd263f79f3..cb59b75b3f7ec 100644 --- a/index.php +++ b/index.php @@ -36,7 +36,7 @@ function resetStaticProperties(): void { Filesystem::reset(); } -$handler = static function () { +$handler = static function (): void { try { resetStaticProperties(); OC::init(); diff --git a/lib/private/Files/Storage/DAV.php b/lib/private/Files/Storage/DAV.php index 08ee02eef4473..efcceba7e6892 100644 --- a/lib/private/Files/Storage/DAV.php +++ b/lib/private/Files/Storage/DAV.php @@ -822,7 +822,7 @@ protected function uploadFile(string $path, string $target): void { $target = $this->cleanPath($target); $this->statCache->remove($target); - $this->withAuthRetry(function () use ($path, $target) { + $this->withAuthRetry(function () use ($path, $target): void { $source = fopen($path, 'r'); $auth = [$this->user, $this->password]; $headers = []; diff --git a/lib/private/Memcache/Memcached.php b/lib/private/Memcache/Memcached.php index b67b0a90a4f6a..6a78eaa648174 100644 --- a/lib/private/Memcache/Memcached.php +++ b/lib/private/Memcache/Memcached.php @@ -9,6 +9,7 @@ namespace OC\Memcache; use OCP\IMemcache; +use OCP\Server; class Memcached extends Cache implements IMemcache { use CASTrait; @@ -19,7 +20,7 @@ class Memcached extends Cache implements IMemcache { public function __construct($prefix = '') { parent::__construct($prefix); - $this->cache = \OCP\Server::get(MemcachedFactory::class)->getInstance(); + $this->cache = Server::get(MemcachedFactory::class)->getInstance(); } /** diff --git a/lib/private/Memcache/Redis.php b/lib/private/Memcache/Redis.php index 3558264b52524..5bca6a225381f 100644 --- a/lib/private/Memcache/Redis.php +++ b/lib/private/Memcache/Redis.php @@ -50,7 +50,7 @@ public function __construct($prefix = '', string $logFile = '') { */ public function getCache(): \Redis|\RedisCluster { if ($this->cache === null) { - $this->cache = \OCP\Server::get(RedisFactory::class)->getInstance(); + $this->cache = Server::get(RedisFactory::class)->getInstance(); } return $this->cache; } diff --git a/lib/private/TaskProcessing/Manager.php b/lib/private/TaskProcessing/Manager.php index 9c1a305b1127c..48f859548e3d1 100644 --- a/lib/private/TaskProcessing/Manager.php +++ b/lib/private/TaskProcessing/Manager.php @@ -16,6 +16,7 @@ use OC\TaskProcessing\Db\TaskMapper; use OCA\AppAPI\PublicFunctions; use OCA\Guests\UserBackend; +use OCA\NotifyPush\Queue\IQueue; use OCP\App\IAppManager; use OCP\AppFramework\Db\DoesNotExistException; use OCP\AppFramework\Db\MultipleObjectsReturnedException; @@ -1193,7 +1194,7 @@ private function notifyTaskStatus(Task $task, int $status): void { ) { try { /** @psalm-suppress UndefinedClass */ - $queue = Server::get(\OCA\NotifyPush\Queue\IQueue::class); + $queue = Server::get(IQueue::class); /** @psalm-suppress UndefinedClass */ $queue->push('notify_custom', [ 'user' => $userId, @@ -1300,7 +1301,7 @@ public function setTaskIntermediateOutput(int $id, array $output): bool { ) { try { /** @psalm-suppress UndefinedClass */ - $queue = Server::get(\OCA\NotifyPush\Queue\IQueue::class); + $queue = Server::get(IQueue::class); /** @psalm-suppress UndefinedClass */ $queue->push('notify_custom', [ 'user' => $userId, diff --git a/lib/private/legacy/OC_Util.php b/lib/private/legacy/OC_Util.php index 3e4b7a7fe9d8b..7af1d24d669bd 100644 --- a/lib/private/legacy/OC_Util.php +++ b/lib/private/legacy/OC_Util.php @@ -261,7 +261,7 @@ public static function addHeader($tag, $attributes, $text = null, $prepend = fal * @return array arrays with error messages and hints */ public static function checkServer(SystemConfig $config) { - $l = \OCP\Server::get(IFactory::class)->get('lib'); + $l = Server::get(IFactory::class)->get('lib'); $errors = []; $CONFIG_DATADIRECTORY = $config->getValue('datadirectory', OC::$SERVERROOT . '/data'); diff --git a/tests/Core/Command/User/LastSeenTest.php b/tests/Core/Command/User/LastSeenTest.php index 8aa9147096478..e1deeb0d43efd 100644 --- a/tests/Core/Command/User/LastSeenTest.php +++ b/tests/Core/Command/User/LastSeenTest.php @@ -129,7 +129,7 @@ public function testAllUsersWithoutExcludeDisabled(): void { $this->userManager->expects($this->once()) ->method('callForAllUsers') - ->willReturnCallback(function ($callback) use ($enabledUser, $disabledUser) { + ->willReturnCallback(function ($callback) use ($enabledUser, $disabledUser): void { $callback($enabledUser); $callback($disabledUser); }); @@ -176,7 +176,7 @@ public function testAllUsersWithExcludeDisabled(): void { $this->userManager->expects($this->once()) ->method('callForAllUsers') - ->willReturnCallback(function ($callback) use ($enabledUser, $disabledUser) { + ->willReturnCallback(function ($callback) use ($enabledUser, $disabledUser): void { $callback($enabledUser); $callback($disabledUser); }); diff --git a/tests/lib/BackgroundJob/DummyJob.php b/tests/lib/BackgroundJob/DummyJob.php index cf8ab72d71ca9..332fc327fd911 100644 --- a/tests/lib/BackgroundJob/DummyJob.php +++ b/tests/lib/BackgroundJob/DummyJob.php @@ -1,5 +1,7 @@ clientService->method('newClient')->willReturn($this->client); $cacheFactory = $this->createMock(ICacheFactory::class); - $cacheFactory->method('createDistributed')->willReturn(new \OC\Memcache\ArrayCache('')); + $cacheFactory->method('createDistributed')->willReturn(new ArrayCache('')); $this->signatoryManager = new OCMSignatoryManager( $this->appConfig, diff --git a/tests/lib/OCM/OCMSignatoryManagerRotationTest.php b/tests/lib/OCM/OCMSignatoryManagerRotationTest.php index 24d25f4476a49..3c1d7038ee78c 100644 --- a/tests/lib/OCM/OCMSignatoryManagerRotationTest.php +++ b/tests/lib/OCM/OCMSignatoryManagerRotationTest.php @@ -9,6 +9,7 @@ namespace Test\OCM; +use OC\Memcache\ArrayCache; use OC\OCM\OCMSignatoryManager; use OC\Security\IdentityProof\Key; use OC\Security\IdentityProof\Manager as IdentityProofManager; @@ -50,7 +51,7 @@ protected function setUp(): void { ->willReturnCallback(static fn (string $suffix): string => 'https://alice.example/' . ltrim($suffix, '/')); $cacheFactory = $this->createMock(ICacheFactory::class); - $cacheFactory->method('createDistributed')->willReturn(new \OC\Memcache\ArrayCache('')); + $cacheFactory->method('createDistributed')->willReturn(new ArrayCache('')); $this->signatoryManager = new OCMSignatoryManager( $this->appConfig, @@ -194,7 +195,7 @@ public function testSignerReturnsNullWhenIdentityCannotBeDerived(): void { ->willThrowException(new IdentityNotFoundException('no url either')); $cacheFactory = $this->createMock(ICacheFactory::class); - $cacheFactory->method('createDistributed')->willReturn(new \OC\Memcache\ArrayCache('')); + $cacheFactory->method('createDistributed')->willReturn(new ArrayCache('')); $manager = new OCMSignatoryManager( $this->appConfig,