]> source.dussan.org Git - nextcloud-server.git/commitdiff
Refactors lib/private/Contacts. 38986/head
authorFaraz Samapoor <f.samapoor@gmail.com>
Sun, 25 Jun 2023 08:26:58 +0000 (11:56 +0330)
committerFaraz Samapoor <fsa@adlas.at>
Sun, 25 Jun 2023 08:26:58 +0000 (11:56 +0330)
Mainly using PHP8's constructor property promotion.

Signed-off-by: Faraz Samapoor <fsa@adlas.at>
lib/private/Contacts/ContactsMenu/ActionProviderStore.php
lib/private/Contacts/ContactsMenu/Actions/LinkAction.php
lib/private/Contacts/ContactsMenu/ContactsStore.php
lib/private/Contacts/ContactsMenu/Entry.php
lib/private/Contacts/ContactsMenu/Manager.php
lib/private/Contacts/ContactsMenu/Providers/EMailProvider.php
lib/private/Contacts/ContactsMenu/Providers/LocalTimeProvider.php
lib/private/Contacts/ContactsMenu/Providers/ProfileProvider.php

index 485895de646a03cb516eca8b12bf43c804a2f87b..7ba5db4bb3377188123a49fed206b3fee26e8bb4 100644 (file)
@@ -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 {
index a3054c9ee52060a16eed3b6f5bc3119e9d6db808..9fc021435a4868b44377b49ca76721c232910cbe 100644 (file)
@@ -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;
        }
 
index e4dd80645ea4995fd936364f52f2d968239e9d8f..c692b486ae4043fbe9c0d5daa53e1331450f5b48 100644 (file)
@@ -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(
index 51fde7604074939edb08b8711206fb40b645e5fc..649c83ae7d8216b94549cfe5cbab8e4240e96b45 100644 (file)
@@ -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) {
index 5c3367a3d091e7b0cb388b9435ecd19dacd188da..490cf6022839919b93a2d17a2efae53cb5ad02d0 100644 (file)
@@ -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) {
index b79052e1f5dda64535e095a5b3b66a617f000854..145c30a2ce7e016040687eae0feb5bd6a3b17688 100644 (file)
@@ -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)) {
index 17e30e89c3771a763f632ade6595b120aa90d8c4..32e1280ff0f224bf0f2f41b6c85f9d6d4e74b953 100644 (file)
@@ -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)) {
index af941fd7fd1feb6876b5d751098952860e22b54e..6b36b9fff0eafc58d0441394ec45f858edced345 100644 (file)
@@ -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)) {