Skip to content

Commit 5cf4861

Browse files
committed
refactor: Fix psalm issues
- Add typing for most of the services, controllers and mappers - Add api doc for mappers - Use vendor-bin for psalm - Use attributes for controllers - Fix upload of attachments Signed-off-by: Carl Schwan <[email protected]>
1 parent 64741e4 commit 5cf4861

File tree

77 files changed

+4257
-1393
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

77 files changed

+4257
-1393
lines changed

composer.json

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,31 +9,35 @@
99
}
1010
],
1111
"require": {
12-
"justinrainbow/json-schema": "^6.0"
12+
"justinrainbow/json-schema": "^6.0",
13+
"bamarni/composer-bin-plugin": "^1.8"
1314
},
1415
"require-dev": {
1516
"roave/security-advisories": "dev-master",
1617
"phpunit/phpunit": "^9",
1718
"nextcloud/coding-standard": "^1.1",
18-
"nextcloud/ocp": "dev-master",
19-
"psalm/phar": "^5.13"
19+
"nextcloud/ocp": "dev-master"
2020
},
2121
"config": {
2222
"optimize-autoloader": true,
2323
"allow-plugins": {
24-
"composer/package-versions-deprecated": true
24+
"composer/package-versions-deprecated": true,
25+
"bamarni/composer-bin-plugin": true
2526
},
2627
"platform": {
2728
"php": "8.1"
2829
}
2930
},
3031
"scripts": {
32+
"post-install-cmd": [
33+
"@composer bin all install --ansi"
34+
],
3135
"lint": "find . -name \\*.php -not -path './vendor/*' -print0 | xargs -0 -n1 php -l",
3236
"cs:check": "php-cs-fixer fix --dry-run --diff",
3337
"cs:fix": "php-cs-fixer fix",
34-
"psalm": "psalm.phar",
35-
"psalm:update-baseline": "psalm.phar --update-baseline",
36-
"psalm:fix": "psalm.phar --alter --issues=InvalidReturnType,InvalidNullableReturnType,MismatchingDocblockParamType,MismatchingDocblockReturnType,MissingParamType,InvalidFalsableReturnType",
38+
"psalm": "psalm",
39+
"psalm:update-baseline": "psalm --threads=$(nproc) --no-cache --update-baseline",
40+
"psalm:fix": "psalm --alter --issues=InvalidReturnType,InvalidNullableReturnType,MismatchingDocblockParamType,MismatchingDocblockReturnType,MissingParamType,InvalidFalsableReturnType",
3741
"test": [
3842
"@test:unit",
3943
"@test:integration"

composer.lock

Lines changed: 58 additions & 36 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/Activity/ActivityManager.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -516,7 +516,7 @@ private function findDetailsForStack($stackId) {
516516
];
517517
}
518518

519-
private function findDetailsForCard($cardId, $subject = null) {
519+
private function findDetailsForCard(int $cardId, ?string $subject = null): array {
520520
$card = $this->cardMapper->find($cardId);
521521
$stack = $this->stackMapper->find($card->getStackId());
522522
$board = $this->boardMapper->find($stack->getBoardId());

lib/Activity/SettingComment.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77

88
namespace OCA\Deck\Activity;
99

10+
/**
11+
* @psalm-api SettingComment
12+
*/
1013
class SettingComment extends SettingBase {
1114

1215
/**

lib/Controller/AttachmentApiController.php

Lines changed: 29 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,13 @@
66
*/
77
namespace OCA\Deck\Controller;
88

9+
use OCA\Deck\Db\Attachment;
910
use OCA\Deck\Service\AttachmentService;
1011
use OCP\AppFramework\ApiController;
1112
use OCP\AppFramework\Http;
13+
use OCP\AppFramework\Http\Attribute\CORS;
14+
use OCP\AppFramework\Http\Attribute\NoAdminRequired;
15+
use OCP\AppFramework\Http\Attribute\NoCSRFRequired;
1216
use OCP\AppFramework\Http\DataResponse;
1317
use OCP\IRequest;
1418

@@ -21,72 +25,52 @@ public function __construct(
2125
parent::__construct($appName, $request);
2226
}
2327

24-
/**
25-
* @NoAdminRequired
26-
* @CORS
27-
* @NoCSRFRequired
28-
*
29-
*/
30-
public function getAll($apiVersion) {
28+
#[NoAdminRequired]
29+
#[CORS]
30+
#[NoCSRFRequired]
31+
public function getAll(string $apiVersion): DataResponse {
3132
$attachment = $this->attachmentService->findAll($this->request->getParam('cardId'), true);
3233
if ($apiVersion === '1.0') {
33-
$attachment = array_filter($attachment, function ($attachment) {
34-
return $attachment->getType() === 'deck_file';
35-
});
34+
$attachment = array_filter($attachment, fn (Attachment $attachment): bool => $attachment->getType() === 'deck_file');
3635
}
3736
return new DataResponse($attachment, HTTP::STATUS_OK);
3837
}
3938

40-
/**
41-
* @NoAdminRequired
42-
* @CORS
43-
* @NoCSRFRequired
44-
*
45-
*/
46-
public function display($cardId, $attachmentId, $type = 'deck_file') {
39+
#[NoAdminRequired]
40+
#[CORS]
41+
#[NoCSRFRequired]
42+
public function display(int $cardId, int $attachmentId, string $type = 'deck_file') {
4743
return $this->attachmentService->display($cardId, $attachmentId, $type);
4844
}
4945

50-
/**
51-
* @NoAdminRequired
52-
* @CORS
53-
* @NoCSRFRequired
54-
*
55-
*/
56-
public function create($cardId, $type, $data) {
46+
#[NoAdminRequired]
47+
#[CORS]
48+
#[NoCSRFRequired]
49+
public function create(int $cardId, string $type, string $data): DataResponse {
5750
$attachment = $this->attachmentService->create($cardId, $type, $data);
5851
return new DataResponse($attachment, HTTP::STATUS_OK);
5952
}
6053

61-
/**
62-
* @NoAdminRequired
63-
* @CORS
64-
* @NoCSRFRequired
65-
*
66-
*/
67-
public function update($cardId, $attachmentId, $data, $type = 'deck_file') {
54+
#[NoAdminRequired]
55+
#[CORS]
56+
#[NoCSRFRequired]
57+
public function update(int $cardId, int $attachmentId, string $data, string $type = 'deck_file'): DataResponse {
6858
$attachment = $this->attachmentService->update($cardId, $attachmentId, $data, $type);
6959
return new DataResponse($attachment, HTTP::STATUS_OK);
7060
}
7161

72-
/**
73-
* @NoAdminRequired
74-
* @CORS
75-
* @NoCSRFRequired
76-
*
77-
*/
78-
public function delete($cardId, $attachmentId, $type = 'deck_file') {
62+
#[NoAdminRequired]
63+
#[CORS]
64+
#[NoCSRFRequired]
65+
public function delete(int $cardId, int $attachmentId, string $type = 'deck_file'): DataResponse {
7966
$attachment = $this->attachmentService->delete($cardId, $attachmentId, $type);
8067
return new DataResponse($attachment, HTTP::STATUS_OK);
8168
}
8269

83-
/**
84-
* @NoAdminRequired
85-
* @CORS
86-
* @NoCSRFRequired
87-
*
88-
*/
89-
public function restore($cardId, $attachmentId, $type = 'deck_file') {
70+
#[NoAdminRequired]
71+
#[CORS]
72+
#[NoCSRFRequired]
73+
public function restore(int $cardId, int $attachmentId, string $type = 'deck_file'): DataResponse {
9074
$attachment = $this->attachmentService->restore($cardId, $attachmentId, $type);
9175
return new DataResponse($attachment, HTTP::STATUS_OK);
9276
}

0 commit comments

Comments
 (0)