Skip to content

Commit 3f0302e

Browse files
committed
refactor(dashboard): Fix all psalm issues
Signed-off-by: Carl Schwan <[email protected]>
1 parent 89fcefb commit 3f0302e

File tree

5 files changed

+23
-36
lines changed

5 files changed

+23
-36
lines changed

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 & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
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;
@@ -33,9 +34,9 @@ public function __construct(
3334
string $appName,
3435
IRequest $request,
3536
private IInitialState $initialState,
36-
private IEventDispatcher $eventDispatcher,
3737
private IManager $dashboardManager,
3838
private IConfig $config,
39+
private IUserConfig $userConfig,
3940
private IL10N $l10n,
4041
private ?string $userId,
4142
private DashboardService $service,
@@ -67,9 +68,9 @@ public function index(): TemplateResponse {
6768
$this->initialState->provideInitialState('statuses', $this->service->getStatuses());
6869
$this->initialState->provideInitialState('layout', $this->service->getLayout());
6970
$this->initialState->provideInitialState('appStoreEnabled', $this->config->getSystemValueBool('appstoreenabled', true));
70-
$this->initialState->provideInitialState('firstRun', $this->config->getUserValue($this->userId, 'dashboard', 'firstRun', '1') === '1');
71+
$this->initialState->provideInitialState('firstRun', $this->userConfig->getValueBool($this->userId, 'dashboard', 'firstRun', true));
7172
$this->initialState->provideInitialState('birthdate', $this->service->getBirthdate());
72-
$this->config->setUserValue($this->userId, 'dashboard', 'firstRun', '0');
73+
$this->userConfig->setValueBool($this->userId, 'dashboard', 'firstRun', false);
7374

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

apps/dashboard/lib/Service/DashboardService.php

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

1819
class DashboardService {
1920
public function __construct(
20-
private IConfig $config,
21+
private IUserConfig $userConfig,
2122
private IAppConfig $appConfig,
2223
private ?string $userId,
2324
private IUserManager $userManager,
@@ -31,21 +32,24 @@ public function __construct(
3132
*/
3233
public function getLayout(): array {
3334
$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 !== ''));
35+
return array_values(array_filter(
36+
explode(',', $this->userConfig->getValueString($this->userId, 'dashboard', 'layout', $systemDefault)),
37+
fn (string $value) => $value !== '')
38+
);
3539
}
3640

3741
/**
3842
* @return list<string>
3943
*/
40-
public function getStatuses() {
41-
$configStatuses = $this->config->getUserValue($this->userId, 'dashboard', 'statuses', '');
44+
public function getStatuses(): array {
45+
$configStatuses = $this->userConfig->getValueString($this->userId, 'dashboard', 'statuses');
4246
try {
4347
// Parse the old format
4448
/** @var array<string, bool> $statuses */
4549
$statuses = json_decode($configStatuses, true, 512, JSON_THROW_ON_ERROR);
4650
// We avoid getting an empty array as it will not produce an object in UI's JS
4751
return array_keys(array_filter($statuses, static fn (bool $value) => $value));
48-
} catch (JsonException $e) {
52+
} catch (JsonException) {
4953
return array_values(array_filter(explode(',', $configStatuses), fn (string $value) => $value !== ''));
5054
}
5155
}

apps/dashboard/tests/DashboardServiceTest.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use OCA\Dashboard\Service\DashboardService;
1414
use OCP\Accounts\IAccountManager;
1515
use OCP\AppFramework\Services\IAppConfig;
16+
use OCP\Config\IUserConfig;
1617
use OCP\IConfig;
1718
use OCP\IUser;
1819
use OCP\IUserManager;
@@ -21,7 +22,7 @@
2122

2223
class DashboardServiceTest extends TestCase {
2324

24-
private IConfig&MockObject $config;
25+
private IUserConfig&MockObject $userConfig;
2526
private IAppConfig&MockObject $appConfig;
2627
private IUserManager&MockObject $userManager;
2728
private IAccountManager&MockObject $accountManager;
@@ -30,13 +31,13 @@ class DashboardServiceTest extends TestCase {
3031
protected function setUp(): void {
3132
parent::setUp();
3233

33-
$this->config = $this->createMock(IConfig::class);
34+
$this->userConfig = $this->createMock(IUserConfig::class);
3435
$this->appConfig = $this->createMock(IAppConfig::class);
3536
$this->userManager = $this->createMock(IUserManager::class);
3637
$this->accountManager = $this->createMock(IAccountManager::class);
3738

3839
$this->service = new DashboardService(
39-
$this->config,
40+
$this->userConfig,
4041
$this->appConfig,
4142
'alice',
4243
$this->userManager,
@@ -90,7 +91,7 @@ public function testGetBirthdateUserNotFound(): void {
9091

9192
public function testGetBirthdateNoUserId(): void {
9293
$service = new DashboardService(
93-
$this->config,
94+
$this->userConfig,
9495
$this->appConfig,
9596
null,
9697
$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/caldav.php">
8667
<DeprecatedMethod>
8768
<code><![CDATA[exec]]></code>

0 commit comments

Comments
 (0)