Skip to content

Commit 8d50027

Browse files
authored
Merge pull request #57142 from nextcloud/carl/dashboard-psalm
2 parents 7165131 + e6ac79d commit 8d50027

5 files changed

Lines changed: 23 additions & 39 deletions

File tree

apps/dashboard/lib/Controller/DashboardApiController.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use OCP\AppFramework\Http\DataResponse;
1919
use OCP\AppFramework\OCSController;
2020
use OCP\AppFramework\Services\IAppConfig;
21+
use OCP\Config\IUserConfig;
2122
use OCP\Dashboard\IAPIWidget;
2223
use OCP\Dashboard\IAPIWidgetV2;
2324
use OCP\Dashboard\IButtonWidget;
@@ -30,7 +31,6 @@
3031
use OCP\Dashboard\Model\WidgetItem;
3132

3233
use OCP\Dashboard\Model\WidgetOptions;
33-
use OCP\IConfig;
3434
use OCP\IRequest;
3535

3636
/**
@@ -45,7 +45,7 @@ public function __construct(
4545
IRequest $request,
4646
private IManager $dashboardManager,
4747
private IAppConfig $appConfig,
48-
private IConfig $config,
48+
private IUserConfig $userConfig,
4949
private ?string $userId,
5050
private DashboardService $service,
5151
) {
@@ -59,7 +59,7 @@ public function __construct(
5959
private function getShownWidgets(array $widgetIds): array {
6060
if (empty($widgetIds)) {
6161
$systemDefault = $this->appConfig->getAppValueString('layout', 'recommendations,spreed,mail,calendar');
62-
$widgetIds = explode(',', $this->config->getUserValue($this->userId, 'dashboard', 'layout', $systemDefault));
62+
$widgetIds = explode(',', $this->userConfig->getValueString($this->userId, 'dashboard', 'layout', $systemDefault));
6363
}
6464

6565
return array_filter(
@@ -202,7 +202,7 @@ public function getLayout(): DataResponse {
202202
#[NoAdminRequired]
203203
#[ApiRoute(verb: 'POST', url: '/api/v3/layout')]
204204
public function updateLayout(array $layout): DataResponse {
205-
$this->config->setUserValue($this->userId, 'dashboard', 'layout', implode(',', $layout));
205+
$this->userConfig->setValueString($this->userId, 'dashboard', 'layout', implode(',', $layout));
206206
return new DataResponse(['layout' => $layout]);
207207
}
208208

@@ -230,7 +230,7 @@ public function getStatuses(): DataResponse {
230230
#[NoAdminRequired]
231231
#[ApiRoute(verb: 'POST', url: '/api/v3/statuses')]
232232
public function updateStatuses(array $statuses): DataResponse {
233-
$this->config->setUserValue($this->userId, 'dashboard', 'statuses', implode(',', $statuses));
233+
$this->userConfig->setValueString($this->userId, 'dashboard', 'statuses', implode(',', $statuses));
234234
return new DataResponse(['statuses' => $statuses]);
235235
}
236236
}

apps/dashboard/lib/Controller/DashboardController.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@
1717
use OCP\AppFramework\Http\FeaturePolicy;
1818
use OCP\AppFramework\Http\TemplateResponse;
1919
use OCP\AppFramework\Services\IInitialState;
20+
use OCP\Config\IUserConfig;
2021
use OCP\Dashboard\IIconWidget;
2122
use OCP\Dashboard\IManager;
2223
use OCP\Dashboard\IWidget;
23-
use OCP\EventDispatcher\IEventDispatcher;
2424
use OCP\IConfig;
2525
use OCP\IL10N;
2626
use OCP\IRequest;
@@ -33,9 +33,9 @@ public function __construct(
3333
string $appName,
3434
IRequest $request,
3535
private IInitialState $initialState,
36-
private IEventDispatcher $eventDispatcher,
3736
private IManager $dashboardManager,
3837
private IConfig $config,
38+
private IUserConfig $userConfig,
3939
private IL10N $l10n,
4040
private ?string $userId,
4141
private DashboardService $service,
@@ -67,9 +67,9 @@ public function index(): TemplateResponse {
6767
$this->initialState->provideInitialState('statuses', $this->service->getStatuses());
6868
$this->initialState->provideInitialState('layout', $this->service->getLayout());
6969
$this->initialState->provideInitialState('appStoreEnabled', $this->config->getSystemValueBool('appstoreenabled', true));
70-
$this->initialState->provideInitialState('firstRun', $this->config->getUserValue($this->userId, 'dashboard', 'firstRun', '1') === '1');
70+
$this->initialState->provideInitialState('firstRun', $this->userConfig->getValueBool($this->userId, 'dashboard', 'firstRun', true));
7171
$this->initialState->provideInitialState('birthdate', $this->service->getBirthdate());
72-
$this->config->setUserValue($this->userId, 'dashboard', 'firstRun', '0');
72+
$this->userConfig->setValueBool($this->userId, 'dashboard', 'firstRun', false);
7373

7474
$response = new TemplateResponse('dashboard', 'index', [
7575
'id-app-content' => '#app-dashboard',

apps/dashboard/lib/Service/DashboardService.php

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@
1212
use OCP\Accounts\IAccountManager;
1313
use OCP\Accounts\PropertyDoesNotExistException;
1414
use OCP\AppFramework\Services\IAppConfig;
15-
use OCP\IConfig;
15+
use OCP\Config\IUserConfig;
1616
use OCP\IUserManager;
1717

1818
class DashboardService {
1919
public function __construct(
20-
private IConfig $config,
20+
private IUserConfig $userConfig,
2121
private IAppConfig $appConfig,
2222
private ?string $userId,
2323
private IUserManager $userManager,
@@ -31,21 +31,24 @@ public function __construct(
3131
*/
3232
public function getLayout(): array {
3333
$systemDefault = $this->appConfig->getAppValueString('layout', 'recommendations,spreed,mail,calendar');
34-
return array_values(array_filter(explode(',', $this->config->getUserValue($this->userId, 'dashboard', 'layout', $systemDefault)), fn (string $value) => $value !== ''));
34+
return array_values(array_filter(
35+
explode(',', $this->userConfig->getValueString($this->userId, 'dashboard', 'layout', $systemDefault)),
36+
fn (string $value) => $value !== '')
37+
);
3538
}
3639

3740
/**
3841
* @return list<string>
3942
*/
40-
public function getStatuses() {
41-
$configStatuses = $this->config->getUserValue($this->userId, 'dashboard', 'statuses', '');
43+
public function getStatuses(): array {
44+
$configStatuses = $this->userConfig->getValueString($this->userId, 'dashboard', 'statuses');
4245
try {
4346
// Parse the old format
4447
/** @var array<string, bool> $statuses */
4548
$statuses = json_decode($configStatuses, true, 512, JSON_THROW_ON_ERROR);
4649
// We avoid getting an empty array as it will not produce an object in UI's JS
4750
return array_keys(array_filter($statuses, static fn (bool $value) => $value));
48-
} catch (JsonException $e) {
51+
} catch (JsonException) {
4952
return array_values(array_filter(explode(',', $configStatuses), fn (string $value) => $value !== ''));
5053
}
5154
}

apps/dashboard/tests/DashboardServiceTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@
1313
use OCA\Dashboard\Service\DashboardService;
1414
use OCP\Accounts\IAccountManager;
1515
use OCP\AppFramework\Services\IAppConfig;
16-
use OCP\IConfig;
16+
use OCP\Config\IUserConfig;
1717
use OCP\IUser;
1818
use OCP\IUserManager;
1919
use PHPUnit\Framework\MockObject\MockObject;
2020
use Test\TestCase;
2121

2222
class DashboardServiceTest extends TestCase {
2323

24-
private IConfig&MockObject $config;
24+
private IUserConfig&MockObject $userConfig;
2525
private IAppConfig&MockObject $appConfig;
2626
private IUserManager&MockObject $userManager;
2727
private IAccountManager&MockObject $accountManager;
@@ -30,13 +30,13 @@ class DashboardServiceTest extends TestCase {
3030
protected function setUp(): void {
3131
parent::setUp();
3232

33-
$this->config = $this->createMock(IConfig::class);
33+
$this->userConfig = $this->createMock(IUserConfig::class);
3434
$this->appConfig = $this->createMock(IAppConfig::class);
3535
$this->userManager = $this->createMock(IUserManager::class);
3636
$this->accountManager = $this->createMock(IAccountManager::class);
3737

3838
$this->service = new DashboardService(
39-
$this->config,
39+
$this->userConfig,
4040
$this->appConfig,
4141
'alice',
4242
$this->userManager,
@@ -90,7 +90,7 @@ public function testGetBirthdateUserNotFound(): void {
9090

9191
public function testGetBirthdateNoUserId(): void {
9292
$service = new DashboardService(
93-
$this->config,
93+
$this->userConfig,
9494
$this->appConfig,
9595
null,
9696
$this->userManager,

build/psalm-baseline.xml

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -63,25 +63,6 @@
6363
<code><![CDATA[CommentsEvent::EVENT_PRE_UPDATE]]></code>
6464
</DeprecatedConstant>
6565
</file>
66-
<file src="apps/dashboard/lib/Controller/DashboardApiController.php">
67-
<DeprecatedMethod>
68-
<code><![CDATA[getUserValue]]></code>
69-
<code><![CDATA[setUserValue]]></code>
70-
<code><![CDATA[setUserValue]]></code>
71-
</DeprecatedMethod>
72-
</file>
73-
<file src="apps/dashboard/lib/Controller/DashboardController.php">
74-
<DeprecatedMethod>
75-
<code><![CDATA[getUserValue]]></code>
76-
<code><![CDATA[setUserValue]]></code>
77-
</DeprecatedMethod>
78-
</file>
79-
<file src="apps/dashboard/lib/Service/DashboardService.php">
80-
<DeprecatedMethod>
81-
<code><![CDATA[getUserValue]]></code>
82-
<code><![CDATA[getUserValue]]></code>
83-
</DeprecatedMethod>
84-
</file>
8566
<file src="apps/dav/appinfo/v1/publicwebdav.php">
8667
<InternalMethod>
8768
<code><![CDATA[Filesystem::logWarningWhenAddingStorageWrapper($previousLog)]]></code>

0 commit comments

Comments
 (0)