refactor: remove duplicated types and add return types

Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
pull/54026/head
Ferdinand Thiessen 2025-07-21 15:51:58 +07:00
parent bffac23322
commit 66eb021ece
No known key found for this signature in database
GPG Key ID: 45FAE7268762B400
12 changed files with 40 additions and 62 deletions

@ -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);

@ -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(

@ -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);

@ -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');

@ -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);

@ -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);
}

@ -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),
);
});

@ -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;
}

@ -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

@ -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();

@ -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();
}

@ -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);
}