aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFerdinand Thiessen <opensource@fthiessen.de>2025-07-21 15:51:58 +0200
committerFerdinand Thiessen <opensource@fthiessen.de>2025-07-23 15:59:26 +0200
commit66eb021ece1ac83b67c8649b2a145e0e1a963e39 (patch)
treec9dbfe9081eee644d302d890939f8763a7ebd950
parentbffac23322a7ca1f3f1aae279c10b5f807c47ae2 (diff)
downloadnextcloud-server-enh/add-cloud-id-chars.tar.gz
nextcloud-server-enh/add-cloud-id-chars.zip
refactor: remove duplicated types and add return typesenh/add-cloud-id-chars
Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
-rw-r--r--apps/federatedfilesharing/tests/AddressHandlerTest.php4
-rw-r--r--apps/federatedfilesharing/tests/Controller/MountPublicLinkControllerTest.php4
-rw-r--r--apps/federatedfilesharing/tests/FederatedShareProviderTest.php4
-rw-r--r--apps/files_sharing/tests/External/CacheTest.php4
-rw-r--r--apps/files_sharing/tests/External/ManagerTest.php4
-rw-r--r--lib/private/Federation/CloudIdManager.php41
-rw-r--r--lib/private/Server.php4
-rw-r--r--lib/public/Federation/ICloudIdManager.php20
-rw-r--r--lib/public/Federation/ICloudIdResolver.php5
-rw-r--r--tests/lib/Collaboration/Collaborators/MailPluginTest.php4
-rw-r--r--tests/lib/Collaboration/Collaborators/RemotePluginTest.php4
-rw-r--r--tests/lib/Federation/CloudIdManagerTest.php4
12 files changed, 40 insertions, 62 deletions
diff --git a/apps/federatedfilesharing/tests/AddressHandlerTest.php b/apps/federatedfilesharing/tests/AddressHandlerTest.php
index 9b67e3e1848..279bf485145 100644
--- a/apps/federatedfilesharing/tests/AddressHandlerTest.php
+++ b/apps/federatedfilesharing/tests/AddressHandlerTest.php
@@ -34,11 +34,11 @@ class AddressHandlerTest extends \Test\TestCase {
$this->contactsManager = $this->createMock(IManager::class);
$this->cloudIdManager = new CloudIdManager(
+ $this->createMock(ICacheFactory::class),
+ $this->createMock(IEventDispatcher::class),
$this->contactsManager,
$this->urlGenerator,
$this->createMock(IUserManager::class),
- $this->createMock(ICacheFactory::class),
- $this->createMock(IEventDispatcher::class)
);
$this->addressHandler = new AddressHandler($this->urlGenerator, $this->il10n, $this->cloudIdManager);
diff --git a/apps/federatedfilesharing/tests/Controller/MountPublicLinkControllerTest.php b/apps/federatedfilesharing/tests/Controller/MountPublicLinkControllerTest.php
index cb890417d0b..e99b59e82b8 100644
--- a/apps/federatedfilesharing/tests/Controller/MountPublicLinkControllerTest.php
+++ b/apps/federatedfilesharing/tests/Controller/MountPublicLinkControllerTest.php
@@ -64,11 +64,11 @@ class MountPublicLinkControllerTest extends \Test\TestCase {
$this->clientService = $this->createMock(IClientService::class);
$this->contactsManager = $this->createMock(IContactsManager::class);
$this->cloudIdManager = new CloudIdManager(
+ $this->createMock(ICacheFactory::class),
+ $this->createMock(IEventDispatcher::class),
$this->contactsManager,
$this->createMock(IURLGenerator::class),
$this->userManager,
- $this->createMock(ICacheFactory::class),
- $this->createMock(IEventDispatcher::class)
);
$this->controller = new MountPublicLinkController(
diff --git a/apps/federatedfilesharing/tests/FederatedShareProviderTest.php b/apps/federatedfilesharing/tests/FederatedShareProviderTest.php
index 4d6add962fe..7e97510af22 100644
--- a/apps/federatedfilesharing/tests/FederatedShareProviderTest.php
+++ b/apps/federatedfilesharing/tests/FederatedShareProviderTest.php
@@ -74,11 +74,11 @@ class FederatedShareProviderTest extends \Test\TestCase {
$this->addressHandler = $this->createMock(AddressHandler::class);
$this->contactsManager = $this->createMock(IContactsManager::class);
$this->cloudIdManager = new CloudIdManager(
+ $this->createMock(ICacheFactory::class),
+ $this->createMock(IEventDispatcher::class),
$this->contactsManager,
$this->createMock(IURLGenerator::class),
$this->userManager,
- $this->createMock(ICacheFactory::class),
- $this->createMock(IEventDispatcher::class)
);
$this->gsConfig = $this->createMock(\OCP\GlobalScale\IConfig::class);
diff --git a/apps/files_sharing/tests/External/CacheTest.php b/apps/files_sharing/tests/External/CacheTest.php
index 60820013f11..39e2057a24c 100644
--- a/apps/files_sharing/tests/External/CacheTest.php
+++ b/apps/files_sharing/tests/External/CacheTest.php
@@ -54,11 +54,11 @@ class CacheTest extends TestCase {
$this->contactsManager = $this->createMock(IManager::class);
$this->cloudIdManager = new CloudIdManager(
+ $this->createMock(ICacheFactory::class),
+ $this->createMock(IEventDispatcher::class),
$this->contactsManager,
$this->createMock(IURLGenerator::class),
$this->createMock(IUserManager::class),
- $this->createMock(ICacheFactory::class),
- $this->createMock(IEventDispatcher::class)
);
$this->remoteUser = $this->getUniqueID('remoteuser');
diff --git a/apps/files_sharing/tests/External/ManagerTest.php b/apps/files_sharing/tests/External/ManagerTest.php
index fbe6eb1e85b..14c6afec4d8 100644
--- a/apps/files_sharing/tests/External/ManagerTest.php
+++ b/apps/files_sharing/tests/External/ManagerTest.php
@@ -90,11 +90,11 @@ class ManagerTest extends TestCase {
$this->testMountProvider = new MountProvider(Server::get(IDBConnection::class), function () {
return $this->manager;
}, new CloudIdManager(
+ $this->createMock(ICacheFactory::class),
+ $this->createMock(IEventDispatcher::class),
$this->contactsManager,
$this->createMock(IURLGenerator::class),
$this->userManager,
- $this->createMock(ICacheFactory::class),
- $this->createMock(IEventDispatcher::class)
));
$group1 = $this->createMock(IGroup::class);
diff --git a/lib/private/Federation/CloudIdManager.php b/lib/private/Federation/CloudIdManager.php
index edd5be3cae6..c599d9046a6 100644
--- a/lib/private/Federation/CloudIdManager.php
+++ b/lib/private/Federation/CloudIdManager.php
@@ -22,29 +22,19 @@ use OCP\IUserManager;
use OCP\User\Events\UserChangedEvent;
class CloudIdManager implements ICloudIdManager {
- /** @var IManager */
- private $contactsManager;
- /** @var IURLGenerator */
- private $urlGenerator;
- /** @var IUserManager */
- private $userManager;
private ICache $memCache;
private ICache $displayNameCache;
- /** @var array[] */
private array $cache = [];
/** @var ICloudIdResolver[] */
private array $cloudIdResolvers = [];
public function __construct(
- IManager $contactsManager,
- IURLGenerator $urlGenerator,
- IUserManager $userManager,
ICacheFactory $cacheFactory,
IEventDispatcher $eventDispatcher,
+ private IManager $contactsManager,
+ private IURLGenerator $urlGenerator,
+ private IUserManager $userManager,
) {
- $this->contactsManager = $contactsManager;
- $this->urlGenerator = $urlGenerator;
- $this->userManager = $userManager;
$this->memCache = $cacheFactory->createDistributed('cloud_id_');
$this->displayNameCache = $cacheFactory->createDistributed('cloudid_name_');
$eventDispatcher->addListener(UserChangedEvent::class, [$this, 'handleUserEvent']);
@@ -83,7 +73,7 @@ class CloudIdManager implements ICloudIdManager {
*/
public function resolveCloudId(string $cloudId): ICloudId {
// TODO magic here to get the url and user instead of just splitting on @
-
+
foreach ($this->cloudIdResolvers as $resolver) {
if ($resolver->isValidCloudId($cloudId)) {
return $resolver->resolveCloudId($cloudId);
@@ -269,34 +259,15 @@ class CloudIdManager implements ICloudIdManager {
return strpos($cloudId, '@') !== false;
}
- /**
- * @param string $id,
- * @param string $user
- * @param string $remote
- * @param ?string $displayName
- * @return ICloudId
- *
- * @since 32.0.0
- */
public function createCloudId(string $id, string $user, string $remote, ?string $displayName = null): ICloudId {
return new CloudId($id, $user, $remote, $displayName);
}
- /**
- * @param ICloudIdResolver $resolver
- *
- * @since 32.0.0
- */
- public function registerCloudIdResolver(ICloudIdResolver $resolver) {
+ public function registerCloudIdResolver(ICloudIdResolver $resolver): void {
array_unshift($this->cloudIdResolvers, $resolver);
}
- /**
- * @param ICloudIdResolver $resolver
- *
- * @since 32.0.0
- */
- public function unregisterCloudIdResolver(ICloudIdResolver $resolver) {
+ public function unregisterCloudIdResolver(ICloudIdResolver $resolver): void {
if (($key = array_search($resolver, $this->cloudIdResolvers)) !== false) {
array_splice($this->cloudIdResolvers, $key, 1);
}
diff --git a/lib/private/Server.php b/lib/private/Server.php
index 1e1ba2a1ad3..8e105ba6b1c 100644
--- a/lib/private/Server.php
+++ b/lib/private/Server.php
@@ -1161,11 +1161,11 @@ class Server extends ServerContainer implements IServerContainer {
$this->registerService(ICloudIdManager::class, function (ContainerInterface $c) {
return new CloudIdManager(
+ $c->get(ICacheFactory::class),
+ $c->get(IEventDispatcher::class),
$c->get(\OCP\Contacts\IManager::class),
$c->get(IURLGenerator::class),
$c->get(IUserManager::class),
- $c->get(ICacheFactory::class),
- $c->get(IEventDispatcher::class),
);
});
diff --git a/lib/public/Federation/ICloudIdManager.php b/lib/public/Federation/ICloudIdManager.php
index 00c7e40da4c..29e261ab3af 100644
--- a/lib/public/Federation/ICloudIdManager.php
+++ b/lib/public/Federation/ICloudIdManager.php
@@ -8,11 +8,14 @@ declare(strict_types=1);
*/
namespace OCP\Federation;
+use OCP\AppFramework\Attribute\Consumable;
+
/**
* Interface for resolving federated cloud ids
*
* @since 12.0.0
*/
+#[Consumable(since: '12.0.0')]
interface ICloudIdManager {
/**
* @param string $cloudId
@@ -57,27 +60,26 @@ interface ICloudIdManager {
public function removeProtocolFromUrl(string $url, bool $httpsOnly = false): string;
/**
- * @param string $id,
- * @param string $user
- * @param string $remote
- * @param ?string $displayName
- * @return ICloudId
+ * @param string $id The remote cloud id
+ * @param string $user The user id on the remote server
+ * @param string $remote The base address of the remote server
+ * @param ?string $displayName The displayname of the remote user
*
* @since 32.0.0
*/
public function createCloudId(string $id, string $user, string $remote, ?string $displayName = null): ICloudId;
/**
- * @param ICloudIdResolver $resolver
+ * @param $resolver The cloud id resolver to register
*
* @since 32.0.0
*/
- public function registerCloudIdResolver(ICloudIdResolver $resolver);
+ public function registerCloudIdResolver(ICloudIdResolver $resolver): void;
/**
- * @param ICloudIdResolver $resolver
+ * @param $resolver The cloud id resolver to unregister
*
* @since 32.0.0
*/
- public function unregisterCloudIdResolver(ICloudIdResolver $resolver);
+ public function unregisterCloudIdResolver(ICloudIdResolver $resolver): void;
}
diff --git a/lib/public/Federation/ICloudIdResolver.php b/lib/public/Federation/ICloudIdResolver.php
index 59dc0eb095c..79f9ed11dd7 100644
--- a/lib/public/Federation/ICloudIdResolver.php
+++ b/lib/public/Federation/ICloudIdResolver.php
@@ -8,11 +8,16 @@ declare(strict_types=1);
*/
namespace OCP\Federation;
+use OCP\AppFramework\Attribute\Consumable;
+use OCP\AppFramework\Attribute\Implementable;
+
/**
* Interface for resolving federated cloud ids
*
* @since 32.0.0
*/
+#[Consumable(since: '32.0.0')]
+#[Implementable(since: '32.0.0')]
interface ICloudIdResolver {
/**
* @param string $cloudId
diff --git a/tests/lib/Collaboration/Collaborators/MailPluginTest.php b/tests/lib/Collaboration/Collaborators/MailPluginTest.php
index 502b7844a2a..b38b961a512 100644
--- a/tests/lib/Collaboration/Collaborators/MailPluginTest.php
+++ b/tests/lib/Collaboration/Collaborators/MailPluginTest.php
@@ -64,11 +64,11 @@ class MailPluginTest extends TestCase {
$this->userSession = $this->createMock(IUserSession::class);
$this->mailer = $this->createMock(IMailer::class);
$this->cloudIdManager = new CloudIdManager(
+ $this->createMock(ICacheFactory::class),
+ $this->createMock(IEventDispatcher::class),
$this->contactsManager,
$this->createMock(IURLGenerator::class),
$this->createMock(IUserManager::class),
- $this->createMock(ICacheFactory::class),
- $this->createMock(IEventDispatcher::class)
);
$this->searchResult = new SearchResult();
diff --git a/tests/lib/Collaboration/Collaborators/RemotePluginTest.php b/tests/lib/Collaboration/Collaborators/RemotePluginTest.php
index ea81b1cbcdc..a9a5e05dfe4 100644
--- a/tests/lib/Collaboration/Collaborators/RemotePluginTest.php
+++ b/tests/lib/Collaboration/Collaborators/RemotePluginTest.php
@@ -49,11 +49,11 @@ class RemotePluginTest extends TestCase {
$this->config = $this->createMock(IConfig::class);
$this->contactsManager = $this->createMock(IManager::class);
$this->cloudIdManager = new CloudIdManager(
+ $this->createMock(ICacheFactory::class),
+ $this->createMock(IEventDispatcher::class),
$this->contactsManager,
$this->createMock(IURLGenerator::class),
$this->createMock(IUserManager::class),
- $this->createMock(ICacheFactory::class),
- $this->createMock(IEventDispatcher::class)
);
$this->searchResult = new SearchResult();
}
diff --git a/tests/lib/Federation/CloudIdManagerTest.php b/tests/lib/Federation/CloudIdManagerTest.php
index 3bd3cf6149d..cf97c895dc1 100644
--- a/tests/lib/Federation/CloudIdManagerTest.php
+++ b/tests/lib/Federation/CloudIdManagerTest.php
@@ -47,11 +47,11 @@ class CloudIdManagerTest extends TestCase {
->willReturn(new ArrayCache(''));
$this->cloudIdManager = new CloudIdManager(
+ $this->cacheFactory,
+ $this->createMock(IEventDispatcher::class),
$this->contactsManager,
$this->urlGenerator,
$this->userManager,
- $this->cacheFactory,
- $this->createMock(IEventDispatcher::class)
);
$this->overwriteService(ICloudIdManager::class, $this->cloudIdManager);
}