Skip to content

Commit

Permalink
Merge pull request #38986 from fsamapoor/refactor_lib_private_contacts
Browse files Browse the repository at this point in the history
  • Loading branch information
skjnldsv authored Jun 25, 2023
2 parents 6abb3dd + 9f2487d commit 31663ac
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 121 deletions.
15 changes: 5 additions & 10 deletions lib/private/Contacts/ContactsMenu/ActionProviderStore.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,14 @@
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
*/
Expand Down Expand Up @@ -90,7 +86,6 @@ private function getServerProviderClasses(): array {
}

/**
* @param IUser $user
* @return string[]
*/
private function getAppProviderClasses(IUser $user): array {
Expand Down
10 changes: 5 additions & 5 deletions lib/private/Contacts/ContactsMenu/Actions/LinkAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,27 +34,27 @@ 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;
}

public function getName(): string {
return $this->name;
}

public function setPriority(int $priority) {
public function setPriority(int $priority): void {
$this->priority = $priority;
}

public function getPriority(): int {
return $this->priority;
}

public function setHref(string $href) {
public function setHref(string $href): void {
$this->href = $href;
}

Expand All @@ -65,7 +65,7 @@ public function getHref(): string {
/**
* @since 23.0.0
*/
public function setAppId(string $appId) {
public function setAppId(string $appId): void {
$this->appId = $appId;
}

Expand Down
35 changes: 8 additions & 27 deletions lib/private/Contacts/ContactsMenu/ContactsStore.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,33 +44,16 @@
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;
}

/**
Expand Down Expand Up @@ -126,9 +109,7 @@ public function getContacts(IUser $user, ?string $filter, ?int $limit = null, ?i
* 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(
Expand Down
9 changes: 1 addition & 8 deletions lib/private/Contacts/ContactsMenu/Entry.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,20 +134,13 @@ public function setProperties(array $contact): void {
$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) {
Expand Down
22 changes: 7 additions & 15 deletions lib/private/Contacts/ContactsMenu/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,22 +33,15 @@
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 {
Expand Down Expand Up @@ -95,10 +88,9 @@ private function sortEntries(array $entries): array {

/**
* @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) {
Expand Down
15 changes: 5 additions & 10 deletions lib/private/Contacts/ContactsMenu/Providers/EMailProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,13 @@
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)) {
Expand Down
34 changes: 8 additions & 26 deletions lib/private/Contacts/ContactsMenu/Providers/LocalTimeProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,36 +37,18 @@
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)) {
Expand Down
26 changes: 6 additions & 20 deletions lib/private/Contacts/ContactsMenu/Providers/ProfileProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,30 +33,16 @@
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)) {
Expand Down

0 comments on commit 31663ac

Please sign in to comment.