diff --git a/apps/dav/appinfo/v1/carddav.php b/apps/dav/appinfo/v1/carddav.php index 5fe9f93d8b542..d883bae450bbb 100644 --- a/apps/dav/appinfo/v1/carddav.php +++ b/apps/dav/appinfo/v1/carddav.php @@ -89,7 +89,7 @@ /** @var string $baseuri defined in remote.php */ $server->setBaseUri($baseuri); // Add plugins -$server->addPlugin(new MaintenancePlugin(Server::get(IConfig::class), \OCP\Server::get(IL10nFactory::class)->get('dav'))); +$server->addPlugin(new MaintenancePlugin(Server::get(IConfig::class), Server::get(IL10nFactory::class)->get('dav'))); $server->addPlugin(new \Sabre\DAV\Auth\Plugin($authBackend)); $server->addPlugin(new Plugin()); diff --git a/apps/dav/lib/CalDAV/Federation/FederatedCalendarEntity.php b/apps/dav/lib/CalDAV/Federation/FederatedCalendarEntity.php index e6d869fec88b7..80cf5570d6512 100644 --- a/apps/dav/lib/CalDAV/Federation/FederatedCalendarEntity.php +++ b/apps/dav/lib/CalDAV/Federation/FederatedCalendarEntity.php @@ -11,6 +11,7 @@ use OCA\DAV\DAV\RemoteUserPrincipalBackend; use OCP\AppFramework\Db\Entity; +use OCP\Constants; use OCP\DB\Types; use Sabre\CalDAV\Xml\Property\SupportedCalendarComponentSet; @@ -94,7 +95,7 @@ public function toCalendarInfo(): array { '{' . \Sabre\CalDAV\Plugin::NS_CALENDARSERVER . '}getctag' => $this->getSyncTokenForSabre(), '{' . \Sabre\CalDAV\Plugin::NS_CALDAV . '}supported-calendar-component-set' => $this->getSupportedCalendarComponentSet(), '{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}owner-principal' => $this->getSharedByPrincipal(), - '{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}read-only' => ($this->getPermissions() & \OCP\Constants::PERMISSION_UPDATE) === 0 ? 1 : 0, + '{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}read-only' => ($this->getPermissions() & Constants::PERMISSION_UPDATE) === 0 ? 1 : 0, '{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}permissions' => $this->getPermissions(), ]; } diff --git a/apps/dav/lib/Connector/Sabre/Directory.php b/apps/dav/lib/Connector/Sabre/Directory.php index f4e8ee1d99a77..d0bde46e96de3 100644 --- a/apps/dav/lib/Connector/Sabre/Directory.php +++ b/apps/dav/lib/Connector/Sabre/Directory.php @@ -532,7 +532,7 @@ public function getNodeForPath($path): INode { } if ($info->getMimeType() === FileInfo::MIMETYPE_FOLDER) { - $node = new \OCA\DAV\Connector\Sabre\Directory($this->fileView, $info, $this->tree, $this->shareManager); + $node = new Directory($this->fileView, $info, $this->tree, $this->shareManager); } else { // In case reading a directory was allowed but it turns out the node was a not a directory, reject it now. if (!$this->info->isReadable()) { diff --git a/apps/dav/tests/unit/CalDAV/Schedule/IMipServiceTest.php b/apps/dav/tests/unit/CalDAV/Schedule/IMipServiceTest.php index 7d58930f0700b..5f9d6adfa737b 100644 --- a/apps/dav/tests/unit/CalDAV/Schedule/IMipServiceTest.php +++ b/apps/dav/tests/unit/CalDAV/Schedule/IMipServiceTest.php @@ -17,6 +17,7 @@ use OCP\IAppConfig; use OCP\IDBConnection; use OCP\IL10N; +use OCP\IUser; use OCP\IUserManager; use OCP\L10N\IFactory; use OCP\Security\ISecureRandom; @@ -163,7 +164,7 @@ public function testGetFrom(): void { public function testIsSystemUserWhenUserExists(): void { $email = 'user@example.com'; - $user = $this->createMock(\OCP\IUser::class); + $user = $this->createMock(IUser::class); $this->userManager->expects(self::once()) ->method('getByEmail') diff --git a/apps/federatedfilesharing/lib/AppInfo/Application.php b/apps/federatedfilesharing/lib/AppInfo/Application.php index b77c76acf5ac6..ca22ce2cbc649 100644 --- a/apps/federatedfilesharing/lib/AppInfo/Application.php +++ b/apps/federatedfilesharing/lib/AppInfo/Application.php @@ -17,6 +17,7 @@ use OCP\AppFramework\Bootstrap\IBootstrap; use OCP\AppFramework\Bootstrap\IRegistrationContext; use OCP\Federation\ICloudFederationProviderManager; +use OCP\Server; class Application extends App implements IBootstrap { @@ -41,7 +42,7 @@ private function registerCloudFederationProvider(ICloudFederationProviderManager $manager->addCloudFederationProvider($type, 'Federated Files Sharing', function (): CloudFederationProviderFiles { - return \OCP\Server::get(CloudFederationProviderFiles::class); + return Server::get(CloudFederationProviderFiles::class); }); } } diff --git a/apps/federatedfilesharing/lib/Settings/Admin.php b/apps/federatedfilesharing/lib/Settings/Admin.php index e66f1a1e41781..20b7ca62ad00d 100644 --- a/apps/federatedfilesharing/lib/Settings/Admin.php +++ b/apps/federatedfilesharing/lib/Settings/Admin.php @@ -14,6 +14,7 @@ use OCP\IL10N; use OCP\IURLGenerator; use OCP\Settings\IDelegatedSettings; +use OCP\Util; class Admin implements IDelegatedSettings { /** @@ -44,8 +45,8 @@ public function getForm() { $this->initialState->provideInitialState('lookupServerUploadEnabled', $this->fedShareProvider->isLookupServerUploadEnabled()); $this->initialState->provideInitialState('federatedTrustedShareAutoAccept', $this->fedShareProvider->isFederatedTrustedShareAutoAccept()); - \OCP\Util::addStyle(Application::APP_ID, 'settings-admin'); - \OCP\Util::addScript(Application::APP_ID, 'settings-admin'); + Util::addStyle(Application::APP_ID, 'settings-admin'); + Util::addScript(Application::APP_ID, 'settings-admin'); return new TemplateResponse(Application::APP_ID, 'settings-admin', renderAs: ''); } diff --git a/apps/federatedfilesharing/lib/Settings/Personal.php b/apps/federatedfilesharing/lib/Settings/Personal.php index fc401c404d421..01239fbe14084 100644 --- a/apps/federatedfilesharing/lib/Settings/Personal.php +++ b/apps/federatedfilesharing/lib/Settings/Personal.php @@ -16,6 +16,7 @@ use OCP\IURLGenerator; use OCP\IUserSession; use OCP\Settings\ISettings; +use OCP\Util; class Personal implements ISettings { public function __construct( @@ -42,8 +43,8 @@ public function getForm(): TemplateResponse { $this->initialState->provideInitialState('cloudId', $cloudID); $this->initialState->provideInitialState('docUrlFederated', $this->urlGenerator->linkToDocs('user-sharing-federated')); - \OCP\Util::addStyle(Application::APP_ID, 'settings-personal'); - \OCP\Util::addScript(Application::APP_ID, 'settings-personal'); + Util::addStyle(Application::APP_ID, 'settings-personal'); + Util::addScript(Application::APP_ID, 'settings-personal'); return new TemplateResponse(Application::APP_ID, 'settings-personal', renderAs: TemplateResponse::RENDER_AS_BLANK); } diff --git a/apps/files/tests/Command/ScanAppDataTest.php b/apps/files/tests/Command/ScanAppDataTest.php index cdba710c2c8cf..a0fc5b18afe6d 100644 --- a/apps/files/tests/Command/ScanAppDataTest.php +++ b/apps/files/tests/Command/ScanAppDataTest.php @@ -69,7 +69,7 @@ public function setUp(): void { $this->scanner->method('getScanner')->willReturn($this->internalScanner); $this->scanner->method('initTools') - ->willReturnCallback(function () {}); + ->willReturnCallback(function (): void {}); try { $this->rootFolder->get($this->rootFolder->getAppDataDirectoryName() . '/preview')->delete(); } catch (NotFoundException) { @@ -103,7 +103,7 @@ public function testScanAppDataRoot(): void { } $this->input->method('getArgument')->with('folder')->willReturn(''); - $this->internalScanner->method('scan')->willReturnCallback(function () { + $this->internalScanner->method('scan')->willReturnCallback(function (): void { $this->internalScanner->emit('\OC\Files\Utils\Scanner', 'scanFile', ['path42']); $this->internalScanner->emit('\OC\Files\Utils\Scanner', 'scanFolder', ['path42']); $this->internalScanner->emit('\OC\Files\Utils\Scanner', 'scanFolder', ['path42']); diff --git a/apps/files_external/tests/Settings/AdminTest.php b/apps/files_external/tests/Settings/AdminTest.php index b8524b5fc2a68..07f4e2df2b4c9 100644 --- a/apps/files_external/tests/Settings/AdminTest.php +++ b/apps/files_external/tests/Settings/AdminTest.php @@ -85,7 +85,7 @@ public function testGetForm(): void { $this->initialState ->expects($this->atLeastOnce()) ->method('provideInitialState') - ->willReturnCallback(function () use (&$initialState) { + ->willReturnCallback(function () use (&$initialState): void { $args = func_get_args(); $initialState[$args[0]] = $args[1]; }); diff --git a/apps/files_sharing/lib/Controller/DeletedShareAPIController.php b/apps/files_sharing/lib/Controller/DeletedShareAPIController.php index e7ddab8a40bf2..42105dca1333c 100644 --- a/apps/files_sharing/lib/Controller/DeletedShareAPIController.php +++ b/apps/files_sharing/lib/Controller/DeletedShareAPIController.php @@ -8,6 +8,7 @@ */ namespace OCA\Files_Sharing\Controller; +use OCA\Deck\Sharing\ShareAPIHelper; use OCA\Files_Sharing\ResponseDefinitions; use OCP\App\IAppManager; use OCP\AppFramework\Http; @@ -204,12 +205,12 @@ private function getRoomShareHelper(): \OCA\Talk\Share\Helper\DeletedShareAPICon * @psalm-suppress UndefinedClass * @throws ContainerExceptionInterface */ - private function getDeckShareHelper(): \OCA\Deck\Sharing\ShareAPIHelper { + private function getDeckShareHelper(): ShareAPIHelper { if (!$this->appManager->isEnabledForUser('deck')) { throw new QueryException(); } /** @psalm-suppress UndefinedClass */ - return Server::get(\OCA\Deck\Sharing\ShareAPIHelper::class); + return Server::get(ShareAPIHelper::class); } } diff --git a/apps/files_sharing/tests/ShareTargetValidatorTest.php b/apps/files_sharing/tests/ShareTargetValidatorTest.php index 7589c32285de9..7bc5820d39e66 100644 --- a/apps/files_sharing/tests/ShareTargetValidatorTest.php +++ b/apps/files_sharing/tests/ShareTargetValidatorTest.php @@ -178,7 +178,7 @@ public function testShareMountCreateParentFolder(): void { $share = $this->shareManager->getShareById($share->getFullId()); $this->assertSame('/foo/bar' . $this->folder, $share->getTarget()); - $this->eventDispatcher->addListener(VerifyMountPointEvent::class, function (VerifyMountPointEvent $event) { + $this->eventDispatcher->addListener(VerifyMountPointEvent::class, function (VerifyMountPointEvent $event): void { $event->setCreateParent(true); }); $this->targetValidator->verifyMountPoint($this->user2, $share, [], [$share]); diff --git a/apps/files_trashbin/lib/Trashbin.php b/apps/files_trashbin/lib/Trashbin.php index 8d1e13556e9c0..d578e14238672 100644 --- a/apps/files_trashbin/lib/Trashbin.php +++ b/apps/files_trashbin/lib/Trashbin.php @@ -16,6 +16,7 @@ use OC\Files\View; use OC\User\NoUserException; use OC_User; +use OCA\FederatedFileSharing\FederatedShareProvider; use OCA\Files_Trashbin\Command\Expire; use OCA\Files_Trashbin\Events\BeforeNodeRestoredEvent; use OCA\Files_Trashbin\Events\NodeRestoredEvent; @@ -1194,7 +1195,7 @@ private static function overwriteDeletedBy(string $user) { return $user; } - $federatedShareProvider = Server::get(\OCA\FederatedFileSharing\FederatedShareProvider::class); + $federatedShareProvider = Server::get(FederatedShareProvider::class); $share = $federatedShareProvider->getShareByToken($token); return $share->getSharedWith(); diff --git a/apps/oauth2/lib/Settings/Admin.php b/apps/oauth2/lib/Settings/Admin.php index e707a263b40dd..b843b31af1701 100644 --- a/apps/oauth2/lib/Settings/Admin.php +++ b/apps/oauth2/lib/Settings/Admin.php @@ -13,6 +13,7 @@ use OCP\AppFramework\Services\IInitialState; use OCP\IURLGenerator; use OCP\Settings\ISettings; +use OCP\Util; use Psr\Log\LoggerInterface; class Admin implements ISettings { @@ -45,8 +46,8 @@ public function getForm(): TemplateResponse { $this->initialState->provideInitialState('clients', $result); $this->initialState->provideInitialState('oauth2-doc-link', $this->urlGenerator->linkToDocs('admin-oauth2')); - \OCP\Util::addStyle('oauth2', 'settings-admin'); - \OCP\Util::addScript('oauth2', 'settings-admin', 'core'); + Util::addStyle('oauth2', 'settings-admin'); + Util::addScript('oauth2', 'settings-admin', 'core'); return new TemplateResponse( 'oauth2', 'admin', diff --git a/apps/settings/tests/Controller/AdminSettingsControllerTest.php b/apps/settings/tests/Controller/AdminSettingsControllerTest.php index 7ac0b73e37a17..ce4f983bbbd79 100644 --- a/apps/settings/tests/Controller/AdminSettingsControllerTest.php +++ b/apps/settings/tests/Controller/AdminSettingsControllerTest.php @@ -125,7 +125,7 @@ public function testIndex(): void { $initialState = []; $this->initialState->expects(self::atLeastOnce()) ->method('provideInitialState') - ->willReturnCallback(function () use (&$initialState) { + ->willReturnCallback(function () use (&$initialState): void { $initialState[] = func_get_args(); }); diff --git a/apps/settings/tests/Integration/DuplicateAssignmentIntegrationTest.php b/apps/settings/tests/Integration/DuplicateAssignmentIntegrationTest.php index 281e6335ee913..43ba37c5d0756 100644 --- a/apps/settings/tests/Integration/DuplicateAssignmentIntegrationTest.php +++ b/apps/settings/tests/Integration/DuplicateAssignmentIntegrationTest.php @@ -10,7 +10,9 @@ use OC\Settings\AuthorizedGroupMapper; use OCA\Settings\Service\AuthorizedGroupService; use OCA\Settings\Service\ConflictException; +use OCA\Settings\Service\NotFoundException; use OCP\AppFramework\Db\DoesNotExistException; +use OCP\Server; use Test\TestCase; /** @@ -27,7 +29,7 @@ protected function setUp(): void { parent::setUp(); // Use real mapper for integration testing - $this->mapper = \OCP\Server::get(AuthorizedGroupMapper::class); + $this->mapper = Server::get(AuthorizedGroupMapper::class); $this->service = new AuthorizedGroupService($this->mapper); } @@ -109,10 +111,10 @@ public function testCreateAfterDelete(): void { $this->service->delete($initialId); // Verify it's deleted by trying to find it - $this->expectException(\OCP\AppFramework\Db\DoesNotExistException::class); + $this->expectException(DoesNotExistException::class); try { $this->service->find($initialId); - } catch (\OCA\Settings\Service\NotFoundException $e) { + } catch (NotFoundException $e) { // Expected - now create the same assignment again, which should succeed $result2 = $this->service->create($groupId, $class); diff --git a/apps/settings/tests/Service/AuthorizedGroupServiceTest.php b/apps/settings/tests/Service/AuthorizedGroupServiceTest.php index f8a3c5c0e47ee..9d8ca16f94eb7 100644 --- a/apps/settings/tests/Service/AuthorizedGroupServiceTest.php +++ b/apps/settings/tests/Service/AuthorizedGroupServiceTest.php @@ -88,7 +88,7 @@ public function testCreateAllowsDifferentGroupsSameClass(): void { // Mock that no duplicate exists for group1 $this->mapper->expects($this->exactly(2)) ->method('findByGroupIdAndClass') - ->willReturnCallback(function ($groupId, $classArg) use ($groupId1, $groupId2, $class) { + ->willReturnCallback(function ($groupId, $classArg) use ($groupId1, $groupId2, $class): void { $this->assertContains($groupId, [$groupId1, $groupId2]); $this->assertEquals($class, $classArg); throw new DoesNotExistException('Not found'); @@ -126,7 +126,7 @@ public function testCreateAllowsSameGroupDifferentClasses(): void { // Mock that no duplicate exists for either class $this->mapper->expects($this->exactly(2)) ->method('findByGroupIdAndClass') - ->willReturnCallback(function ($groupIdArg, $class) use ($groupId, $class1, $class2) { + ->willReturnCallback(function ($groupIdArg, $class) use ($groupId, $class1, $class2): void { $this->assertEquals($groupId, $groupIdArg); $this->assertContains($class, [$class1, $class2]); throw new DoesNotExistException('Not found'); diff --git a/apps/user_ldap/lib/Settings/Admin.php b/apps/user_ldap/lib/Settings/Admin.php index e1410441292ed..aab8fcfeccfc9 100644 --- a/apps/user_ldap/lib/Settings/Admin.php +++ b/apps/user_ldap/lib/Settings/Admin.php @@ -15,6 +15,7 @@ use OCP\Server; use OCP\Settings\IDelegatedSettings; use OCP\Template\ITemplateManager; +use OCP\Util; class Admin implements IDelegatedSettings { public function __construct( @@ -60,8 +61,8 @@ public function getForm(): TemplateResponse { $this->initialState->provideInitialState('ldapConfigs', $ldapConfigs); $this->initialState->provideInitialState('ldapModuleInstalled', function_exists('ldap_connect')); - \OCP\Util::addStyle(Application::APP_ID, 'settings-admin'); - \OCP\Util::addScript(Application::APP_ID, 'settings-admin'); + Util::addStyle(Application::APP_ID, 'settings-admin'); + Util::addScript(Application::APP_ID, 'settings-admin'); return new TemplateResponse(Application::APP_ID, 'settings', $parameters); } diff --git a/build/psalm-baseline.xml b/build/psalm-baseline.xml index 9936d3543d934..55da4af361729 100644 --- a/build/psalm-baseline.xml +++ b/build/psalm-baseline.xml @@ -3613,22 +3613,6 @@ fileInfo]]> - - - - mountManager->findByNumericId($numericId)]]> - mountManager->findByStorageId($storageId)]]> - mountManager->findIn($mountPoint)]]> - - - - - - - - - - diff --git a/composer.lock b/composer.lock index 2218fd6fad21d..7301359b75857 100644 --- a/composer.lock +++ b/composer.lock @@ -96,5 +96,5 @@ "platform-overrides": { "php": "8.2" }, - "plugin-api-version": "2.6.0" + "plugin-api-version": "2.9.0" } diff --git a/core/Controller/ContactsMenuController.php b/core/Controller/ContactsMenuController.php index b3cb7de78816c..7224b124122ef 100644 --- a/core/Controller/ContactsMenuController.php +++ b/core/Controller/ContactsMenuController.php @@ -8,6 +8,7 @@ use Exception; use OC\Contacts\ContactsMenu\Manager; +use OC\Teams\TeamManager; use OCP\AppFramework\Controller; use OCP\AppFramework\Http; use OCP\AppFramework\Http\Attribute\FrontpageRoute; @@ -37,7 +38,7 @@ public function __construct( public function index(?string $filter = null, ?string $teamId = null): array { $entries = $this->manager->getEntries($this->userSession->getUser(), $filter); if ($teamId !== null) { - /** @var \OC\Teams\TeamManager */ + /** @var TeamManager */ $teamManager = $this->teamManager; $memberIds = $teamManager->getMembersOfTeam($teamId, $this->userSession->getUser()->getUID()); $entries['contacts'] = array_filter( diff --git a/core/Controller/OpenMetricsController.php b/core/Controller/OpenMetricsController.php index 8c57eb1a66335..c6e6c1673aa73 100644 --- a/core/Controller/OpenMetricsController.php +++ b/core/Controller/OpenMetricsController.php @@ -15,6 +15,8 @@ use OCP\AppFramework\Http\Attribute\FrontpageRoute; use OCP\AppFramework\Http\Attribute\NoCSRFRequired; use OCP\AppFramework\Http\Attribute\PublicPage; +use OCP\AppFramework\Http\Response; +use OCP\AppFramework\Http\StreamTraversableResponse; use OCP\IConfig; use OCP\IRequest; use OCP\OpenMetrics\IMetricFamily; @@ -44,12 +46,12 @@ public function __construct( #[NoCSRFRequired] #[PublicPage] #[FrontpageRoute(verb: 'GET', url: '/metrics')] - public function export(): Http\Response { + public function export(): Response { if (!$this->isRemoteAddressAllowed()) { - return new Http\Response(Http::STATUS_FORBIDDEN); + return new Response(Http::STATUS_FORBIDDEN); } - return new Http\StreamTraversableResponse( + return new StreamTraversableResponse( $this->generate(), Http::STATUS_OK, [ diff --git a/lib/composer/composer/installed.php b/lib/composer/composer/installed.php index ab3dd57b35611..87357f5e32faa 100644 --- a/lib/composer/composer/installed.php +++ b/lib/composer/composer/installed.php @@ -3,7 +3,7 @@ 'name' => '__root__', 'pretty_version' => 'dev-master', 'version' => 'dev-master', - 'reference' => '8c12590cf6f93ce7aa41f17817b3791e524da39e', + 'reference' => '671cec33f134e670bb21c5e3c49c685bd78fc339', 'type' => 'library', 'install_path' => __DIR__ . '/../../../', 'aliases' => array(), @@ -13,7 +13,7 @@ '__root__' => array( 'pretty_version' => 'dev-master', 'version' => 'dev-master', - 'reference' => '8c12590cf6f93ce7aa41f17817b3791e524da39e', + 'reference' => '671cec33f134e670bb21c5e3c49c685bd78fc339', 'type' => 'library', 'install_path' => __DIR__ . '/../../../', 'aliases' => array(), diff --git a/lib/private/AppFramework/DependencyInjection/DIContainer.php b/lib/private/AppFramework/DependencyInjection/DIContainer.php index c316bdab6ac8f..7527d2495863b 100644 --- a/lib/private/AppFramework/DependencyInjection/DIContainer.php +++ b/lib/private/AppFramework/DependencyInjection/DIContainer.php @@ -38,6 +38,7 @@ use OC\AppFramework\Services\InitialState; use OC\AppFramework\Utility\ControllerMethodReflector; use OC\AppFramework\Utility\SimpleContainer; +use OC\CapabilitiesManager; use OC\Core\Middleware\TwoFactorMiddleware; use OC\Diagnostics\EventLogger; use OC\Log\PsrLoggerAdapter; @@ -305,7 +306,7 @@ private function getUserId(): string { * @param string $serviceName e.g. 'OCA\Files\Capabilities' */ public function registerCapability($serviceName) { - $this->query(\OC\CapabilitiesManager::class)->registerCapability(function () use ($serviceName) { + $this->query(CapabilitiesManager::class)->registerCapability(function () use ($serviceName) { return $this->query($serviceName); }); } diff --git a/lib/private/Cache/File.php b/lib/private/Cache/File.php index 82afdd4ce3e8b..d9a3e5e8b6331 100644 --- a/lib/private/Cache/File.php +++ b/lib/private/Cache/File.php @@ -13,6 +13,7 @@ use OC\User\NoUserException; use OCP\Files\LockNotAcquiredException; use OCP\ICache; +use OCP\IConfig; use OCP\IUserSession; use OCP\Lock\LockedException; use OCP\Security\ISecureRandom; @@ -161,7 +162,7 @@ public function clear($prefix = '') { public function gc() { $storage = $this->getStorage(); if ($storage) { - $ttl = \OC::$server->getConfig()->getSystemValueInt('cache_chunk_gc_ttl', 60 * 60 * 24); + $ttl = Server::get(IConfig::class)->getSystemValueInt('cache_chunk_gc_ttl', 60 * 60 * 24); $now = time() - $ttl; $dh = $storage->opendir('/'); diff --git a/lib/private/Files/Cache/Cache.php b/lib/private/Files/Cache/Cache.php index 9bd6e58497469..aad405a7d1508 100644 --- a/lib/private/Files/Cache/Cache.php +++ b/lib/private/Files/Cache/Cache.php @@ -27,6 +27,7 @@ use OCP\Files\Cache\CacheUpdateEvent; use OCP\Files\Cache\ICache; use OCP\Files\Cache\ICacheEntry; +use OCP\Files\Config\IUserMountCache; use OCP\Files\FileInfo; use OCP\Files\IMimeTypeLoader; use OCP\Files\Search\ISearchComparison; @@ -825,7 +826,7 @@ public function moveFromCache(ICache $sourceCache, $sourcePath, $targetPath) { $this->connection->commit(); if ($sourceCache->getNumericStorageId() !== $this->getNumericStorageId()) { - \OCP\Server::get(\OCP\Files\Config\IUserMountCache::class)->clear(); + Server::get(IUserMountCache::class)->clear(); $event = new CacheEntryRemovedEvent($this->storage, $sourcePath, $sourceId, $sourceCache->getNumericStorageId()); $this->eventDispatcher->dispatchTyped($event); diff --git a/lib/private/Files/FileInfo.php b/lib/private/Files/FileInfo.php index 967d404b8a4f0..d864ebe2a0913 100644 --- a/lib/private/Files/FileInfo.php +++ b/lib/private/Files/FileInfo.php @@ -10,6 +10,7 @@ use OC\Files\Mount\HomeMountPoint; use OCA\Files_Sharing\External\Mount; use OCA\Files_Sharing\ISharedMountPoint; +use OCP\Constants; use OCP\Files\Cache\ICacheEntry; use OCP\Files\Mount\IMountPoint; use OCP\IUser; @@ -18,29 +19,11 @@ * @template-implements \ArrayAccess */ class FileInfo implements \OCP\Files\FileInfo, \ArrayAccess { - private array|ICacheEntry $data; - /** - * @var string - */ - private $path; - - /** - * @var \OC\Files\Storage\Storage $storage - */ - private $storage; - - /** - * @var string - */ - private $internalPath; - /** * @var \OCP\Files\Mount\IMountPoint */ private $mount; - private ?IUser $owner; - /** * @var string[] */ @@ -59,20 +42,22 @@ class FileInfo implements \OCP\Files\FileInfo, \ArrayAccess { private int|float $rawSize = 0; /** - * @param string|boolean $path + * @param string $path * @param Storage\Storage $storage * @param string $internalPath * @param array|ICacheEntry $data * @param IMountPoint $mount * @param ?IUser $owner */ - public function __construct($path, $storage, $internalPath, $data, $mount, $owner = null) { - $this->path = $path; - $this->storage = $storage; - $this->internalPath = $internalPath; - $this->data = $data; + public function __construct( + private $path, + private $storage, + private $internalPath, + private array|ICacheEntry $data, + $mount, + private ?IUser $owner = null, + ) { $this->mount = $mount; - $this->owner = $owner; if (isset($this->data['unencrypted_size']) && $this->data['unencrypted_size'] !== 0) { $this->rawSize = $this->data['unencrypted_size']; } else { @@ -239,14 +224,14 @@ protected function checkPermissions($permissions) { * @return bool */ public function isReadable() { - return $this->checkPermissions(\OCP\Constants::PERMISSION_READ); + return $this->checkPermissions(Constants::PERMISSION_READ); } /** * @return bool */ public function isUpdateable() { - return $this->checkPermissions(\OCP\Constants::PERMISSION_UPDATE); + return $this->checkPermissions(Constants::PERMISSION_UPDATE); } /** @@ -255,21 +240,21 @@ public function isUpdateable() { * @return bool */ public function isCreatable() { - return $this->checkPermissions(\OCP\Constants::PERMISSION_CREATE); + return $this->checkPermissions(Constants::PERMISSION_CREATE); } /** * @return bool */ public function isDeletable() { - return $this->checkPermissions(\OCP\Constants::PERMISSION_DELETE); + return $this->checkPermissions(Constants::PERMISSION_DELETE); } /** * @return bool */ public function isShareable() { - return $this->checkPermissions(\OCP\Constants::PERMISSION_SHARE); + return $this->checkPermissions(Constants::PERMISSION_SHARE); } /** diff --git a/lib/private/Files/Node/File.php b/lib/private/Files/Node/File.php index eb6411d7d137c..4e8aad1cfb14e 100644 --- a/lib/private/Files/Node/File.php +++ b/lib/private/Files/Node/File.php @@ -7,6 +7,7 @@ */ namespace OC\Files\Node; +use OCP\Constants; use OCP\Files\GenericFileException; use OCP\Files\NotPermittedException; use OCP\Lock\LockedException; @@ -29,7 +30,7 @@ protected function createNonExistingNode($path) { * @throws LockedException */ public function getContent() { - if ($this->checkPermissions(\OCP\Constants::PERMISSION_READ)) { + if ($this->checkPermissions(Constants::PERMISSION_READ)) { $content = $this->view->file_get_contents($this->path); if ($content === false) { throw new GenericFileException(); @@ -47,7 +48,7 @@ public function getContent() { * @throws LockedException */ public function putContent($data) { - if ($this->checkPermissions(\OCP\Constants::PERMISSION_UPDATE)) { + if ($this->checkPermissions(Constants::PERMISSION_UPDATE)) { $this->sendHooks(['preWrite']); if ($this->view->file_put_contents($this->path, $data) === false) { throw new GenericFileException('file_put_contents failed'); @@ -68,7 +69,7 @@ public function putContent($data) { public function fopen($mode) { $preHooks = []; $postHooks = []; - $requiredPermissions = \OCP\Constants::PERMISSION_READ; + $requiredPermissions = Constants::PERMISSION_READ; switch ($mode) { case 'r+': case 'rb+': @@ -86,7 +87,7 @@ public function fopen($mode) { case 'ab': $preHooks[] = 'preWrite'; $postHooks[] = 'postWrite'; - $requiredPermissions |= \OCP\Constants::PERMISSION_UPDATE; + $requiredPermissions |= Constants::PERMISSION_UPDATE; break; } @@ -106,7 +107,7 @@ public function fopen($mode) { * @throws \OCP\Files\NotFoundException */ public function delete() { - if ($this->checkPermissions(\OCP\Constants::PERMISSION_DELETE)) { + if ($this->checkPermissions(Constants::PERMISSION_DELETE)) { $this->sendHooks(['preDelete']); $fileInfo = $this->getFileInfo(); $this->view->unlink($this->path); diff --git a/lib/private/Files/Node/Folder.php b/lib/private/Files/Node/Folder.php index c27f051108059..0a7810a18d572 100644 --- a/lib/private/Files/Node/Folder.php +++ b/lib/private/Files/Node/Folder.php @@ -14,6 +14,7 @@ use OC\Files\Search\SearchQuery; use OC\Files\Utils\PathHelper; use OC\User\LazyUser; +use OCP\Constants; use OCP\Files\Cache\ICacheEntry; use OCP\Files\FileInfo; use OCP\Files\Folder as IFolder; @@ -26,7 +27,9 @@ use OCP\Files\Search\ISearchOperator; use OCP\Files\Search\ISearchOrder; use OCP\Files\Search\ISearchQuery; +use OCP\IConfig; use OCP\IUserManager; +use OCP\Server; use Override; class Folder extends Node implements IFolder { @@ -122,7 +125,7 @@ public function nodeExists($path) { * @throws \OCP\Files\NotPermittedException */ public function newFolder($path) { - if ($this->checkPermissions(\OCP\Constants::PERMISSION_CREATE)) { + if ($this->checkPermissions(Constants::PERMISSION_CREATE)) { $fullPath = $this->getFullPath($path); $nonExisting = new NonExistingFolder($this->root, $this->view, $fullPath); $this->sendHooks(['preWrite', 'preCreate'], [$nonExisting]); @@ -154,7 +157,7 @@ public function newFolder($path) { /** * @param string $path * @param string | resource | null $content - * @return \OC\Files\Node\File + * @return File * @throws \OCP\Files\NotPermittedException */ public function newFile($path, $content = null) { @@ -162,7 +165,7 @@ public function newFile($path, $content = null) { throw new NotPermittedException('Could not create as provided path is empty'); } $this->recreateIfNeeded(); - if ($this->checkPermissions(\OCP\Constants::PERMISSION_CREATE)) { + if ($this->checkPermissions(Constants::PERMISSION_CREATE)) { $fullPath = $this->getFullPath($path); $nonExisting = new NonExistingFile($this->root, $this->view, $fullPath); $this->sendHooks(['preWrite', 'preCreate'], [$nonExisting]); @@ -186,7 +189,7 @@ private function queryFromOperator(ISearchOperator $operator, ?string $uid = nul $user = null; } else { /** @var IUserManager $userManager */ - $userManager = \OCP\Server::get(IUserManager::class); + $userManager = Server::get(IUserManager::class); $user = $userManager->get($uid); } return new SearchQuery($operator, $limit, $offset, [], $user); @@ -212,7 +215,7 @@ public function search($query) { } /** @var QuerySearchHelper $searchHelper */ - $searchHelper = \OC::$server->get(QuerySearchHelper::class); + $searchHelper = Server::get(QuerySearchHelper::class); [$caches, $mountByMountPoint] = $searchHelper->getCachesAndMountPointsForSearch($this->root, $this->path, $limitToHome); $resultsPerCache = $searchHelper->searchInCaches($query, $caches); @@ -259,7 +262,7 @@ private function cacheEntryToFileInfo(IMountPoint $mount, string $appendRoot, IC if ($ownerId !== false) { // Cache the user manager (for performance) if ($this->userManager === null) { - $this->userManager = \OCP\Server::get(IUserManager::class); + $this->userManager = Server::get(IUserManager::class); } $owner = new LazyUser($ownerId, $this->userManager); } @@ -314,12 +317,12 @@ public function getById($id) { return $this->root->getByIdInPath((int)$id, $this->getPath()); } - public function getFirstNodeById(int $id): ?\OCP\Files\Node { + public function getFirstNodeById(int $id): ?INode { return $this->root->getFirstNodeByIdInPath($id, $this->getPath()); } public function getAppDataDirectoryName(): string { - $instanceId = \OC::$server->getConfig()->getSystemValueString('instanceid'); + $instanceId = Server::get(IConfig::class)->getSystemValueString('instanceid'); return 'appdata_' . $instanceId; } @@ -371,7 +374,7 @@ public function getFreeSpace() { } public function delete() { - if ($this->checkPermissions(\OCP\Constants::PERMISSION_DELETE)) { + if ($this->checkPermissions(Constants::PERMISSION_DELETE)) { $this->sendHooks(['preDelete']); $fileInfo = $this->getFileInfo(); $this->view->rmdir($this->path); diff --git a/lib/private/Files/Node/LazyFolder.php b/lib/private/Files/Node/LazyFolder.php index d04c8aefb7e06..23858bb0679af 100644 --- a/lib/private/Files/Node/LazyFolder.php +++ b/lib/private/Files/Node/LazyFolder.php @@ -13,6 +13,7 @@ use OCP\Files\Folder; use OCP\Files\IRootFolder; use OCP\Files\Mount\IMountPoint; +use OCP\Files\Node; use OCP\Files\NotPermittedException; use Override; @@ -25,21 +26,20 @@ * @package OC\Files\Node */ class LazyFolder implements Folder { - /** @var \Closure(): Folder */ - private \Closure $folderClosure; protected ?Folder $folder = null; protected IRootFolder $rootFolder; - protected array $data; /** * @param IRootFolder $rootFolder * @param \Closure(): Folder $folderClosure * @param array $data */ - public function __construct(IRootFolder $rootFolder, \Closure $folderClosure, array $data = []) { + public function __construct( + IRootFolder $rootFolder, + private \Closure $folderClosure, + protected array $data = [], + ) { $this->rootFolder = $rootFolder; - $this->folderClosure = $folderClosure; - $this->data = $data; } protected function getRootFolder(): IRootFolder { @@ -470,7 +470,7 @@ public function getById($id) { return $this->getRootFolder()->getByIdInPath((int)$id, $this->getPath()); } - public function getFirstNodeById(int $id): ?\OCP\Files\Node { + public function getFirstNodeById(int $id): ?Node { return $this->getRootFolder()->getFirstNodeByIdInPath($id, $this->getPath()); } diff --git a/lib/private/Files/Node/LazyRoot.php b/lib/private/Files/Node/LazyRoot.php index bc3f3a2e80f38..8920a2f68f67e 100644 --- a/lib/private/Files/Node/LazyRoot.php +++ b/lib/private/Files/Node/LazyRoot.php @@ -10,7 +10,6 @@ use OCP\Files\Cache\ICacheEntry; use OCP\Files\IRootFolder; use OCP\Files\Mount\IMountPoint; -use OCP\Files\Node; use OCP\Files\Node as INode; /** @@ -42,7 +41,7 @@ public function getByIdInPath(int $id, string $path) { return $this->__call(__FUNCTION__, func_get_args()); } - public function getFirstNodeByIdInPath(int $id, string $path): ?Node { + public function getFirstNodeByIdInPath(int $id, string $path): ?INode { return $this->__call(__FUNCTION__, func_get_args()); } diff --git a/lib/private/Files/Node/LazyUserFolder.php b/lib/private/Files/Node/LazyUserFolder.php index d7afb199b913f..5ac74e2705e21 100644 --- a/lib/private/Files/Node/LazyUserFolder.php +++ b/lib/private/Files/Node/LazyUserFolder.php @@ -16,6 +16,7 @@ use OCP\Files\Mount\IMountManager; use OCP\Files\NotFoundException; use OCP\IUser; +use OCP\Server; use Psr\Log\LoggerInterface; class LazyUserFolder extends LazyFolder { @@ -48,7 +49,7 @@ function () use ($user): Folder { $node = $this->getRootFolder()->get($this->path); if ($node instanceof File) { $e = new \RuntimeException(); - \OCP\Server::get(LoggerInterface::class)->error('User root storage is not a folder: ' . $this->path, [ + Server::get(LoggerInterface::class)->error('User root storage is not a folder: ' . $this->path, [ 'exception' => $e, ]); throw $e; diff --git a/lib/private/Files/Node/Node.php b/lib/private/Files/Node/Node.php index fd8d84883d964..38e8398439020 100644 --- a/lib/private/Files/Node/Node.php +++ b/lib/private/Files/Node/Node.php @@ -10,6 +10,8 @@ use OC\Files\Filesystem; use OC\Files\Mount\MoveableMount; use OC\Files\Utils\PathHelper; +use OC\Files\View; +use OCP\Constants; use OCP\EventDispatcher\GenericEvent; use OCP\EventDispatcher\IEventDispatcher; use OCP\Files\FileInfo; @@ -20,43 +22,36 @@ use OCP\Files\NotPermittedException; use OCP\Lock\LockedException; use OCP\PreConditionNotMetException; +use OCP\Server; // FIXME: this class really should be abstract (+1) class Node implements INode { /** - * @var \OC\Files\View $view + * @var View $view */ protected $view; protected IRootFolder $root; /** - * @var string $path Absolute path to the node (e.g. /admin/files/folder/file) - */ - protected $path; - - protected ?FileInfo $fileInfo; - - protected ?INode $parent; - - private bool $infoHasSubMountsIncluded; - - /** - * @param \OC\Files\View $view + * @param View $view * @param \OCP\Files\IRootFolder $root * @param string $path * @param FileInfo $fileInfo */ - public function __construct(IRootFolder $root, $view, $path, $fileInfo = null, ?INode $parent = null, bool $infoHasSubMountsIncluded = true) { + public function __construct( + IRootFolder $root, + $view, + protected $path, + protected ?FileInfo $fileInfo = null, + protected ?INode $parent = null, + private bool $infoHasSubMountsIncluded = true, + ) { if (Filesystem::normalizePath($view->getRoot()) !== '/') { throw new PreConditionNotMetException('The view passed to the node should not have any fake root set'); } $this->view = $view; $this->root = $root; - $this->path = $path; - $this->fileInfo = $fileInfo; - $this->parent = $parent; - $this->infoHasSubMountsIncluded = $infoHasSubMountsIncluded; } /** @@ -104,7 +99,7 @@ public function getFileInfo(bool $includeMountPoint = true) { protected function sendHooks($hooks, ?array $args = null) { $args = !empty($args) ? $args : [$this]; /** @var IEventDispatcher $dispatcher */ - $dispatcher = \OC::$server->get(IEventDispatcher::class); + $dispatcher = Server::get(IEventDispatcher::class); foreach ($hooks as $hook) { if (method_exists($this->root, 'emit')) { $this->root->emit('\OC\Files', $hook, $args); @@ -140,7 +135,7 @@ public function delete() { * @throws NotPermittedException */ public function touch($mtime = null) { - if ($this->checkPermissions(\OCP\Constants::PERMISSION_UPDATE)) { + if ($this->checkPermissions(Constants::PERMISSION_UPDATE)) { $this->sendHooks(['preTouch']); $this->view->touch($this->path, $mtime); $this->sendHooks(['postTouch']); diff --git a/lib/private/Files/Node/NonExistingFolder.php b/lib/private/Files/Node/NonExistingFolder.php index ee07e53beddfc..9e6638376cd4f 100644 --- a/lib/private/Files/Node/NonExistingFolder.php +++ b/lib/private/Files/Node/NonExistingFolder.php @@ -7,6 +7,7 @@ */ namespace OC\Files\Node; +use OCP\Files\Node; use OCP\Files\NotFoundException; use Override; @@ -156,7 +157,7 @@ public function getById($id) { throw new NotFoundException(); } - public function getFirstNodeById(int $id): ?\OCP\Files\Node { + public function getFirstNodeById(int $id): ?Node { throw new NotFoundException(); } diff --git a/lib/private/Files/Node/Root.php b/lib/private/Files/Node/Root.php index 8354f382aa3be..0c121dc8b0527 100644 --- a/lib/private/Files/Node/Root.php +++ b/lib/private/Files/Node/Root.php @@ -11,6 +11,7 @@ use OC\Files\FileInfo; use OC\Files\Mount\Manager; use OC\Files\Mount\MountPoint; +use OC\Files\Storage\Storage; use OC\Files\Utils\PathHelper; use OC\Files\View; use OC\Hooks\PublicEmitter; @@ -18,6 +19,7 @@ use OCA\Files\AppInfo\Application; use OCA\Files\ConfigLexicon; use OCP\Cache\CappedMemoryCache; +use OCP\Constants; use OCP\EventDispatcher\IEventDispatcher; use OCP\Files\Cache\ICacheEntry; use OCP\Files\Config\ICachedMountFileInfo; @@ -76,7 +78,7 @@ public function __construct( parent::__construct($this, $view, ''); $this->emitter = new PublicEmitter(); $this->userFolderCache = new CappedMemoryCache(); - $eventDispatcher->addListener(FilesystemTornDownEvent::class, function () { + $eventDispatcher->addListener(FilesystemTornDownEvent::class, function (): void { $this->userFolderCache = new CappedMemoryCache(); }); $this->pathByIdCache = $cacheFactory->createLocal('path-by-id'); @@ -118,7 +120,7 @@ public function emit($scope, $method, $arguments = []) { } /** - * @param \OC\Files\Storage\Storage $storage + * @param Storage $storage * @param string $mountPoint * @param array $arguments */ @@ -133,35 +135,12 @@ public function getMount(string $mountPoint): IMountPoint { /** * @param string $mountPoint - * @return \OC\Files\Mount\MountPoint[] + * @return IMountPoint[] */ public function getMountsIn(string $mountPoint): array { return $this->mountManager->findIn($mountPoint); } - /** - * @param string $storageId - * @return \OC\Files\Mount\MountPoint[] - */ - public function getMountByStorageId($storageId) { - return $this->mountManager->findByStorageId($storageId); - } - - /** - * @param int $numericId - * @return MountPoint[] - */ - public function getMountByNumericStorageId($numericId) { - return $this->mountManager->findByNumericId($numericId); - } - - /** - * @param \OC\Files\Mount\MountPoint $mount - */ - public function unMount($mount) { - $this->mountManager->remove($mount); - } - public function get($path) { $path = $this->normalizePath($path); if ($this->isValidPath($path)) { @@ -210,7 +189,7 @@ public function touch($mtime = null) { } /** - * @return \OC\Files\Storage\Storage + * @return Storage * @throws \OCP\Files\NotFoundException */ public function getStorage() { @@ -271,7 +250,7 @@ public function getEtag() { * @return int */ public function getPermissions() { - return \OCP\Constants::PERMISSION_CREATE; + return Constants::PERMISSION_CREATE; } /** @@ -401,8 +380,7 @@ public function getFirstNodeByIdInPath(int $id, string $path): ?INode { } /** - * @param int $id - * @return Node[] + * @return INode[] */ public function getByIdInPath(int $id, string $path): array { $mountCache = $this->getUserMountCache(); @@ -510,9 +488,7 @@ public function getByIdInPath(int $id, string $path): array { $folders = array_filter($nodes, function (Node $node) use ($path) { return PathHelper::getRelativePath($path, $node->getPath()) !== null; }); - usort($folders, function ($a, $b) { - return $b->getPath() <=> $a->getPath(); - }); + usort($folders, static fn (Node $a, Node $b): int => $b->getPath() <=> $a->getPath()); return $folders; } diff --git a/lib/private/Files/Notify/RenameChange.php b/lib/private/Files/Notify/RenameChange.php index 47e89fe9e16c4..bb5c17d7cbcee 100644 --- a/lib/private/Files/Notify/RenameChange.php +++ b/lib/private/Files/Notify/RenameChange.php @@ -1,5 +1,7 @@ registerMounts($user, $fullProviderMounts, $currentProviders); } - $this->setupForUserWith($user, function () use ($fullProviderMounts, $authoritativeMounts) { + $this->setupForUserWith($user, function () use ($fullProviderMounts, $authoritativeMounts): void { $allMounts = [...$fullProviderMounts, ...$authoritativeMounts]; array_walk($allMounts, $this->mountManager->addMount(...)); }); @@ -778,7 +778,7 @@ private function setupListeners() { $this->eventDispatcher->addListener(ShareCreatedEvent::class, function (ShareCreatedEvent $event): void { $this->cache->remove($event->getShare()->getSharedWith()); }); - $this->eventDispatcher->addListener(BeforeNodeRenamedEvent::class, function (BeforeNodeRenamedEvent $event) { + $this->eventDispatcher->addListener(BeforeNodeRenamedEvent::class, function (BeforeNodeRenamedEvent $event): void { // update cache information that is cached by mount point $from = rtrim($event->getSource()->getPath(), '/') . '/'; $to = rtrim($event->getTarget()->getPath(), '/') . '/'; diff --git a/lib/private/Files/View.php b/lib/private/Files/View.php index 0d20ab75067a3..669f5211b4b6a 100644 --- a/lib/private/Files/View.php +++ b/lib/private/Files/View.php @@ -1526,8 +1526,8 @@ public function getDirectoryContent(string $directory, ?string $mimeTypeFilter = $folderId = $data->getId(); $contents = $cache->getFolderContentsById($folderId, $mimeTypeFilter); - $sharingDisabled = \OCP\Util::isSharingDisabledForUser(); - $permissionsMask = ~\OCP\Constants::PERMISSION_SHARE; + $sharingDisabled = Util::isSharingDisabledForUser(); + $permissionsMask = ~Constants::PERMISSION_SHARE; $files = []; foreach ($contents as $content) { diff --git a/lib/private/FilesMetadata/FilesMetadataManager.php b/lib/private/FilesMetadata/FilesMetadataManager.php index 188cb09e53a15..9282513109b4d 100644 --- a/lib/private/FilesMetadata/FilesMetadataManager.php +++ b/lib/private/FilesMetadata/FilesMetadataManager.php @@ -203,13 +203,13 @@ public function saveMetadata(IFilesMetadata $filesMetadata): void { public function deleteMetadata(int $fileId): void { try { $this->metadataRequestService->dropMetadata($fileId); - } catch (Exception $e) { + } catch (DBException $e) { $this->logger->warning('issue while deleteMetadata', ['exception' => $e, 'fileId' => $fileId]); } try { $this->indexRequestService->dropIndex($fileId); - } catch (Exception $e) { + } catch (DBException $e) { $this->logger->warning('issue while deleteMetadata', ['exception' => $e, 'fileId' => $fileId]); } } @@ -217,13 +217,13 @@ public function deleteMetadata(int $fileId): void { public function deleteMetadataForFiles(int $storage, array $fileIds): void { try { $this->metadataRequestService->dropMetadataForFiles($storage, $fileIds); - } catch (Exception $e) { + } catch (DBException $e) { $this->logger->warning('issue while deleteMetadata', ['exception' => $e, 'fileIds' => $fileIds]); } try { $this->indexRequestService->dropIndexForFiles($fileIds); - } catch (Exception $e) { + } catch (DBException $e) { $this->logger->warning('issue while deleteMetadata', ['exception' => $e, 'fileIds' => $fileIds]); } } diff --git a/lib/private/FilesMetadata/MetadataQuery.php b/lib/private/FilesMetadata/MetadataQuery.php index deae433e2fc1f..19495c38e5e13 100644 --- a/lib/private/FilesMetadata/MetadataQuery.php +++ b/lib/private/FilesMetadata/MetadataQuery.php @@ -18,6 +18,7 @@ use OCP\FilesMetadata\IMetadataQuery; use OCP\FilesMetadata\Model\IFilesMetadata; use OCP\FilesMetadata\Model\IMetadataValueWrapper; +use OCP\Server; use Psr\Log\LoggerInterface; /** @@ -42,7 +43,7 @@ public function __construct( * * FIXME: remove support for IFilesMetadata */ - $logger = \OCP\Server::get(LoggerInterface::class); + $logger = Server::get(LoggerInterface::class); $logger->debug('It is deprecated to use IFilesMetadata as second parameter when calling MetadataQuery::__construct()'); } } diff --git a/lib/private/FilesMetadata/Model/MetadataValueWrapper.php b/lib/private/FilesMetadata/Model/MetadataValueWrapper.php index 710a8129340cb..606f3b5acec04 100644 --- a/lib/private/FilesMetadata/Model/MetadataValueWrapper.php +++ b/lib/private/FilesMetadata/Model/MetadataValueWrapper.php @@ -18,7 +18,6 @@ * @since 28.0.0 */ class MetadataValueWrapper implements IMetadataValueWrapper { - private string $type; /** @var string|int|float|bool|array|string[]|int[] */ private mixed $value = null; private string $etag = ''; @@ -38,8 +37,9 @@ class MetadataValueWrapper implements IMetadataValueWrapper { * @see self::TYPE_STRING * @since 28.0.0 */ - public function __construct(string $type = '') { - $this->type = $type; + public function __construct( + private string $type = '', + ) { } /** diff --git a/lib/private/OpenMetrics/ExporterManager.php b/lib/private/OpenMetrics/ExporterManager.php index 5bf8e59786ae6..0b984fb382ee8 100644 --- a/lib/private/OpenMetrics/ExporterManager.php +++ b/lib/private/OpenMetrics/ExporterManager.php @@ -10,6 +10,16 @@ namespace OC\OpenMetrics; use Generator; +use OC\OpenMetrics\Exporters\ActiveSessions; +use OC\OpenMetrics\Exporters\ActiveUsers; +use OC\OpenMetrics\Exporters\AppsCount; +use OC\OpenMetrics\Exporters\AppsInfo; +use OC\OpenMetrics\Exporters\FilesByType; +use OC\OpenMetrics\Exporters\InstanceInfo; +use OC\OpenMetrics\Exporters\LogLevel; +use OC\OpenMetrics\Exporters\Maintenance; +use OC\OpenMetrics\Exporters\RunningJobs; +use OC\OpenMetrics\Exporters\UsersByBackend; use OCP\App\IAppManager; use OCP\IConfig; use OCP\OpenMetrics\IMetricFamily; @@ -33,22 +43,22 @@ public function export(): Generator { // Core exporters $exporters = [ // Basic exporters - Exporters\InstanceInfo::class, - Exporters\AppsInfo::class, - Exporters\AppsCount::class, - Exporters\Maintenance::class, - Exporters\LogLevel::class, + InstanceInfo::class, + AppsInfo::class, + AppsCount::class, + Maintenance::class, + LogLevel::class, // File exporters - Exporters\FilesByType::class, + FilesByType::class, // Users exporters - Exporters\ActiveUsers::class, - Exporters\ActiveSessions::class, - Exporters\UsersByBackend::class, + ActiveUsers::class, + ActiveSessions::class, + UsersByBackend::class, // Jobs - Exporters\RunningJobs::class, + RunningJobs::class, ]; $exporters = array_filter($exporters, fn ($classname) => !isset($this->skippedClasses[$classname])); foreach ($exporters as $classname) { diff --git a/lib/private/Profiler/FileProfilerStorage.php b/lib/private/Profiler/FileProfilerStorage.php index 1636b9d60651e..14aaf1b906952 100644 --- a/lib/private/Profiler/FileProfilerStorage.php +++ b/lib/private/Profiler/FileProfilerStorage.php @@ -8,6 +8,12 @@ namespace OC\Profiler; +use OC\DB\DbDataCollector; +use OC\Memcache\ProfilerWrapperCache; +use OCA\Profiler\DataCollector\EventLoggerDataProvider; +use OCA\Profiler\DataCollector\HttpDataCollector; +use OCA\Profiler\DataCollector\MemoryDataCollector; +use OCA\User_LDAP\DataCollector\LdapDataCollector; use OCP\Profiler\IProfile; /** @@ -16,13 +22,13 @@ class FileProfilerStorage { /** @psalm-suppress UndefinedClass */ public const allowedClasses = [ - \OCA\Profiler\DataCollector\EventLoggerDataProvider::class, - \OCA\Profiler\DataCollector\HttpDataCollector::class, - \OCA\Profiler\DataCollector\MemoryDataCollector::class, - \OCA\User_LDAP\DataCollector\LdapDataCollector::class, - \OC\Memcache\ProfilerWrapperCache::class, - \OC\Profiler\RoutingDataCollector::class, - \OC\DB\DbDataCollector::class, + EventLoggerDataProvider::class, + HttpDataCollector::class, + MemoryDataCollector::class, + LdapDataCollector::class, + ProfilerWrapperCache::class, + RoutingDataCollector::class, + DbDataCollector::class, ]; /** diff --git a/lib/private/Server.php b/lib/private/Server.php index f608d3ee26d28..532ac3887c460 100644 --- a/lib/private/Server.php +++ b/lib/private/Server.php @@ -9,6 +9,7 @@ use bantu\IniGetWrapper\IniGetWrapper; use OC\Accounts\AccountManager; +use OC\Activity\EventMerger; use OC\App\AppManager; use OC\App\AppStore\Bundles\BundleFetcher; use OC\AppFramework\Bootstrap\Coordinator; @@ -30,6 +31,8 @@ use OC\Collaboration\Collaborators\MailByMailPlugin; use OC\Collaboration\Collaborators\RemoteGroupPlugin; use OC\Collaboration\Collaborators\RemotePlugin; +use OC\Collaboration\Collaborators\Search; +use OC\Collaboration\Collaborators\SearchResult; use OC\Collaboration\Collaborators\UserByMailPlugin; use OC\Collaboration\Collaborators\UserPlugin; use OC\Collaboration\Reference\ReferenceManager; @@ -39,6 +42,7 @@ use OC\Config\UserConfig; use OC\Contacts\ContactsMenu\ActionFactory; use OC\Contacts\ContactsMenu\ContactsStore; +use OC\ContextChat\ContentManager; use OC\DB\Connection; use OC\DB\ConnectionAdapter; use OC\DB\ConnectionFactory; @@ -123,6 +127,9 @@ use OC\Security\CSRF\TokenStorage\SessionStorage; use OC\Security\Hasher; use OC\Security\Ip\RemoteAddress; +use OC\Security\RateLimiting\Backend\DatabaseBackend; +use OC\Security\RateLimiting\Backend\IBackend; +use OC\Security\RateLimiting\Backend\MemoryCacheBackend; use OC\Security\RateLimiting\Limiter; use OC\Security\RemoteHostValidator; use OC\Security\SecureRandom; @@ -159,6 +166,7 @@ use OCA\Theming\ThemingDefaults; use OCA\Theming\Util; use OCP\Accounts\IAccountManager; +use OCP\Activity\IEventMerger; use OCP\App\IAppManager; use OCP\AppFramework\Utility\IControllerMethodReflector; use OCP\AppFramework\Utility\ITimeFactory; @@ -167,13 +175,17 @@ use OCP\Authentication\TwoFactorAuth\IRegistry; use OCP\AutoloadNotAllowedException; use OCP\BackgroundJob\IJobList; +use OCP\Collaboration\Collaborators\ISearch; +use OCP\Collaboration\Collaborators\ISearchResult; use OCP\Collaboration\Reference\IReferenceManager; +use OCP\Collaboration\Resources\IProviderManager; use OCP\Command\IBus; use OCP\Comments\ICommentsManager; use OCP\Comments\ICommentsManagerFactory; use OCP\Config\IUserConfig; use OCP\Contacts\ContactsMenu\IActionFactory; use OCP\Contacts\ContactsMenu\IContactsStore; +use OCP\ContextChat\IContentManager; use OCP\Defaults; use OCP\Diagnostics\IEventLogger; use OCP\Diagnostics\IQueryLogger; @@ -194,6 +206,7 @@ use OCP\Files\IMimeTypeDetector; use OCP\Files\IMimeTypeLoader; use OCP\Files\IRootFolder; +use OCP\Files\ISetupManager; use OCP\Files\Lock\ILockManager; use OCP\Files\Mount\IMountManager; use OCP\Files\Storage\IStorageFactory; @@ -237,7 +250,10 @@ use OCP\Log\ILogFactory; use OCP\Mail\IEmailValidator; use OCP\Mail\IMailer; +use OCP\OCM\ICapabilityAwareOCMProvider; use OCP\OCM\IOCMDiscoveryService; +use OCP\OCM\IOCMProvider; +use OCP\OCS\IDiscoveryService; use OCP\Preview\IMimeIconProvider; use OCP\Profile\IProfileManager; use OCP\Profiler\IProfiler; @@ -247,10 +263,12 @@ use OCP\RichObjectStrings\IValidator; use OCP\Route\IRouter; use OCP\Security\Bruteforce\IThrottler; +use OCP\Security\IContentSecurityPolicyManager; use OCP\Security\ICredentialsManager; use OCP\Security\ICrypto; use OCP\Security\IHasher; use OCP\Security\Ip\IRemoteAddress; +use OCP\Security\IRemoteHostValidator; use OCP\Security\ISecureRandom; use OCP\Security\ITrustedDomainHelper; use OCP\Security\RateLimiting\ILimiter; @@ -260,10 +278,12 @@ use OCP\Settings\IDeclarativeManager; use OCP\SetupCheck\ISetupCheckManager; use OCP\Share\IProviderFactory; +use OCP\Share\IPublicShareTemplateFactory; use OCP\Share\IShareHelper; use OCP\Snowflake\ISnowflakeDecoder; use OCP\Snowflake\ISnowflakeGenerator; use OCP\SpeechToText\ISpeechToTextManager; +use OCP\Support\Subscription\IAssertion; use OCP\SystemTag\ISystemTagManager; use OCP\SystemTag\ISystemTagObjectMapper; use OCP\Talk\IBroker; @@ -313,8 +333,8 @@ public function __construct( $this->registerAlias(\OCP\Contacts\IManager::class, ContactsManager::class); - $this->registerAlias(\OCP\ContextChat\IContentManager::class, \OC\ContextChat\ContentManager::class); - $this->registerAlias(\OCP\Files\ISetupManager::class, \OC\Files\SetupManager::class); + $this->registerAlias(IContentManager::class, ContentManager::class); + $this->registerAlias(ISetupManager::class, SetupManager::class); $this->registerAlias(\OCP\DirectEditing\IManager::class, \OC\DirectEditing\Manager::class); $this->registerAlias(ITemplateManager::class, TemplateManager::class); @@ -671,8 +691,8 @@ public function __construct( ); }); - $this->registerService(\OCP\Activity\IEventMerger::class, function (Server $c) { - return new \OC\Activity\EventMerger( + $this->registerService(IEventMerger::class, function (Server $c) { + return new EventMerger( $c->getL10N('lib') ); }); @@ -695,7 +715,7 @@ public function __construct( $this->registerAlias(\OCP\Support\CrashReport\IRegistry::class, \OC\Support\CrashReport\Registry::class); $this->registerAlias(\OCP\Support\Subscription\IRegistry::class, \OC\Support\Subscription\Registry::class); - $this->registerAlias(\OCP\Support\Subscription\IAssertion::class, Assertion::class); + $this->registerAlias(IAssertion::class, Assertion::class); /** Only used by the PsrLoggerAdapter should not be used by apps */ $this->registerService(Log::class, function (Server $c) { @@ -726,16 +746,16 @@ public function __construct( }); $this->registerAlias(IRouter::class, Router::class); - $this->registerService(\OC\Security\RateLimiting\Backend\IBackend::class, function ($c) { + $this->registerService(IBackend::class, function ($c) { $config = $c->get(IConfig::class); if (ltrim($config->getSystemValueString('memcache.distributed', ''), '\\') === Redis::class) { - $backend = new \OC\Security\RateLimiting\Backend\MemoryCacheBackend( + $backend = new MemoryCacheBackend( $c->get(AllConfig::class), $this->get(ICacheFactory::class), new TimeFactory() ); } else { - $backend = new \OC\Security\RateLimiting\Backend\DatabaseBackend( + $backend = new DatabaseBackend( $c->get(AllConfig::class), $c->get(IDBConnection::class), new TimeFactory() @@ -746,7 +766,7 @@ public function __construct( }); $this->registerAlias(ISecureRandom::class, SecureRandom::class); - $this->registerAlias(\OCP\Security\IRemoteHostValidator::class, RemoteHostValidator::class); + $this->registerAlias(IRemoteHostValidator::class, RemoteHostValidator::class); $this->registerAlias(IVerificationToken::class, VerificationToken::class); $this->registerAlias(ICrypto::class, Crypto::class); @@ -1127,7 +1147,7 @@ public function __construct( $this->registerService(SessionStorage::class, function (ContainerInterface $c) { return new SessionStorage($c->get(ISession::class)); }); - $this->registerAlias(\OCP\Security\IContentSecurityPolicyManager::class, ContentSecurityPolicyManager::class); + $this->registerAlias(IContentSecurityPolicyManager::class, ContentSecurityPolicyManager::class); $this->registerService(IProviderFactory::class, function (ContainerInterface $c) { $config = $c->get(IConfig::class); @@ -1138,8 +1158,8 @@ public function __construct( $this->registerAlias(\OCP\Share\IManager::class, \OC\Share20\Manager::class); - $this->registerService(\OCP\Collaboration\Collaborators\ISearch::class, function (Server $c): \OCP\Collaboration\Collaborators\ISearch { - $instance = new \OC\Collaboration\Collaborators\Search($c); + $this->registerService(ISearch::class, function (Server $c): ISearch { + $instance = new Search($c); // register default plugins $instance->registerPlugin(['shareType' => 'SHARE_TYPE_USER', 'class' => UserPlugin::class]); @@ -1151,11 +1171,11 @@ public function __construct( return $instance; }); - $this->registerAlias(\OCP\Collaboration\Collaborators\ISearchResult::class, \OC\Collaboration\Collaborators\SearchResult::class); + $this->registerAlias(ISearchResult::class, SearchResult::class); $this->registerAlias(\OCP\Collaboration\AutoComplete\IManager::class, \OC\Collaboration\AutoComplete\Manager::class); - $this->registerAlias(\OCP\Collaboration\Resources\IProviderManager::class, ProviderManager::class); + $this->registerAlias(IProviderManager::class, ProviderManager::class); $this->registerAlias(\OCP\Collaboration\Resources\IManager::class, \OC\Collaboration\Resources\Manager::class); $this->registerAlias(IReferenceManager::class, ReferenceManager::class); @@ -1176,7 +1196,7 @@ public function __construct( }); }); - $this->registerService(\OCP\OCS\IDiscoveryService::class, function (ContainerInterface $c): \OCP\OCS\IDiscoveryService { + $this->registerService(IDiscoveryService::class, function (ContainerInterface $c): IDiscoveryService { return new DiscoveryService( $c->get(ICacheFactory::class), $c->get(IClientService::class) @@ -1258,7 +1278,7 @@ public function __construct( $this->registerAlias(IBinaryFinder::class, BinaryFinder::class); - $this->registerAlias(\OCP\Share\IPublicShareTemplateFactory::class, PublicShareTemplateFactory::class); + $this->registerAlias(IPublicShareTemplateFactory::class, PublicShareTemplateFactory::class); $this->registerAlias(ITranslationManager::class, TranslationManager::class); @@ -1277,8 +1297,8 @@ public function __construct( $this->registerAlias(IPhoneNumberUtil::class, PhoneNumberUtil::class); // there is no reason for having OCMProvider as a Service (marked as deprecated since 32.0.0) - $this->registerDeprecatedAlias(\OCP\OCM\ICapabilityAwareOCMProvider::class, OCMProvider::class); - $this->registerDeprecatedAlias(\OCP\OCM\IOCMProvider::class, OCMProvider::class); + $this->registerDeprecatedAlias(ICapabilityAwareOCMProvider::class, OCMProvider::class); + $this->registerDeprecatedAlias(IOCMProvider::class, OCMProvider::class); $this->registerAlias(ISetupCheckManager::class, SetupCheckManager::class); diff --git a/lib/private/Share20/Manager.php b/lib/private/Share20/Manager.php index 586a1ff9c0d88..a8b968cf01dea 100644 --- a/lib/private/Share20/Manager.php +++ b/lib/private/Share20/Manager.php @@ -58,6 +58,7 @@ use OCP\Share\IProviderFactory; use OCP\Share\IShare; use OCP\Share\IShareProvider; +use OCP\Share\IShareProviderGetUsers; use OCP\Share\IShareProviderSupportsAccept; use OCP\Share\IShareProviderSupportsAllSharesInFolder; use OCP\Share\IShareProviderWithNotification; @@ -1547,7 +1548,7 @@ public function userDeletedFromGroup(string $uid, string $gid): void { } #[\Override] - public function getAccessList(\OCP\Files\Node $path, $recursive = true, $currentAccess = false): array { + public function getAccessList(Node $path, $recursive = true, $currentAccess = false): array { $owner = $path->getOwner(); if ($owner === null) { @@ -1942,7 +1943,7 @@ private function dispatchEvent(Event $event, string $name): void { public function getUsersForShare(IShare $share): iterable { $provider = $this->factory->getProviderForType($share->getShareType()); - if ($provider instanceof Share\IShareProviderGetUsers) { + if ($provider instanceof IShareProviderGetUsers) { return $provider->getUsersForShare($share); } else { return []; diff --git a/lib/private/User/Manager.php b/lib/private/User/Manager.php index 36b9f80dd991c..5c899b7892f21 100644 --- a/lib/private/User/Manager.php +++ b/lib/private/User/Manager.php @@ -664,7 +664,7 @@ private function getSeenUserIds($limit = null, $offset = null) { * @internal Only for mocks it in unit tests. */ public function getUserConfig(): IUserConfig { - return \OCP\Server::get(IUserConfig::class); + return Server::get(IUserConfig::class); } /** diff --git a/lib/private/legacy/OC_User.php b/lib/private/legacy/OC_User.php index abdb37b737cc3..ddd426da942e4 100644 --- a/lib/private/legacy/OC_User.php +++ b/lib/private/legacy/OC_User.php @@ -9,6 +9,7 @@ use OC\SystemConfig; use OC\User\Database; use OC\User\DisabledUserException; +use OC\User\Session; use OCP\Authentication\Exceptions\InvalidTokenException; use OCP\Authentication\Exceptions\WipeTokenException; use OCP\Authentication\IApacheBackend; @@ -151,7 +152,7 @@ public static function loginWithApache(IApacheBackend $backend): bool { if ($uid) { if (self::getUser() !== $uid) { self::setUserId($uid); - /** @var \OC\User\Session $userSession */ + /** @var Session $userSession */ $userSession = Server::get(IUserSession::class); /** @var IEventDispatcher $dispatcher */ @@ -234,7 +235,7 @@ public static function handleApacheAuth(): ?bool { //setup extra user backends self::setupBackends(); - /** @var \OC\User\Session $session */ + /** @var Session $session */ $session = Server::get(IUserSession::class); $session->unsetMagicInCookie(); diff --git a/lib/private/legacy/OC_Util.php b/lib/private/legacy/OC_Util.php index 0a38062e553ca..b3b0f4e3e20ca 100644 --- a/lib/private/legacy/OC_Util.php +++ b/lib/private/legacy/OC_Util.php @@ -12,6 +12,7 @@ use OC\Files\SetupManager; use OC\Setup; use OC\SystemConfig; +use OCP\App\IAppManager; use OCP\Files\FileInfo; use OCP\Files\Folder; use OCP\Files\NotFoundException; @@ -787,14 +788,14 @@ public static function normalizeUnicode(string $value): string { * @deprecated 32.0.0 Use \OCP\Util::needUpgrade() instead. * @see \OCP\Util::needUpgrade */ - public static function needUpgrade(\OC\SystemConfig $config): bool { + public static function needUpgrade(SystemConfig $config): bool { if (!$config->getValue('installed', false)) { // not installed (nothing to do) return false; } $installedVersion = (string)$config->getValue('version', '0.0.0'); - $codeVersion = implode('.', \OCP\Util::getVersion()); + $codeVersion = implode('.', Util::getVersion()); // codebase newer: upgrade needed if (version_compare($codeVersion, $installedVersion, '>')) { @@ -815,12 +816,12 @@ public static function needUpgrade(\OC\SystemConfig $config): bool { // disallow downgrade (not in debug mode or major.minor mismatch) /** @var \Psr\Log\LoggerInterface $logger */ - $logger = \OCP\Server::get(LoggerInterface::class); + $logger = Server::get(LoggerInterface::class); $logger->error( 'Detected downgrade attempt from installed {installed} to code {code}', [ 'installed' => $installedVersion, 'code' => $codeVersion, 'app' => 'core', ] ); - throw new \OCP\HintException(sprintf( + throw new HintException(sprintf( 'Downgrading Nextcloud from %s to %s is not supported and may corrupt your instance (database and data directory). ' . 'Restore a full backup (code, database, and data directory) taken before the change, ' . 'or restore the previous codebase so that it matches the installed version (version %s).', @@ -829,7 +830,7 @@ public static function needUpgrade(\OC\SystemConfig $config): bool { } // versions are equal: check whether any enabled apps need upgrading - $appManager = \OCP\Server::get(\OCP\App\IAppManager::class); + $appManager = Server::get(IAppManager::class); $apps = $appManager->getEnabledApps(); foreach ($apps as $app) { if ($appManager->isUpgradeRequired($app)) { diff --git a/tests/Core/Controller/ClientFlowLoginControllerTest.php b/tests/Core/Controller/ClientFlowLoginControllerTest.php index 7a5bbbec82d5a..39d915e04bce9 100644 --- a/tests/Core/Controller/ClientFlowLoginControllerTest.php +++ b/tests/Core/Controller/ClientFlowLoginControllerTest.php @@ -161,7 +161,7 @@ public function testShowAuthPickerPageWithOcsHeader(): void { $initialState = []; $this->initialState->expects($this->exactly(2)) ->method('provideInitialState') - ->willReturnCallback(function () use (&$initialState) { + ->willReturnCallback(function () use (&$initialState): void { $initialState[] = func_get_args(); }); @@ -240,7 +240,7 @@ public function testShowAuthPickerPageWithOauth(): void { $initialState = []; $this->initialState->expects($this->exactly(2)) ->method('provideInitialState') - ->willReturnCallback(function () use (&$initialState) { + ->willReturnCallback(function () use (&$initialState): void { $initialState[] = func_get_args(); }); diff --git a/tests/Core/Controller/OpenMetricsControllerTest.php b/tests/Core/Controller/OpenMetricsControllerTest.php index 56e40cdf7d773..fdc81ad5d2c0e 100644 --- a/tests/Core/Controller/OpenMetricsControllerTest.php +++ b/tests/Core/Controller/OpenMetricsControllerTest.php @@ -59,7 +59,7 @@ public function testGetMetrics(): void { $output = $this->createMock(IOutput::class); $fullOutput = ''; $output->method('setOutput') - ->willReturnCallback(function ($output) use (&$fullOutput) { + ->willReturnCallback(function ($output) use (&$fullOutput): void { $fullOutput .= $output; }); $this->config->expects($this->once()) diff --git a/tests/lib/Collaboration/Collaborators/MailPluginTest.php b/tests/lib/Collaboration/Collaborators/MailPluginTest.php index cf39642280c20..9a0928a82e9f3 100644 --- a/tests/lib/Collaboration/Collaborators/MailPluginTest.php +++ b/tests/lib/Collaboration/Collaborators/MailPluginTest.php @@ -970,7 +970,7 @@ function ($appName, $key, $default) { $this->instantiatePlugin(IShare::TYPE_USER); - $currentUser = $this->createMock(\OCP\IUser::class); + $currentUser = $this->createMock(IUser::class); $currentUser->expects($this->any()) ->method('getUID') diff --git a/tests/lib/DB/MigrationServiceTest.php b/tests/lib/DB/MigrationServiceTest.php index c2c8cdc03cc9b..0142c36ee264c 100644 --- a/tests/lib/DB/MigrationServiceTest.php +++ b/tests/lib/DB/MigrationServiceTest.php @@ -224,7 +224,7 @@ public function testMigrate(): void { $migrationService ->expects($this->exactly(2)) ->method('executeStep') - ->willReturnCallback(function (string $migration) use (&$calls) { + ->willReturnCallback(function (string $migration) use (&$calls): void { $calls[] = $migration; }); diff --git a/tests/lib/Files/SetupManagerTest.php b/tests/lib/Files/SetupManagerTest.php index 673b0fc738cbc..f70358691cde4 100644 --- a/tests/lib/Files/SetupManagerTest.php +++ b/tests/lib/Files/SetupManagerTest.php @@ -633,7 +633,7 @@ public function testSetupForProviderResetsUserProviderPaths(): void { } private function getAddMountCheckCallback(InvokedCount $invokedCount, $expectations): \Closure { - return function (IMountPoint $actualMount) use ($invokedCount, $expectations) { + return function (IMountPoint $actualMount) use ($invokedCount, $expectations): void { $expectedMount = $expectations[$invokedCount->numberOfInvocations()] ?? null; $this->assertSame($expectedMount, $actualMount); }; diff --git a/tests/lib/Files/Template/TemplateManagerTest.php b/tests/lib/Files/Template/TemplateManagerTest.php index 7b3f0beff429d..431b032594c14 100644 --- a/tests/lib/Files/Template/TemplateManagerTest.php +++ b/tests/lib/Files/Template/TemplateManagerTest.php @@ -24,6 +24,8 @@ use OCP\IPreview; use OCP\IServerContainer; use OCP\IUser; +use OCP\IUserManager; +use OCP\IUserSession; use OCP\L10N\IFactory; use Psr\Log\NullLogger; use Test\TestCase; @@ -64,10 +66,10 @@ protected function setUp(): void { $this->rootFolder = $this->createMock(IRootFolder::class); $user = $this->createMock(IUser::class); $user->method('getUID')->willReturn('user1'); - $userSession = $this->createMock(\OCP\IUserSession::class); + $userSession = $this->createMock(IUserSession::class); $userSession->method('getUser') ->willReturn($user); - $userManager = $this->createMock(\OCP\IUserManager::class); + $userManager = $this->createMock(IUserManager::class); $previewManager = $this->createMock(IPreview::class); $this->templateManager = new TemplateManager( diff --git a/tests/lib/OCM/Listeners/LocalOCMDiscoveryTestEvent.php b/tests/lib/OCM/Listeners/LocalOCMDiscoveryTestEvent.php index 7553d9f1b74b3..b2d0e7d09f671 100644 --- a/tests/lib/OCM/Listeners/LocalOCMDiscoveryTestEvent.php +++ b/tests/lib/OCM/Listeners/LocalOCMDiscoveryTestEvent.php @@ -10,6 +10,7 @@ use OCP\EventDispatcher\Event; use OCP\EventDispatcher\IEventListener; +use OCP\OCM\Events\LocalOCMDiscoveryEvent; /** @template-implements IEventListener<\OCP\OCM\Events\LocalOCMDiscoveryEvent> */ class LocalOCMDiscoveryTestEvent implements IEventListener { @@ -18,7 +19,7 @@ public function __construct( } public function handle(Event $event): void { - if (!($event instanceof \OCP\OCM\Events\LocalOCMDiscoveryEvent)) { + if (!($event instanceof LocalOCMDiscoveryEvent)) { return; } diff --git a/tests/lib/OCM/Listeners/OCMEndpointRequestTestEvent.php b/tests/lib/OCM/Listeners/OCMEndpointRequestTestEvent.php index f0b706fe39b79..bbe36a529fd57 100644 --- a/tests/lib/OCM/Listeners/OCMEndpointRequestTestEvent.php +++ b/tests/lib/OCM/Listeners/OCMEndpointRequestTestEvent.php @@ -12,6 +12,8 @@ use OCP\AppFramework\Http\Response; use OCP\EventDispatcher\Event; use OCP\EventDispatcher\IEventListener; +use OCP\OCM\Enum\ParamType; +use OCP\OCM\Events\OCMEndpointRequestEvent; /** @template-implements IEventListener<\OCP\OCM\Events\OCMEndpointRequestEvent> */ class OCMEndpointRequestTestEvent implements IEventListener { @@ -20,7 +22,7 @@ public function __construct( } public function handle(Event $event): void { - if (!($event instanceof \OCP\OCM\Events\OCMEndpointRequestEvent)) { + if (!($event instanceof OCMEndpointRequestEvent)) { return; } @@ -36,11 +38,11 @@ public function handle(Event $event): void { 'args' => $event->getArgs(), 'totalArgs' => $event->getArgsCount(), 'typedArgs' => $event->getArgs( - \OCP\OCM\Enum\ParamType::STRING, - \OCP\OCM\Enum\ParamType::STRING, - \OCP\OCM\Enum\ParamType::INT, - \OCP\OCM\Enum\ParamType::BOOL, - \OCP\OCM\Enum\ParamType::INT + ParamType::STRING, + ParamType::STRING, + ParamType::INT, + ParamType::BOOL, + ParamType::INT ) ] )); diff --git a/tests/lib/Preview/PostscriptTest.php b/tests/lib/Preview/PostscriptTest.php index 5fb7abc5201ca..e5cc15ee7f4c5 100644 --- a/tests/lib/Preview/PostscriptTest.php +++ b/tests/lib/Preview/PostscriptTest.php @@ -10,6 +10,7 @@ use OC\BinaryFinder; use OC\Preview\Postscript; +use OCP\Server; #[\PHPUnit\Framework\Attributes\Group('DB')] #[\PHPUnit\Framework\Attributes\RequiresPhpExtension('imagick')] @@ -19,7 +20,7 @@ protected function setUp(): void { if (\Imagick::queryFormats('EPS') === false || \Imagick::queryFormats('PS') === false) { $this->markTestSkipped('Imagick does not support postscript.'); } - if (\OCP\Server::get(BinaryFinder::class)->findBinaryPath('gs') === false) { + if (Server::get(BinaryFinder::class)->findBinaryPath('gs') === false) { // Imagick forwards postscript rendering to Ghostscript but does not report this in queryFormats $this->markTestSkipped('Ghostscript is not installed.'); } diff --git a/tests/lib/TestCase.php b/tests/lib/TestCase.php index 551c1024e0bef..c40c05b3de773 100644 --- a/tests/lib/TestCase.php +++ b/tests/lib/TestCase.php @@ -23,6 +23,7 @@ use OC\Files\View; use OC\Installer; use OC\Updater; +use OC\User\Session; use OCP\Command\IBus; use OCP\DB\QueryBuilder\IQueryBuilder; use OCP\Files\IRootFolder; @@ -442,7 +443,7 @@ protected static function loginAsUser(string $user = ''): void { */ protected static function logout(): void { Server::get(SetupManager::class)->tearDown(); - $userSession = Server::get(\OC\User\Session::class); + $userSession = Server::get(Session::class); $userSession->getSession()->set('user_id', ''); // needed for fully logout $userSession->setUser(null);