From 9f2487d14b4fbf8a5ec58a74bc6db5eb5cd27bc1 Mon Sep 17 00:00:00 2001 From: Faraz Samapoor Date: Sun, 25 Jun 2023 11:56:58 +0330 Subject: [PATCH] Refactors lib/private/Contacts. Mainly using PHP8's constructor property promotion. Signed-off-by: Faraz Samapoor --- .../ContactsMenu/ActionProviderStore.php | 15 +++----- .../ContactsMenu/Actions/LinkAction.php | 10 +++--- .../Contacts/ContactsMenu/ContactsStore.php | 35 +++++-------------- lib/private/Contacts/ContactsMenu/Entry.php | 9 +---- lib/private/Contacts/ContactsMenu/Manager.php | 22 ++++-------- .../ContactsMenu/Providers/EMailProvider.php | 15 +++----- .../Providers/LocalTimeProvider.php | 34 +++++------------- .../Providers/ProfileProvider.php | 26 ++++---------- 8 files changed, 45 insertions(+), 121 deletions(-) diff --git a/lib/private/Contacts/ContactsMenu/ActionProviderStore.php b/lib/private/Contacts/ContactsMenu/ActionProviderStore.php index 485895de646..7ba5db4bb33 100644 --- a/lib/private/Contacts/ContactsMenu/ActionProviderStore.php +++ b/lib/private/Contacts/ContactsMenu/ActionProviderStore.php @@ -39,18 +39,14 @@ use OCP\IUser; use Psr\Log\LoggerInterface; class ActionProviderStore { - private IServerContainer $serverContainer; - private AppManager $appManager; - private LoggerInterface $logger; - - public function __construct(IServerContainer $serverContainer, AppManager $appManager, LoggerInterface $logger) { - $this->serverContainer = $serverContainer; - $this->appManager = $appManager; - $this->logger = $logger; + public function __construct( + private IServerContainer $serverContainer, + private AppManager $appManager, + private LoggerInterface $logger, + ) { } /** - * @param IUser $user * @return IProvider[] * @throws Exception */ @@ -90,7 +86,6 @@ class ActionProviderStore { } /** - * @param IUser $user * @return string[] */ private function getAppProviderClasses(IUser $user): array { diff --git a/lib/private/Contacts/ContactsMenu/Actions/LinkAction.php b/lib/private/Contacts/ContactsMenu/Actions/LinkAction.php index a3054c9ee52..9fc021435a4 100644 --- a/lib/private/Contacts/ContactsMenu/Actions/LinkAction.php +++ b/lib/private/Contacts/ContactsMenu/Actions/LinkAction.php @@ -34,11 +34,11 @@ class LinkAction implements ILinkAction { /** * @param string $icon absolute URI to an icon */ - public function setIcon(string $icon) { + public function setIcon(string $icon): void { $this->icon = $icon; } - public function setName(string $name) { + public function setName(string $name): void { $this->name = $name; } @@ -46,7 +46,7 @@ class LinkAction implements ILinkAction { return $this->name; } - public function setPriority(int $priority) { + public function setPriority(int $priority): void { $this->priority = $priority; } @@ -54,7 +54,7 @@ class LinkAction implements ILinkAction { return $this->priority; } - public function setHref(string $href) { + public function setHref(string $href): void { $this->href = $href; } @@ -65,7 +65,7 @@ class LinkAction implements ILinkAction { /** * @since 23.0.0 */ - public function setAppId(string $appId) { + public function setAppId(string $appId): void { $this->appId = $appId; } diff --git a/lib/private/Contacts/ContactsMenu/ContactsStore.php b/lib/private/Contacts/ContactsMenu/ContactsStore.php index e4dd80645ea..c692b486ae4 100644 --- a/lib/private/Contacts/ContactsMenu/ContactsStore.php +++ b/lib/private/Contacts/ContactsMenu/ContactsStore.php @@ -44,33 +44,16 @@ use OCP\IUserManager; use OCP\L10N\IFactory as IL10NFactory; class ContactsStore implements IContactsStore { - private IManager $contactsManager; - private IConfig $config; - private ProfileManager $profileManager; - private IUserManager $userManager; - private IURLGenerator $urlGenerator; - private IGroupManager $groupManager; - private KnownUserService $knownUserService; - private IL10NFactory $l10nFactory; - public function __construct( - IManager $contactsManager, - IConfig $config, - ProfileManager $profileManager, - IUserManager $userManager, - IURLGenerator $urlGenerator, - IGroupManager $groupManager, - KnownUserService $knownUserService, - IL10NFactory $l10nFactory + private IManager $contactsManager, + private IConfig $config, + private ProfileManager $profileManager, + private IUserManager $userManager, + private IURLGenerator $urlGenerator, + private IGroupManager $groupManager, + private KnownUserService $knownUserService, + private IL10NFactory $l10nFactory, ) { - $this->contactsManager = $contactsManager; - $this->config = $config; - $this->profileManager = $profileManager; - $this->userManager = $userManager; - $this->urlGenerator = $urlGenerator; - $this->groupManager = $groupManager; - $this->knownUserService = $knownUserService; - $this->l10nFactory = $l10nFactory; } /** @@ -126,9 +109,7 @@ class ContactsStore implements IContactsStore { * enabled it will filter all users which doesn't have a common group * with the current user. * - * @param IUser $self * @param Entry[] $entries - * @param string|null $filter * @return Entry[] the filtered contacts */ private function filterContacts( diff --git a/lib/private/Contacts/ContactsMenu/Entry.php b/lib/private/Contacts/ContactsMenu/Entry.php index 51fde760407..649c83ae7d8 100644 --- a/lib/private/Contacts/ContactsMenu/Entry.php +++ b/lib/private/Contacts/ContactsMenu/Entry.php @@ -134,20 +134,13 @@ class Entry implements IEntry { $this->properties = $contact; } - /** - * @param string $key - * @return mixed - */ - public function getProperty(string $key) { + public function getProperty(string $key): mixed { if (!isset($this->properties[$key])) { return null; } return $this->properties[$key]; } - /** - * @return array - */ public function jsonSerialize(): array { $topAction = !empty($this->actions) ? $this->actions[0]->jsonSerialize() : null; $otherActions = array_map(function (IAction $action) { diff --git a/lib/private/Contacts/ContactsMenu/Manager.php b/lib/private/Contacts/ContactsMenu/Manager.php index 5c3367a3d09..490cf602283 100644 --- a/lib/private/Contacts/ContactsMenu/Manager.php +++ b/lib/private/Contacts/ContactsMenu/Manager.php @@ -33,22 +33,15 @@ use OCP\IConfig; use OCP\IUser; class Manager { - private ContactsStore $store; - private ActionProviderStore $actionProviderStore; - private IAppManager $appManager; - private IConfig $config; - - public function __construct(ContactsStore $store, ActionProviderStore $actionProviderStore, IAppManager $appManager, IConfig $config) { - $this->store = $store; - $this->actionProviderStore = $actionProviderStore; - $this->appManager = $appManager; - $this->config = $config; + public function __construct( + private ContactsStore $store, + private ActionProviderStore $actionProviderStore, + private IAppManager $appManager, + private IConfig $config, + ) { } /** - * @param IUser $user - * @param string|null $filter - * @return array * @throws Exception */ public function getEntries(IUser $user, ?string $filter): array { @@ -95,10 +88,9 @@ class Manager { /** * @param IEntry[] $entries - * @param IUser $user * @throws Exception */ - private function processEntries(array $entries, IUser $user) { + private function processEntries(array $entries, IUser $user): void { $providers = $this->actionProviderStore->getProviders($user); foreach ($entries as $entry) { foreach ($providers as $provider) { diff --git a/lib/private/Contacts/ContactsMenu/Providers/EMailProvider.php b/lib/private/Contacts/ContactsMenu/Providers/EMailProvider.php index b79052e1f5d..145c30a2ce7 100644 --- a/lib/private/Contacts/ContactsMenu/Providers/EMailProvider.php +++ b/lib/private/Contacts/ContactsMenu/Providers/EMailProvider.php @@ -28,18 +28,13 @@ use OCP\Contacts\ContactsMenu\IProvider; use OCP\IURLGenerator; class EMailProvider implements IProvider { - private IActionFactory $actionFactory; - private IURLGenerator $urlGenerator; - - public function __construct(IActionFactory $actionFactory, IURLGenerator $urlGenerator) { - $this->actionFactory = $actionFactory; - $this->urlGenerator = $urlGenerator; + public function __construct( + private IActionFactory $actionFactory, + private IURLGenerator $urlGenerator, + ) { } - /** - * @param IEntry $entry - */ - public function process(IEntry $entry) { + public function process(IEntry $entry): void { $iconUrl = $this->urlGenerator->getAbsoluteURL($this->urlGenerator->imagePath('core', 'actions/mail.svg')); foreach ($entry->getEMailAddresses() as $address) { if (empty($address)) { diff --git a/lib/private/Contacts/ContactsMenu/Providers/LocalTimeProvider.php b/lib/private/Contacts/ContactsMenu/Providers/LocalTimeProvider.php index 17e30e89c37..32e1280ff0f 100644 --- a/lib/private/Contacts/ContactsMenu/Providers/LocalTimeProvider.php +++ b/lib/private/Contacts/ContactsMenu/Providers/LocalTimeProvider.php @@ -37,36 +37,18 @@ use OCP\IUserManager; use OCP\L10N\IFactory as IL10NFactory; class LocalTimeProvider implements IProvider { - private IActionFactory $actionFactory; - private IL10NFactory $l10nFactory; - private IURLGenerator $urlGenerator; - private IUserManager $userManager; - private ITimeFactory $timeFactory; - private IDateTimeFormatter $dateTimeFormatter; - private IConfig $config; - public function __construct( - IActionFactory $actionFactory, - IL10NFactory $l10nFactory, - IURLGenerator $urlGenerator, - IUserManager $userManager, - ITimeFactory $timeFactory, - IDateTimeFormatter $dateTimeFormatter, - IConfig $config + private IActionFactory $actionFactory, + private IL10NFactory $l10nFactory, + private IURLGenerator $urlGenerator, + private IUserManager $userManager, + private ITimeFactory $timeFactory, + private IDateTimeFormatter $dateTimeFormatter, + private IConfig $config, ) { - $this->actionFactory = $actionFactory; - $this->l10nFactory = $l10nFactory; - $this->urlGenerator = $urlGenerator; - $this->userManager = $userManager; - $this->timeFactory = $timeFactory; - $this->dateTimeFormatter = $dateTimeFormatter; - $this->config = $config; } - /** - * @param IEntry $entry - */ - public function process(IEntry $entry) { + public function process(IEntry $entry): void { $targetUserId = $entry->getProperty('UID'); $targetUser = $this->userManager->get($targetUserId); if (!empty($targetUser)) { diff --git a/lib/private/Contacts/ContactsMenu/Providers/ProfileProvider.php b/lib/private/Contacts/ContactsMenu/Providers/ProfileProvider.php index af941fd7fd1..6b36b9fff0e 100644 --- a/lib/private/Contacts/ContactsMenu/Providers/ProfileProvider.php +++ b/lib/private/Contacts/ContactsMenu/Providers/ProfileProvider.php @@ -33,30 +33,16 @@ use OCP\IUserManager; use OCP\L10N\IFactory as IL10NFactory; class ProfileProvider implements IProvider { - private IActionFactory $actionFactory; - private ProfileManager $profileManager; - private IL10NFactory $l10nFactory; - private IURLGenerator $urlGenerator; - private IUserManager $userManager; - public function __construct( - IActionFactory $actionFactory, - ProfileManager $profileManager, - IL10NFactory $l10nFactory, - IURLGenerator $urlGenerator, - IUserManager $userManager + private IActionFactory $actionFactory, + private ProfileManager $profileManager, + private IL10NFactory $l10nFactory, + private IURLGenerator $urlGenerator, + private IUserManager $userManager, ) { - $this->actionFactory = $actionFactory; - $this->profileManager = $profileManager; - $this->l10nFactory = $l10nFactory; - $this->urlGenerator = $urlGenerator; - $this->userManager = $userManager; } - /** - * @param IEntry $entry - */ - public function process(IEntry $entry) { + public function process(IEntry $entry): void { $targetUserId = $entry->getProperty('UID'); $targetUser = $this->userManager->get($targetUserId); if (!empty($targetUser)) { -- 2.39.5