Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit3f0302e

Browse files
committed
refactor(dashboard): Fix all psalm issues
Signed-off-by: Carl Schwan <carl.schwan@nextcloud.com>
1 parent89fcefb commit3f0302e

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
useOCP\AppFramework\Http\DataResponse;
1919
useOCP\AppFramework\OCSController;
2020
useOCP\AppFramework\Services\IAppConfig;
21+
useOCP\Config\IUserConfig;
2122
useOCP\Dashboard\IAPIWidget;
2223
useOCP\Dashboard\IAPIWidgetV2;
2324
useOCP\Dashboard\IButtonWidget;
@@ -30,7 +31,6 @@
3031
useOCP\Dashboard\Model\WidgetItem;
3132

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

3636
/**
@@ -45,7 +45,7 @@ public function __construct(
4545
IRequest$request,
4646
privateIManager$dashboardManager,
4747
privateIAppConfig$appConfig,
48-
privateIConfig$config,
48+
privateIUserConfig$userConfig,
4949
private ?string$userId,
5050
privateDashboardService$service,
5151
) {
@@ -59,7 +59,7 @@ public function __construct(
5959
privatefunctiongetShownWidgets(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
returnarray_filter(
@@ -202,7 +202,7 @@ public function getLayout(): DataResponse {
202202
#[NoAdminRequired]
203203
#[ApiRoute(verb:'POST', url:'/api/v3/layout')]
204204
publicfunctionupdateLayout(array$layout):DataResponse {
205-
$this->config->setUserValue($this->userId,'dashboard','layout',implode(',',$layout));
205+
$this->userConfig->setValueString($this->userId,'dashboard','layout',implode(',',$layout));
206206
returnnewDataResponse(['layout' =>$layout]);
207207
}
208208

@@ -230,7 +230,7 @@ public function getStatuses(): DataResponse {
230230
#[NoAdminRequired]
231231
#[ApiRoute(verb:'POST', url:'/api/v3/statuses')]
232232
publicfunctionupdateStatuses(array$statuses):DataResponse {
233-
$this->config->setUserValue($this->userId,'dashboard','statuses',implode(',',$statuses));
233+
$this->userConfig->setValueString($this->userId,'dashboard','statuses',implode(',',$statuses));
234234
returnnewDataResponse(['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
useOCP\AppFramework\Http\FeaturePolicy;
1818
useOCP\AppFramework\Http\TemplateResponse;
1919
useOCP\AppFramework\Services\IInitialState;
20+
useOCP\Config\IUserConfig;
2021
useOCP\Dashboard\IIconWidget;
2122
useOCP\Dashboard\IManager;
2223
useOCP\Dashboard\IWidget;
@@ -33,9 +34,9 @@ public function __construct(
3334
string$appName,
3435
IRequest$request,
3536
privateIInitialState$initialState,
36-
privateIEventDispatcher$eventDispatcher,
3737
privateIManager$dashboardManager,
3838
privateIConfig$config,
39+
privateIUserConfig$userConfig,
3940
privateIL10N$l10n,
4041
private ?string$userId,
4142
privateDashboardService$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 =newTemplateResponse('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
useOCP\Accounts\IAccountManager;
1313
useOCP\Accounts\PropertyDoesNotExistException;
1414
useOCP\AppFramework\Services\IAppConfig;
15+
useOCP\Config\IUserConfig;
1516
useOCP\IConfig;
1617
useOCP\IUserManager;
1718

1819
class DashboardService {
1920
publicfunction__construct(
20-
privateIConfig$config,
21+
privateIUserConfig$userConfig,
2122
privateIAppConfig$appConfig,
2223
private ?string$userId,
2324
privateIUserManager$userManager,
@@ -31,21 +32,24 @@ public function __construct(
3132
*/
3233
publicfunctiongetLayout():array {
3334
$systemDefault =$this->appConfig->getAppValueString('layout','recommendations,spreed,mail,calendar');
34-
returnarray_values(array_filter(explode(',',$this->config->getUserValue($this->userId,'dashboard','layout',$systemDefault)),fn (string$value) =>$value !==''));
35+
returnarray_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-
publicfunctiongetStatuses() {
41-
$configStatuses =$this->config->getUserValue($this->userId,'dashboard','statuses','');
44+
publicfunctiongetStatuses():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
returnarray_keys(array_filter($statuses,staticfn (bool$value) =>$value));
48-
}catch (JsonException$e) {
52+
}catch (JsonException) {
4953
returnarray_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
useOCA\Dashboard\Service\DashboardService;
1414
useOCP\Accounts\IAccountManager;
1515
useOCP\AppFramework\Services\IAppConfig;
16+
useOCP\Config\IUserConfig;
1617
useOCP\IConfig;
1718
useOCP\IUser;
1819
useOCP\IUserManager;
@@ -21,7 +22,7 @@
2122

2223
class DashboardServiceTestextends TestCase {
2324

24-
privateIConfig&MockObject$config;
25+
privateIUserConfig&MockObject$userConfig;
2526
privateIAppConfig&MockObject$appConfig;
2627
privateIUserManager&MockObject$userManager;
2728
privateIAccountManager&MockObject$accountManager;
@@ -30,13 +31,13 @@ class DashboardServiceTest extends TestCase {
3031
protectedfunctionsetUp():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 =newDashboardService(
39-
$this->config,
40+
$this->userConfig,
4041
$this->appConfig,
4142
'alice',
4243
$this->userManager,
@@ -90,7 +91,7 @@ public function testGetBirthdateUserNotFound(): void {
9091

9192
publicfunctiontestGetBirthdateNoUserId():void {
9293
$service =newDashboardService(
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-
<filesrc="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-
<filesrc="apps/dashboard/lib/Controller/DashboardController.php">
74-
<DeprecatedMethod>
75-
<code><![CDATA[getUserValue]]></code>
76-
<code><![CDATA[setUserValue]]></code>
77-
</DeprecatedMethod>
78-
</file>
79-
<filesrc="apps/dashboard/lib/Service/DashboardService.php">
80-
<DeprecatedMethod>
81-
<code><![CDATA[getUserValue]]></code>
82-
<code><![CDATA[getUserValue]]></code>
83-
</DeprecatedMethod>
84-
</file>
8566
<filesrc="apps/dav/appinfo/v1/caldav.php">
8667
<DeprecatedMethod>
8768
<code><![CDATA[exec]]></code>

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp