Skip to content

Commit f9673f4

Browse files
committed
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 8221da9 commit f9673f4

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
@@ -47,7 +47,7 @@ public function __construct(
4747
* @param string $type One of the activity types, 'batchtime' or 'self'
4848
* @return bool|int
4949
*/
50-
public function getUserSetting($user, $method, $type) {
50+
public function getUserSetting(string $user, string $method, string $type): bool|int {
5151
if ($method === 'email' && $this->config->getAppValue('activity', 'enable_email', 'yes') === 'no') {
5252
return false;
5353
}
@@ -82,7 +82,7 @@ public function getUserSetting($user, $method, $type) {
8282
* @param string $type
8383
* @return bool|int
8484
*/
85-
public function getAdminSetting($method, $type) {
85+
public function getAdminSetting(string $method, string $type): bool|int {
8686
$defaultSetting = $this->getDefaultSetting($method, $type);
8787
if (is_bool($defaultSetting)) {
8888
return (bool)$this->config->getAppValue(
@@ -106,7 +106,7 @@ public function getAdminSetting($method, $type) {
106106
* @param string $type One of the activity types, 'batchtime', 'self' or 'selfemail'
107107
* @return bool|int
108108
*/
109-
protected function getDefaultSetting($method, $type) {
109+
protected function getDefaultSetting(string $method, string $type): bool|int {
110110
if ($method === 'setting') {
111111
if ($type === 'batchtime') {
112112
return 3600;
@@ -145,7 +145,7 @@ protected function getDefaultSetting($method, $type) {
145145
* @param string $type One of the activity types, 'batchtime', 'self' or 'selfemail'
146146
* @return bool
147147
*/
148-
protected function canModifySetting($method, $type) {
148+
protected function canModifySetting(string $method, string $type): bool {
149149
if ($method === 'setting') {
150150
return true;
151151
}
@@ -168,7 +168,7 @@ protected function canModifySetting($method, $type) {
168168
/**
169169
* Get a list with all notification types
170170
*/
171-
public function getNotificationTypes() {
171+
public function getNotificationTypes(): array {
172172
$settings = $this->manager->getSettings();
173173

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

tests/ConsumerTest.php

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -77,17 +77,25 @@ protected function setUp(): void {
7777
->method('get')
7878
->with('activity')
7979
->willReturn($l10n);
80+
$map = [
81+
['affectedUser', 'notification', 'type', true],
82+
['affectedUser2', 'notification', 'type', true],
83+
['affectedUser', 'email', 'type', true],
84+
['affectedUser2', 'email', 'type', true],
85+
['affectedUser', 'setting', 'batchtime', 10],
86+
['affectedUser2', 'setting', 'batchtime', 10],
87+
];
8088
$this->userSettings
8189
->method('getUserSetting')
8290
->with($this->stringContains('affectedUser'), $this->anything(), $this->anything())
83-
->willReturnMap([
84-
['affectedUser', 'notification', 'type', true],
85-
['affectedUser2', 'notification', 'type', true],
86-
['affectedUser', 'email', 'type', true],
87-
['affectedUser2', 'email', 'type', true],
88-
['affectedUser', 'setting', 'batchtime', 10],
89-
['affectedUser2', 'setting', 'batchtime', 10],
90-
]);
91+
->willReturnCallback(function ($user, $method, $type) use ($map): bool|int {
92+
foreach ($map as [$u, $m, $t, $v]) {
93+
if ($u === $user && $m === $method && $t === $type) {
94+
return $v;
95+
}
96+
}
97+
return false;
98+
});
9199

92100
$this->consumer = new Consumer(
93101
$this->data,

tests/FilesHooksTest.php

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

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

726732
$filesHooks->expects($this->once())
727733
->method('shareNotificationForSharer')

0 commit comments

Comments
 (0)