Skip to content

Commit d4cb9d6

Browse files
miaulalalabackportbot[bot]
authored andcommitted
refactor(types): add native parameter and return types to UserSettings
All six public/protected methods now carry PHP 8.x native types instead of relying on docblocks alone. Two test mocks that used willReturnMap were migrated to willReturnCallback so they return a typed default (false / []) instead of null when no entry matches. Signed-off-by: Anna Larch <anna@nextcloud.com> AI-Assisted-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 793435a commit d4cb9d6

3 files changed

Lines changed: 30 additions & 16 deletions

File tree

lib/UserSettings.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public function __construct(
5151
* @param string $type One of the activity types, 'batchtime' or 'self'
5252
* @return bool|int
5353
*/
54-
public function getUserSetting($user, $method, $type) {
54+
public function getUserSetting(string $user, string $method, string $type): bool|int {
5555
if ($method === 'email' && $this->config->getAppValue('activity', 'enable_email', 'yes') === 'no') {
5656
return false;
5757
}
@@ -86,7 +86,7 @@ public function getUserSetting($user, $method, $type) {
8686
* @param string $type
8787
* @return bool|int
8888
*/
89-
public function getAdminSetting($method, $type) {
89+
public function getAdminSetting(string $method, string $type): bool|int {
9090
$defaultSetting = $this->getDefaultSetting($method, $type);
9191
if (is_bool($defaultSetting)) {
9292
return (bool)$this->config->getAppValue(
@@ -110,7 +110,7 @@ public function getAdminSetting($method, $type) {
110110
* @param string $type One of the activity types, 'batchtime', 'self' or 'selfemail'
111111
* @return bool|int
112112
*/
113-
protected function getDefaultSetting($method, $type) {
113+
protected function getDefaultSetting(string $method, string $type): bool|int {
114114
if ($method === 'setting') {
115115
if ($type === 'batchtime') {
116116
return self::BATCH_TIME_HOURLY;
@@ -149,7 +149,7 @@ protected function getDefaultSetting($method, $type) {
149149
* @param string $type One of the activity types, 'batchtime', 'self' or 'selfemail'
150150
* @return bool
151151
*/
152-
protected function canModifySetting($method, $type) {
152+
protected function canModifySetting(string $method, string $type): bool {
153153
if ($method === 'setting') {
154154
return true;
155155
}
@@ -172,7 +172,7 @@ protected function canModifySetting($method, $type) {
172172
/**
173173
* Get a list with all notification types
174174
*/
175-
public function getNotificationTypes() {
175+
public function getNotificationTypes(): array {
176176
$settings = $this->manager->getSettings();
177177

178178
$return = array_map(function (ActivitySettings $setting) {
@@ -198,7 +198,7 @@ public function getNotificationTypes() {
198198
* @return array Returns a "username => b:true" Map for method = notification
199199
* Returns a "username => i:batchtime" Map for method = email
200200
*/
201-
public function filterUsersBySetting($users, $method, $type) {
201+
public function filterUsersBySetting(array $users, string $method, string $type): array {
202202
if (empty($users)) {
203203
return [];
204204
}

tests/ConsumerTest.php

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -82,17 +82,25 @@ protected function setUp(): void {
8282
->method('get')
8383
->with('activity')
8484
->willReturn($l10n);
85+
$map = [
86+
['affectedUser', 'notification', 'type', true],
87+
['affectedUser2', 'notification', 'type', true],
88+
['affectedUser', 'email', 'type', true],
89+
['affectedUser2', 'email', 'type', true],
90+
['affectedUser', 'setting', 'batchtime', 10],
91+
['affectedUser2', 'setting', 'batchtime', 10],
92+
];
8593
$this->userSettings
8694
->method('getUserSetting')
8795
->with($this->stringContains('affectedUser'), $this->anything(), $this->anything())
88-
->willReturnMap([
89-
['affectedUser', 'notification', 'type', true],
90-
['affectedUser2', 'notification', 'type', true],
91-
['affectedUser', 'email', 'type', true],
92-
['affectedUser2', 'email', 'type', true],
93-
['affectedUser', 'setting', 'batchtime', 10],
94-
['affectedUser2', 'setting', 'batchtime', 10],
95-
]);
96+
->willReturnCallback(function ($user, $method, $type) use ($map): bool|int {
97+
foreach ($map as [$u, $m, $t, $v]) {
98+
if ($u === $user && $m === $method && $t === $type) {
99+
return $v;
100+
}
101+
}
102+
return false;
103+
});
96104

97105
$this->consumer = new Consumer(
98106
$this->data,

tests/FilesHooksTest.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -722,8 +722,14 @@ public function testShareWithGroup(array $usersInGroup, int $settingCalls, int $
722722

723723
$this->settings->expects($this->exactly($settingCalls))
724724
->method('filterUsersBySetting')
725-
#->with($settingUsers, $this->anything(), Files_Sharing::TYPE_SHARED)
726-
->willReturnMap($settingsReturn);
725+
->willReturnCallback(function ($users, $method, $type) use ($settingsReturn): array {
726+
foreach ($settingsReturn as [$u, $m, $t, $v]) {
727+
if ($u === $users && $m === $method && $t === $type) {
728+
return $v;
729+
}
730+
}
731+
return [];
732+
});
727733

728734
$filesHooks->expects($this->once())
729735
->method('shareNotificationForSharer')

0 commit comments

Comments
 (0)