Skip to content

Commit 0b468a1

Browse files
committed
Modernize contacts menu
Signed-off-by: Thomas Citharel <[email protected]>
1 parent f548548 commit 0b468a1

File tree

20 files changed

+270
-448
lines changed

20 files changed

+270
-448
lines changed

build/psalm-baseline.xml

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2850,14 +2850,6 @@
28502850
<code>$this-&gt;application</code>
28512851
</UndefinedThisPropertyFetch>
28522852
</file>
2853-
<file src="lib/private/Contacts/ContactsMenu/Manager.php">
2854-
<InvalidNullableReturnType occurrences="1">
2855-
<code>IEntry</code>
2856-
</InvalidNullableReturnType>
2857-
<NullableReturnStatement occurrences="1">
2858-
<code>$entry</code>
2859-
</NullableReturnStatement>
2860-
</file>
28612853
<file src="lib/private/ContactsManager.php">
28622854
<InvalidNullableReturnType occurrences="3">
28632855
<code>IAddressBook</code>

core/Controller/ContactsMenuController.php

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
*/
2525
namespace OC\Core\Controller;
2626

27+
use Exception;
2728
use OC\Contacts\ContactsMenu\Manager;
2829
use OCP\AppFramework\Controller;
2930
use OCP\AppFramework\Http;
@@ -32,18 +33,9 @@
3233
use OCP\IUserSession;
3334

3435
class ContactsMenuController extends Controller {
36+
private Manager $manager;
37+
private IUserSession $userSession;
3538

36-
/** @var Manager */
37-
private $manager;
38-
39-
/** @var IUserSession */
40-
private $userSession;
41-
42-
/**
43-
* @param IRequest $request
44-
* @param IUserSession $userSession
45-
* @param Manager $manager
46-
*/
4739
public function __construct(IRequest $request, IUserSession $userSession, Manager $manager) {
4840
parent::__construct('core', $request);
4941
$this->userSession = $userSession;
@@ -53,21 +45,20 @@ public function __construct(IRequest $request, IUserSession $userSession, Manage
5345
/**
5446
* @NoAdminRequired
5547
*
56-
* @param string|null filter
5748
* @return \JsonSerializable[]
49+
* @throws Exception
5850
*/
59-
public function index($filter = null) {
51+
public function index(?string $filter = null): array {
6052
return $this->manager->getEntries($this->userSession->getUser(), $filter);
6153
}
6254

6355
/**
6456
* @NoAdminRequired
6557
*
66-
* @param integer $shareType
67-
* @param string $shareWith
6858
* @return JSONResponse|\JsonSerializable
59+
* @throws Exception
6960
*/
70-
public function findOne($shareType, $shareWith) {
61+
public function findOne(int $shareType, string $shareWith) {
7162
$contact = $this->manager->findOne($this->userSession->getUser(), $shareType, $shareWith);
7263

7364
if ($contact) {

lib/private/Contacts/ContactsMenu/ActionProviderStore.php

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,22 +31,16 @@
3131
use OC\App\AppManager;
3232
use OC\Contacts\ContactsMenu\Providers\EMailProvider;
3333
use OC\Contacts\ContactsMenu\Providers\ProfileProvider;
34-
use OCP\AppFramework\QueryException;
3534
use OCP\Contacts\ContactsMenu\IProvider;
3635
use OCP\IServerContainer;
3736
use OCP\IUser;
37+
use Psr\Container\ContainerExceptionInterface;
3838
use Psr\Log\LoggerInterface;
3939

4040
class ActionProviderStore {
41-
42-
/** @var IServerContainer */
43-
private $serverContainer;
44-
45-
/** @var AppManager */
46-
private $appManager;
47-
48-
/** @var LoggerInterface */
49-
private $logger;
41+
private IServerContainer $serverContainer;
42+
private AppManager $appManager;
43+
private LoggerInterface $logger;
5044

5145
public function __construct(IServerContainer $serverContainer, AppManager $appManager, LoggerInterface $logger) {
5246
$this->serverContainer = $serverContainer;
@@ -67,8 +61,8 @@ public function getProviders(IUser $user): array {
6761

6862
foreach ($allClasses as $class) {
6963
try {
70-
$providers[] = $this->serverContainer->query($class);
71-
} catch (QueryException $ex) {
64+
$providers[] = $this->serverContainer->get($class);
65+
} catch (ContainerExceptionInterface $ex) {
7266
$this->logger->error(
7367
'Could not load contacts menu action provider ' . $class,
7468
[

lib/private/Contacts/ContactsMenu/Actions/LinkAction.php

Lines changed: 12 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -25,81 +25,51 @@
2525
use OCP\Contacts\ContactsMenu\ILinkAction;
2626

2727
class LinkAction implements ILinkAction {
28-
29-
/** @var string */
30-
private $icon;
31-
32-
/** @var string */
33-
private $name;
34-
35-
/** @var string */
36-
private $href;
37-
38-
/** @var int */
39-
private $priority = 10;
40-
41-
/** @var string */
42-
private $appId;
28+
private string $icon = '';
29+
private string $name = '';
30+
private string $href = '';
31+
private int $priority = 10;
32+
private string $appId = '';
4333

4434
/**
4535
* @param string $icon absolute URI to an icon
4636
*/
47-
public function setIcon($icon) {
37+
public function setIcon(string $icon) {
4838
$this->icon = $icon;
4939
}
5040

51-
/**
52-
* @param string $name
53-
*/
54-
public function setName($name) {
41+
public function setName(string $name) {
5542
$this->name = $name;
5643
}
5744

58-
/**
59-
* @return string
60-
*/
61-
public function getName() {
45+
public function getName(): string {
6246
return $this->name;
6347
}
6448

65-
/**
66-
* @param int $priority
67-
*/
68-
public function setPriority($priority) {
49+
public function setPriority(int $priority) {
6950
$this->priority = $priority;
7051
}
7152

72-
/**
73-
* @return int
74-
*/
75-
public function getPriority() {
53+
public function getPriority(): int {
7654
return $this->priority;
7755
}
7856

79-
/**
80-
* @param string $href
81-
*/
82-
public function setHref($href) {
57+
public function setHref(string $href) {
8358
$this->href = $href;
8459
}
8560

86-
/**
87-
* @return string
88-
*/
89-
public function getHref() {
61+
public function getHref(): string {
9062
return $this->href;
9163
}
9264

9365
/**
94-
* @param string $appId
9566
* @since 23.0.0
9667
*/
9768
public function setAppId(string $appId) {
9869
$this->appId = $appId;
9970
}
10071

10172
/**
102-
* @return string
10373
* @since 23.0.0
10474
*/
10575
public function getAppId(): string {

lib/private/Contacts/ContactsMenu/ContactsStore.php

Lines changed: 14 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -44,30 +44,14 @@
4444
use OCP\L10N\IFactory as IL10NFactory;
4545

4646
class ContactsStore implements IContactsStore {
47-
48-
/** @var IManager */
49-
private $contactsManager;
50-
51-
/** @var IConfig */
52-
private $config;
53-
54-
/** @var ProfileManager */
55-
private $profileManager;
56-
57-
/** @var IUserManager */
58-
private $userManager;
59-
60-
/** @var IURLGenerator */
61-
private $urlGenerator;
62-
63-
/** @var IGroupManager */
64-
private $groupManager;
65-
66-
/** @var KnownUserService */
67-
private $knownUserService;
68-
69-
/** @var IL10NFactory */
70-
private $l10nFactory;
47+
private IManager $contactsManager;
48+
private IConfig $config;
49+
private ProfileManager $profileManager;
50+
private IUserManager $userManager;
51+
private IURLGenerator $urlGenerator;
52+
private IGroupManager $groupManager;
53+
private KnownUserService $knownUserService;
54+
private IL10NFactory $l10nFactory;
7155

7256
public function __construct(
7357
IManager $contactsManager,
@@ -90,11 +74,9 @@ public function __construct(
9074
}
9175

9276
/**
93-
* @param IUser $user
94-
* @param string|null $filter
9577
* @return IEntry[]
9678
*/
97-
public function getContacts(IUser $user, $filter, ?int $limit = null, ?int $offset = null) {
79+
public function getContacts(IUser $user, ?string $filter, ?int $limit = null, ?int $offset = null): array {
9880
$options = [
9981
'enumeration' => $this->config->getAppValue('core', 'shareapi_allow_share_dialog_user_enumeration', 'yes') === 'yes',
10082
'fullmatch' => $this->config->getAppValue('core', 'shareapi_restrict_user_enumeration_full_match', 'yes') === 'yes',
@@ -152,8 +134,8 @@ public function getContacts(IUser $user, $filter, ?int $limit = null, ?int $offs
152134
private function filterContacts(
153135
IUser $self,
154136
array $entries,
155-
$filter
156-
) {
137+
?string $filter
138+
): array {
157139
$disallowEnumeration = $this->config->getAppValue('core', 'shareapi_allow_share_dialog_user_enumeration', 'yes') !== 'yes';
158140
$restrictEnumerationGroup = $this->config->getAppValue('core', 'shareapi_restrict_user_enumeration_to_group', 'no') === 'yes';
159141
$restrictEnumerationPhone = $this->config->getAppValue('core', 'shareapi_restrict_user_enumeration_to_phone', 'no') === 'yes';
@@ -168,7 +150,7 @@ private function filterContacts(
168150
$selfGroups = $this->groupManager->getUserGroupIds($self);
169151

170152
if ($excludedGroups) {
171-
$excludedGroups = $this->config->getAppValue('core', 'shareapi_exclude_groups_list', '');
153+
$excludedGroups = $this->config->getAppValue('core', 'shareapi_exclude_groups_list');
172154
$decodedExcludeGroups = json_decode($excludedGroups, true);
173155
$excludeGroupsList = $decodedExcludeGroups ?? [];
174156

@@ -253,13 +235,7 @@ private function filterContacts(
253235
}));
254236
}
255237

256-
/**
257-
* @param IUser $user
258-
* @param integer $shareType
259-
* @param string $shareWith
260-
* @return IEntry|null
261-
*/
262-
public function findOne(IUser $user, $shareType, $shareWith) {
238+
public function findOne(IUser $user, int $shareType, string $shareWith): ?IEntry {
263239
switch ($shareType) {
264240
case 0:
265241
case 6:
@@ -309,7 +285,7 @@ public function findOne(IUser $user, $shareType, $shareWith) {
309285
* @param array $contact
310286
* @return Entry
311287
*/
312-
private function contactArrayToEntry(array $contact) {
288+
private function contactArrayToEntry(array $contact): Entry {
313289
$entry = new Entry();
314290

315291
if (isset($contact['id'])) {

0 commit comments

Comments
 (0)