Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions lib/UserSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function __construct(
* @param string $type One of the activity types, 'batchtime' or 'self'
* @return bool|int
*/
public function getUserSetting($user, $method, $type) {
public function getUserSetting(string $user, string $method, string $type): bool|int {
if ($method === 'email' && $this->config->getAppValue('activity', 'enable_email', 'yes') === 'no') {
return false;
}
Expand Down Expand Up @@ -82,7 +82,7 @@ public function getUserSetting($user, $method, $type) {
* @param string $type
* @return bool|int
*/
public function getAdminSetting($method, $type) {
public function getAdminSetting(string $method, string $type): bool|int {
$defaultSetting = $this->getDefaultSetting($method, $type);
if (is_bool($defaultSetting)) {
return (bool)$this->config->getAppValue(
Expand All @@ -106,7 +106,7 @@ public function getAdminSetting($method, $type) {
* @param string $type One of the activity types, 'batchtime', 'self' or 'selfemail'
* @return bool|int
*/
protected function getDefaultSetting($method, $type) {
protected function getDefaultSetting(string $method, string $type): bool|int {
if ($method === 'setting') {
if ($type === 'batchtime') {
return 3600;
Expand Down Expand Up @@ -145,7 +145,7 @@ protected function getDefaultSetting($method, $type) {
* @param string $type One of the activity types, 'batchtime', 'self' or 'selfemail'
* @return bool
*/
protected function canModifySetting($method, $type) {
protected function canModifySetting(string $method, string $type): bool {
if ($method === 'setting') {
return true;
}
Expand All @@ -168,7 +168,7 @@ protected function canModifySetting($method, $type) {
/**
* Get a list with all notification types
*/
public function getNotificationTypes() {
public function getNotificationTypes(): array {
$settings = $this->manager->getSettings();

$return = array_map(function (ActivitySettings $setting) {
Expand All @@ -194,7 +194,7 @@ public function getNotificationTypes() {
* @return array Returns a "username => b:true" Map for method = notification
* Returns a "username => i:batchtime" Map for method = email
*/
public function filterUsersBySetting($users, $method, $type) {
public function filterUsersBySetting(array $users, string $method, string $type): array {
if (empty($users)) {
return [];
}
Expand Down
24 changes: 16 additions & 8 deletions tests/ConsumerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,17 +77,25 @@ protected function setUp(): void {
->method('get')
->with('activity')
->willReturn($l10n);
$map = [
['affectedUser', 'notification', 'type', true],
['affectedUser2', 'notification', 'type', true],
['affectedUser', 'email', 'type', true],
['affectedUser2', 'email', 'type', true],
['affectedUser', 'setting', 'batchtime', 10],
['affectedUser2', 'setting', 'batchtime', 10],
];
$this->userSettings
->method('getUserSetting')
->with($this->stringContains('affectedUser'), $this->anything(), $this->anything())
->willReturnMap([
['affectedUser', 'notification', 'type', true],
['affectedUser2', 'notification', 'type', true],
['affectedUser', 'email', 'type', true],
['affectedUser2', 'email', 'type', true],
['affectedUser', 'setting', 'batchtime', 10],
['affectedUser2', 'setting', 'batchtime', 10],
]);
->willReturnCallback(function ($user, $method, $type) use ($map): bool|int {
foreach ($map as [$u, $m, $t, $v]) {
if ($u === $user && $m === $method && $t === $type) {
return $v;
}
}
return false;
});

$this->consumer = new Consumer(
$this->data,
Expand Down
10 changes: 8 additions & 2 deletions tests/FilesHooksTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -720,8 +720,14 @@ public function testShareWithGroup(array $usersInGroup, int $settingCalls, int $

$this->settings->expects($this->exactly($settingCalls))
->method('filterUsersBySetting')
#->with($settingUsers, $this->anything(), Files_Sharing::TYPE_SHARED)
->willReturnMap($settingsReturn);
->willReturnCallback(function ($users, $method, $type) use ($settingsReturn): array {
foreach ($settingsReturn as [$u, $m, $t, $v]) {
if ($u === $users && $m === $method && $t === $type) {
return $v;
}
}
return [];
});

$filesHooks->expects($this->once())
->method('shareNotificationForSharer')
Expand Down
Loading