Skip to content

Commit

Permalink
fix: psalm issues
Browse files Browse the repository at this point in the history
Signed-off-by: Marcel Klehr <[email protected]>
  • Loading branch information
marcelklehr committed Jun 1, 2024
1 parent ffea417 commit 26694fd
Show file tree
Hide file tree
Showing 19 changed files with 255 additions and 201 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"require-dev": {
"phpunit/phpunit": "^9.5.26",
"nextcloud/coding-standard": "^1.0.0",
"vimeo/psalm": "^4",
"vimeo/psalm": "5.x",
"nextcloud/ocp": "dev-master"
},
"config": {
Expand Down
3 changes: 3 additions & 0 deletions lib/Activity/ActivityPublisher.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
use OCP\EventDispatcher\IEventListener;
use OCP\IL10N;

/**
* @psalm-implements IEventListener<ChangeEvent>
*/
class ActivityPublisher implements IEventListener {
/**
* @var IManager
Expand Down
7 changes: 6 additions & 1 deletion lib/AugmentedTemplateResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,15 @@
use OC;
use OCP\AppFramework\Http\TemplateResponse;

/**
* @psalm-template S of int
* @psalm-template H of array<string, mixed>
* @psalm-implements TemplateResponse<S,H>
*/
class AugmentedTemplateResponse extends TemplateResponse {
public function render() {
$return = parent::render();
$return = preg_replace('/<link rel="manifest" href="(.*?)">/i', '<link rel="manifest" href="'. OC::$server->getURLGenerator()->linkToRouteAbsolute('bookmarks.web_view.manifest').'">', $return);
preg_replace('/<link rel="manifest" href="(.*?)">/i', '<link rel="manifest" href="'. OC::$server->getURLGenerator()->linkToRouteAbsolute('bookmarks.web_view.manifest').'">', $return);
return $return;
}
}
9 changes: 5 additions & 4 deletions lib/Controller/BookmarkController.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
use DateInterval;
use DateTime;
use Exception;
use OC\DB\Exceptions\DbalException;
use OCA\Bookmarks\Contract\IImage;
use OCA\Bookmarks\Db\Bookmark;
use OCA\Bookmarks\Db\BookmarkMapper;
Expand Down Expand Up @@ -154,7 +153,7 @@ public function __construct(
*
* @return ((int|mixed)[]|mixed)[]
*
* @psalm-return array{folders: array<array-key, int>, tags: array|mixed}
* @psalm-return array{folders: array<array-key, int>, tags: array<array-key, mixed>|mixed, archivedFilePath?: mixed|string, archivedFileType?: mixed|string, ...<array-key, mixed>}
*/
private function _returnBookmarkAsArray(Bookmark $bookmark): array {
$array = $bookmark->toArray();
Expand Down Expand Up @@ -306,7 +305,9 @@ public function getBookmarks(
'description' => $description,
'bookmarks' => $bookmarks,
], '');
$response->setHeaders($res->getHeaders());
/** @var array<string, mixed> $headers */
$headers = $res->getHeaders();
$response->setHeaders($headers);
$response->setStatus($res->getStatus());
if (stripos($this->request->getHeader('accept'), 'application/rss+xml') !== false) {
$response->addHeader('Content-Type', 'application/rss+xml');
Expand Down Expand Up @@ -875,7 +876,7 @@ public function getDeletedBookmarks(): DataResponse {
}
try {
$bookmarks = $this->treeMapper->getSoftDeletedRootItems($this->authorizer->getUserId(), TreeMapper::TYPE_BOOKMARK);
} catch (UrlParseError|DbalException|\OCP\DB\Exception $e) {
} catch (UrlParseError|\OCP\DB\Exception $e) {
return new Http\DataResponse(['status' => 'error', 'data' => 'Internal error'], Http::STATUS_INTERNAL_SERVER_ERROR);
}

Expand Down
3 changes: 1 addition & 2 deletions lib/Controller/FoldersController.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

namespace OCA\Bookmarks\Controller;

use OC\DB\Exceptions\DbalException;
use OCA\Bookmarks\Db\Folder;
use OCA\Bookmarks\Db\FolderMapper;
use OCA\Bookmarks\Db\PublicFolder;
Expand Down Expand Up @@ -783,7 +782,7 @@ public function getDeletedFolders(): DataResponse {
$array['children'] = $this->treeMapper->getSubFolders($folder->getId(), -1, true);
return $array;
}, $folders);
} catch (UrlParseError|DbalException|Exception $e) {
} catch (UrlParseError|Exception $e) {
return new Http\DataResponse(['status' => 'error', 'data' => 'Internal error'], Http::STATUS_INTERNAL_SERVER_ERROR);
}

Expand Down
2 changes: 1 addition & 1 deletion lib/Db/BookmarkMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public function __construct(IDBConnection $db, IEventDispatcher $eventDispatcher
$this->eventDispatcher = $eventDispatcher;
$this->urlNormalizer = $urlNormalizer;
$this->config = $config;
$this->limit = (int)$config->getAppValue('bookmarks', 'performance.maxBookmarksperAccount', 0);
$this->limit = (int)$config->getAppValue('bookmarks', 'performance.maxBookmarksperAccount', '0');
$this->publicMapper = $publicMapper;

$this->deleteTagsQuery = $this->getDeleteTagsQuery();
Expand Down
2 changes: 1 addition & 1 deletion lib/Db/Share.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public function __construct() {
/**
* @return array
*
* @psalm-return array{id: mixed, folderId: mixed, owner: mixed, participant: mixed, type: mixed, canWrite: mixed, canShare: mixed, createdAt: mixed}
* @psalm-return array{id: mixed, folderId: mixed, owner: mixed, participant: mixed, type: mixed, canWrite: mixed, canShare: mixed, createdAt: mixed, participantDisplayName: string}
*/
public function toArray(): array {
return [
Expand Down
3 changes: 2 additions & 1 deletion lib/Db/SharedFolderMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -185,10 +185,11 @@ public function findByOwnerAndUser(string $owner, string $userId): array {

/**
* @param int $shareId
* @param int $userId
* @param string $userId
* @return SharedFolder
* @throws DoesNotExistException
* @throws MultipleObjectsReturnedException
* @throws Exception
*/
public function findByShareAndUser(int $shareId, string $userId): SharedFolder {
$qb = $this->db->getQueryBuilder();
Expand Down
Loading

0 comments on commit 26694fd

Please sign in to comment.