Skip to content

Commit 9444333

Browse files
committed
chore(settings): Cleanup IManager and Manager type annotations
Signed-off-by: jld3103 <jld3103yt@gmail.com>
1 parent ba1af2b commit 9444333

File tree

2 files changed

+37
-32
lines changed

2 files changed

+37
-32
lines changed

lib/private/Settings/Manager.php

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
* @author Roeland Jago Douma <roeland@famdouma.nl>
1313
* @author sualko <klaus@jsxc.org>
1414
* @author Carl Schwan <carl@carlschwan.eu>
15+
* @author Kate Döen <kate.doeen@nextcloud.com>
1516
*
1617
* @license GNU AGPL version 3 or any later version
1718
*
@@ -90,17 +91,14 @@ public function __construct(
9091
$this->subAdmin = $subAdmin;
9192
}
9293

93-
/** @var array */
94+
/** @var array<'admin'|'personal', list<class-string<IIconSection>>> */
9495
protected $sectionClasses = [];
9596

96-
/** @var array */
97+
/** @var array<'admin'|'personal', array<string, IIconSection>> */
9798
protected $sections = [];
9899

99100
/**
100-
* @param string $type 'admin' or 'personal'
101-
* @param string $section Class must implement OCP\Settings\IIconSection
102-
*
103-
* @return void
101+
* @inheritdoc
104102
*/
105103
public function registerSection(string $type, string $section) {
106104
if (!isset($this->sectionClasses[$type])) {
@@ -111,7 +109,7 @@ public function registerSection(string $type, string $section) {
111109
}
112110

113111
/**
114-
* @param string $type 'admin' or 'personal'
112+
* @psalm-param 'admin'|'personal' $type
115113
*
116114
* @return IIconSection[]
117115
*/
@@ -149,6 +147,9 @@ protected function getSections(string $type): array {
149147
return $this->sections[$type];
150148
}
151149

150+
/**
151+
* @inheritdoc
152+
*/
152153
public function getSection(string $type, string $sectionId): ?IIconSection {
153154
if (isset($this->sections[$type]) && isset($this->sections[$type][$sectionId])) {
154155
return $this->sections[$type][$sectionId];
@@ -163,27 +164,23 @@ protected function isKnownDuplicateSectionId(string $sectionID): bool {
163164
], true);
164165
}
165166

166-
/** @var array */
167+
/** @var array<class-string<ISettings>, 'admin'|'personal'> */
167168
protected $settingClasses = [];
168169

169-
/** @var array */
170+
/** @var array<'admin'|'personal', array<string, list<ISettings>>> */
170171
protected $settings = [];
171172

172173
/**
173-
* @psam-param 'admin'|'personal' $type The type of the setting.
174-
* @param string $setting Class must implement OCP\Settings\ISettings
175-
* @param bool $allowedDelegation
176-
*
177-
* @return void
174+
* @inheritdoc
178175
*/
179176
public function registerSetting(string $type, string $setting) {
180177
$this->settingClasses[$setting] = $type;
181178
}
182179

183180
/**
184-
* @param string $type 'admin' or 'personal'
181+
* @psalm-param 'admin'|'personal' $type The type of the setting.
185182
* @param string $section
186-
* @param Closure $filter optional filter to apply on all loaded ISettings
183+
* @param ?Closure $filter optional filter to apply on all loaded ISettings
187184
*
188185
* @return ISettings[]
189186
*/
@@ -252,7 +249,7 @@ public function getAdminSections(): array {
252249

253250
ksort($sections);
254251

255-
return $sections;
252+
return array_values($sections);
256253
}
257254

258255
/**
@@ -277,7 +274,7 @@ public function getAdminSettings($section, bool $subAdminOnly = false): array {
277274
}
278275

279276
ksort($settings);
280-
return $settings;
277+
return array_values($settings);
281278
}
282279

283280
/**
@@ -309,7 +306,7 @@ public function getPersonalSections(): array {
309306

310307
ksort($sections);
311308

312-
return $sections;
309+
return array_values($sections);
313310
}
314311

315312
/**
@@ -341,9 +338,12 @@ public function getPersonalSettings($section): array {
341338
}
342339

343340
ksort($settings);
344-
return $settings;
341+
return array_values($settings);
345342
}
346343

344+
/**
345+
* @inheritdoc
346+
*/
347347
public function getAllowedAdminSettings(string $section, IUser $user): array {
348348
$isAdmin = $this->groupManager->isAdmin($user->getUID());
349349
if ($isAdmin) {
@@ -372,9 +372,12 @@ public function getAllowedAdminSettings(string $section, IUser $user): array {
372372
}
373373

374374
ksort($settings);
375-
return $settings;
375+
return array_values($settings);
376376
}
377377

378+
/**
379+
* @inheritdoc
380+
*/
378381
public function getAllAllowedAdminSettings(IUser $user): array {
379382
$this->getSettings('admin', ''); // Make sure all the settings are loaded
380383
$settings = [];

lib/public/Settings/IManager.php

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
* @author Christoph Wurst <christoph@winzerhof-wurst.at>
77
* @author Joas Schilling <coding@schilljs.com>
88
* @author Lukas Reschke <lukas@statuscode.ch>
9+
* @author Kate Döen <kate.doeen@nextcloud.com>
910
*
1011
* @license GNU AGPL version 3 or any later version
1112
*
@@ -53,31 +54,31 @@ interface IManager {
5354
public const KEY_PERSONAL_SECTION = 'personal-section';
5455

5556
/**
56-
* @param string $type 'admin-section' or 'personal-section'
57-
* @param string $section Class must implement OCP\Settings\ISection
57+
* @psalm-param 'admin'|'personal' $type
58+
* @param class-string<IIconSection> $section
5859
* @since 14.0.0
5960
*/
6061
public function registerSection(string $type, string $section);
6162

6263
/**
63-
* @param string $type 'admin' or 'personal'
64-
* @param string $setting Class must implement OCP\Settings\ISettings
64+
* @psalm-param 'admin'|'personal' $type
65+
* @param class-string<ISettings> $setting
6566
* @since 14.0.0
6667
*/
6768
public function registerSetting(string $type, string $setting);
6869

6970
/**
7071
* returns a list of the admin sections
7172
*
72-
* @return array<int, array<int, IIconSection>> array from IConSection[] where key is the priority
73+
* @return list<array<int, IIconSection>> list of sections with priority as key
7374
* @since 9.1.0
7475
*/
7576
public function getAdminSections(): array;
7677

7778
/**
7879
* returns a list of the personal sections
7980
*
80-
* @return array array of ISection[] where key is the priority
81+
* @return list<array<int, IIconSection>> list of sections with priority as key
8182
* @since 13.0.0
8283
*/
8384
public function getPersonalSections(): array;
@@ -87,10 +88,10 @@ public function getPersonalSections(): array;
8788
*
8889
* @param string $section the section id for which to load the settings
8990
* @param bool $subAdminOnly only return settings sub admins are supposed to see (since 17.0.0)
90-
* @return array<int, array<int, ISettings>> array of ISettings[] where key is the priority
91+
* @return list<array<int, ISettings>> list of settings with priority as key
9192
* @since 9.1.0
9293
*/
93-
public function getAdminSettings($section, bool $subAdminOnly = false): array;
94+
public function getAdminSettings(string $section, bool $subAdminOnly = false): array;
9495

9596
/**
9697
* Returns a list of admin settings that the given user can use for the give section
@@ -103,7 +104,7 @@ public function getAllowedAdminSettings(string $section, IUser $user): array;
103104
/**
104105
* Returns a list of admin settings that the given user can use.
105106
*
106-
* @return array<int, list<ISettings>> The array of admin settings there admin delegation is allowed.
107+
* @return list<ISettings> The array of admin settings there admin delegation is allowed.
107108
* @since 23.0.0
108109
*/
109110
public function getAllAllowedAdminSettings(IUser $user): array;
@@ -112,13 +113,14 @@ public function getAllAllowedAdminSettings(IUser $user): array;
112113
* returns a list of the personal settings
113114
*
114115
* @param string $section the section id for which to load the settings
115-
* @return array array of ISettings[] where key is the priority
116+
* @return list<array<int, ISettings>> list of settings with priority as key
116117
* @since 13.0.0
117118
*/
118-
public function getPersonalSettings($section): array;
119+
public function getPersonalSettings(string $section): array;
119120

120121
/**
121122
* Get a specific section by type and id
123+
* @psalm-param 'admin'|'personal' $type
122124
* @since 25.0.0
123125
*/
124126
public function getSection(string $type, string $sectionId): ?IIconSection;

0 commit comments

Comments
 (0)