summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBenjamin Brahmer <info@b-brahmer.de>2021-01-06 20:16:33 +0100
committerSean Molenaar <SMillerDev@users.noreply.github.com>2021-01-08 22:45:10 +0100
commit7180e11bdb3f27a1a282a137ca95279b39944b5b (patch)
tree17fd8152b8fabcb760395b45b5e47e66022304a9
parentcc582c5dc8f5c5ec7052f4e2cab8530b9307afaa (diff)
fixes done by psalm
Signed-off-by: Benjamin Brahmer <info@b-brahmer.de>
-rw-r--r--lib/Config/LegacyConfig.php7
-rw-r--r--lib/Controller/ApiController.php4
-rw-r--r--lib/Controller/Controller.php4
-rw-r--r--lib/Controller/FolderController.php6
-rw-r--r--lib/Controller/ItemApiController.php46
-rw-r--r--lib/Controller/ItemController.php4
-rw-r--r--lib/Controller/PageController.php2
-rw-r--r--lib/Db/Item.php2
-rw-r--r--lib/Db/ItemMapper.php98
-rw-r--r--lib/Db/ItemMapperV2.php2
-rw-r--r--lib/Db/Mysql/ItemMapper.php5
-rw-r--r--lib/Migration/MigrateConfig.php3
-rw-r--r--lib/Migration/MigrateStatusFlags.php3
-rw-r--r--lib/Migration/Version140200Date20200824201413.php4
-rw-r--r--lib/Migration/Version150004Date20201009183830.php4
-rw-r--r--lib/Migration/Version150005Date20201009192341.php4
-rw-r--r--lib/Plugin/Client/Plugin.php4
-rw-r--r--lib/Service/FolderServiceV2.php4
-rw-r--r--lib/Service/ImportService.php4
-rw-r--r--lib/Service/ItemService.php44
-rw-r--r--lib/Service/UpdaterService.php6
-rw-r--r--lib/Settings/AdminSection.php6
22 files changed, 188 insertions, 78 deletions
diff --git a/lib/Config/LegacyConfig.php b/lib/Config/LegacyConfig.php
index 02181370c..f5cd36ffb 100644
--- a/lib/Config/LegacyConfig.php
+++ b/lib/Config/LegacyConfig.php
@@ -54,7 +54,12 @@ class LegacyConfig
$this->updateInterval = 3600;
}
- public function read($configPath, $createIfNotExists = false)
+ /**
+ * @param false $createIfNotExists
+ *
+ * @return void
+ */
+ public function read($configPath, bool $createIfNotExists = false)
{
if ($this->fileSystem === null) {
return;
diff --git a/lib/Controller/ApiController.php b/lib/Controller/ApiController.php
index 1ffa1272d..a434f8de7 100644
--- a/lib/Controller/ApiController.php
+++ b/lib/Controller/ApiController.php
@@ -49,9 +49,9 @@ class ApiController extends BaseApiController
}
/**
- * @return IUser
+ * @return IUser|null
*/
- protected function getUser()
+ protected function getUser(): ?IUser
{
if ($this->userSession === null) {
throw new NotLoggedInException();
diff --git a/lib/Controller/Controller.php b/lib/Controller/Controller.php
index 726ee8e7d..ab3c83a70 100644
--- a/lib/Controller/Controller.php
+++ b/lib/Controller/Controller.php
@@ -48,9 +48,9 @@ class Controller extends BaseController
}
/**
- * @return IUser
+ * @return IUser|null
*/
- protected function getUser()
+ protected function getUser(): ?IUser
{
if ($this->userSession === null) {
throw new NotLoggedInException();
diff --git a/lib/Controller/FolderController.php b/lib/Controller/FolderController.php
index acf3f0109..9dc13b309 100644
--- a/lib/Controller/FolderController.php
+++ b/lib/Controller/FolderController.php
@@ -56,8 +56,12 @@ class FolderController extends Controller
/**
* @NoAdminRequired
+ *
+ * @return array[]
+ *
+ * @psalm-return array{folders: array}
*/
- public function index()
+ public function index(): array
{
$folders = $this->folderService->findAllForUser($this->getUserId());
return ['folders' => $this->serialize($folders)];
diff --git a/lib/Controller/ItemApiController.php b/lib/Controller/ItemApiController.php
index 442734127..c958324af 100644
--- a/lib/Controller/ItemApiController.php
+++ b/lib/Controller/ItemApiController.php
@@ -109,6 +109,11 @@ class ItemApiController extends ApiController
}
+ /**
+ * @return JSONResponse|array
+ *
+ * @psalm-return JSONResponse|array<empty, empty>
+ */
private function setRead(bool $isRead, int $itemId)
{
try {
@@ -151,6 +156,11 @@ class ItemApiController extends ApiController
}
+ /**
+ * @return JSONResponse|array
+ *
+ * @psalm-return JSONResponse|array<empty, empty>
+ */
private function setStarred(bool $isStarred, int $feedId, string $guidHash)
{
try {
@@ -202,18 +212,22 @@ class ItemApiController extends ApiController
/**
* @NoAdminRequired
+ *
* @NoCSRFRequired
+ *
* @CORS
*
* @param int $newestItemId
+ *
+ * @return void
*/
- public function readAll(int $newestItemId)
+ public function readAll(int $newestItemId): void
{
$this->oldItemService->readAll($newestItemId, $this->getUserId());
}
- private function setMultipleRead(bool $isRead, array $items)
+ private function setMultipleRead(bool $isRead, array $items): void
{
foreach ($items as $id) {
try {
@@ -227,12 +241,16 @@ class ItemApiController extends ApiController
/**
* @NoAdminRequired
+ *
* @NoCSRFRequired
+ *
* @CORS
*
* @param int[] $items item ids
+ *
+ * @return void
*/
- public function readMultiple(array $items)
+ public function readMultiple(array $items): void
{
$this->setMultipleRead(true, $items);
}
@@ -240,12 +258,16 @@ class ItemApiController extends ApiController
/**
* @NoAdminRequired
+ *
* @NoCSRFRequired
+ *
* @CORS
*
* @param int[] $items item ids
+ *
+ * @return void
*/
- public function unreadMultiple(array $items)
+ public function unreadMultiple(array $items): void
{
$this->setMultipleRead(false, $items);
}
@@ -254,8 +276,10 @@ class ItemApiController extends ApiController
/**
* @param bool $isStarred
* @param array $items
+ *
+ * @return void
*/
- private function setMultipleStarred(bool $isStarred, array $items)
+ private function setMultipleStarred(bool $isStarred, array $items): void
{
foreach ($items as $item) {
try {
@@ -274,12 +298,16 @@ class ItemApiController extends ApiController
/**
* @NoAdminRequired
+ *
* @NoCSRFRequired
+ *
* @CORS
*
* @param int[] $items item ids
+ *
+ * @return void
*/
- public function starMultiple(array $items)
+ public function starMultiple(array $items): void
{
$this->setMultipleStarred(true, $items);
}
@@ -287,12 +315,16 @@ class ItemApiController extends ApiController
/**
* @NoAdminRequired
+ *
* @NoCSRFRequired
+ *
* @CORS
*
* @param array $items item ids
+ *
+ * @return void
*/
- public function unstarMultiple(array $items)
+ public function unstarMultiple(array $items): void
{
$this->setMultipleStarred(false, $items);
}
diff --git a/lib/Controller/ItemController.php b/lib/Controller/ItemController.php
index 8783a5286..96ebcbaec 100644
--- a/lib/Controller/ItemController.php
+++ b/lib/Controller/ItemController.php
@@ -249,8 +249,10 @@ class ItemController extends Controller
* @NoAdminRequired
*
* @param int[] $itemIds item ids
+ *
+ * @return void
*/
- public function readMultiple($itemIds)
+ public function readMultiple($itemIds): void
{
foreach ($itemIds as $id) {
try {
diff --git a/lib/Controller/PageController.php b/lib/Controller/PageController.php
index 4b39ba9c2..35924d10c 100644
--- a/lib/Controller/PageController.php
+++ b/lib/Controller/PageController.php
@@ -189,6 +189,8 @@ class PageController extends Controller
* @NoAdminRequired
*
* @param string $lang
+ *
+ * @return Http\JSONResponse|array
*/
public function explore(string $lang)
{
diff --git a/lib/Db/Item.php b/lib/Db/Item.php
index 1dab1b96c..cb10900d4 100644
--- a/lib/Db/Item.php
+++ b/lib/Db/Item.php
@@ -199,7 +199,7 @@ class Item extends Entity implements IAPI, \JsonSerializable
return $this->enclosureMime;
}
- public function getFeedId(): string
+ public function getFeedId(): int
{
return $this->feedId;
}
diff --git a/lib/Db/ItemMapper.php b/lib/Db/ItemMapper.php
index d7edbd12f..d4a16614d 100644
--- a/lib/Db/ItemMapper.php
+++ b/lib/Db/ItemMapper.php
@@ -50,10 +50,10 @@ class ItemMapper extends Mapper
}
private function makeSelectQuery(
- $prependTo = '',
+ string $prependTo = '',
$oldestFirst = false,
$distinctFingerprint = false
- ) {
+ ): string {
if ($oldestFirst) {
$ordering = 'ASC';
} else {
@@ -95,7 +95,7 @@ class ItemMapper extends Mapper
return $sql;
}
- private function buildSearchQueryPart(array $search = [])
+ private function buildSearchQueryPart(array $search = []): string
{
return str_repeat('AND `items`.`search_index` LIKE ? ', count($search));
}
@@ -128,7 +128,7 @@ class ItemMapper extends Mapper
return $this->findEntity($sql, [$userId, $id]);
}
- public function starredCount(string $userId)
+ public function starredCount(string $userId): int
{
$sql = 'SELECT COUNT(*) AS size FROM `*PREFIX*news_items` `items` ' .
'JOIN `*PREFIX*news_feeds` `feeds` ' .
@@ -149,7 +149,7 @@ class ItemMapper extends Mapper
}
- public function readAll(int $highestItemId, $time, string $userId)
+ public function readAll(int $highestItemId, string $time, string $userId): void
{
$sql = 'UPDATE `*PREFIX*news_items` ' .
'SET unread = ? ' .
@@ -164,7 +164,7 @@ class ItemMapper extends Mapper
}
- public function readFolder(?int $folderId, $highestItemId, $time, $userId)
+ public function readFolder(?int $folderId, int $highestItemId, string $time, string $userId): void
{
$folderWhere = is_null($folderId) ? 'IS' : '=';
$sql = 'UPDATE `*PREFIX*news_items` ' .
@@ -182,7 +182,7 @@ class ItemMapper extends Mapper
}
- public function readFeed($feedId, $highestItemId, $time, $userId)
+ public function readFeed(int $feedId, int $highestItemId, string $time, string $userId): void
{
$sql = 'UPDATE `*PREFIX*news_items` ' .
'SET unread = ? ' .
@@ -200,7 +200,7 @@ class ItemMapper extends Mapper
}
- private function getOperator($oldestFirst)
+ private function getOperator($oldestFirst): string
{
if ($oldestFirst) {
return '>';
@@ -210,7 +210,7 @@ class ItemMapper extends Mapper
}
- public function findAllNew($updatedSince, $type, $showAll, $userId)
+ public function findAllNew(int $updatedSince, int $type, bool $showAll, string $userId): array
{
$sql = $this->buildStatusQueryPart($showAll, $type);
@@ -221,7 +221,7 @@ class ItemMapper extends Mapper
}
- public function findAllNewFolder(?int $id, $updatedSince, $showAll, $userId)
+ public function findAllNewFolder(?int $id, int $updatedSince, bool $showAll, string $userId): array
{
$sql = $this->buildStatusQueryPart($showAll);
@@ -234,7 +234,7 @@ class ItemMapper extends Mapper
}
- public function findAllNewFeed($id, $updatedSince, $showAll, $userId)
+ public function findAllNewFeed(?int $id, int $updatedSince, bool $showAll, string $userId): array
{
$sql = $this->buildStatusQueryPart($showAll);
@@ -246,7 +246,10 @@ class ItemMapper extends Mapper
}
- private function findEntitiesIgnoringNegativeLimit($sql, $params, $limit): array
+ /**
+ * @param (int|mixed|null)[] $params
+ */
+ private function findEntitiesIgnoringNegativeLimit($sql, array $params, $limit): array
{
// ignore limit if negative to offer a way to return all feeds
if ($limit >= 0) {
@@ -258,14 +261,14 @@ class ItemMapper extends Mapper
public function findAllFeed(
- $id,
- $limit,
- $offset,
- $showAll,
- $oldestFirst,
- $userId,
- $search = []
- ) {
+ ?int $id,
+ int $limit,
+ int $offset,
+ bool $showAll,
+ bool $oldestFirst,
+ string $userId,
+ array $search = []
+ ): array {
$params = [$userId];
$params = array_merge($params, $this->buildLikeParameters($search));
$params[] = $id;
@@ -286,13 +289,13 @@ class ItemMapper extends Mapper
public function findAllFolder(
?int $id,
- $limit,
- $offset,
- $showAll,
- $oldestFirst,
- $userId,
- $search = []
- ) {
+ int $limit,
+ int $offset,
+ bool $showAll,
+ bool $oldestFirst,
+ string $userId,
+ array $search = []
+ ): array {
$params = [$userId];
$params = array_merge($params, $this->buildLikeParameters($search));
$params[] = $id;
@@ -311,14 +314,17 @@ class ItemMapper extends Mapper
}
+ /**
+ * @param string[] $search
+ */
public function findAllItems(
- $limit,
- $offset,
- $type,
- $showAll,
- $oldestFirst,
- $userId,
- $search = []
+ int $limit,
+ int $offset,
+ int $type,
+ bool $showAll,
+ bool $oldestFirst,
+ string $userId,
+ array $search = []
): array {
$params = [$userId];
$params = array_merge($params, $this->buildLikeParameters($search));
@@ -337,7 +343,7 @@ class ItemMapper extends Mapper
}
- public function findAllUnreadOrStarred($userId)
+ public function findAllUnreadOrStarred(string $userId): array
{
$params = [$userId, true, true];
$sql = 'AND (`items`.`unread` = ? OR `items`.`starred` = ?) ';
@@ -370,6 +376,8 @@ class ItemMapper extends Mapper
* starred items
*
* @param int $threshold the number of items that should be deleted
+ *
+ * @return void
*/
public function deleteReadOlderThanThreshold($threshold)
{
@@ -417,7 +425,7 @@ class ItemMapper extends Mapper
}
- public function getNewestItemId($userId)
+ public function getNewestItemId(string $userId): int
{
$sql = 'SELECT MAX(`items`.`id`) AS `max_id` ' .
'FROM `*PREFIX*news_items` `items` ' .
@@ -434,8 +442,13 @@ class ItemMapper extends Mapper
/**
* Returns a list of ids and userid of all items
+ *
+ * @param int|null $limit
+ * @param int|null $offset
+ *
+ * @return array|false
*/
- public function findAllIds($limit = null, $offset = null)
+ public function findAllIds(?int $limit = null, ?int $offset = null)
{
$sql = 'SELECT `id` FROM `*PREFIX*news_items`';
return $this->execute($sql, [], $limit, $offset)->fetchAll();
@@ -443,8 +456,10 @@ class ItemMapper extends Mapper
/**
* Update search indices of all items
+ *
+ * @return void
*/
- public function updateSearchIndices()
+ public function updateSearchIndices(): void
{
// update indices in steps to prevent memory issues on larger systems
$step = 1000; // update 1000 items at a time
@@ -460,7 +475,7 @@ class ItemMapper extends Mapper
}
}
- private function updateSearchIndex(array $items = [])
+ private function updateSearchIndex(array $items = []): void
{
foreach ($items as $row) {
$sql = 'SELECT * FROM `*PREFIX*news_items` WHERE `id` = ?';
@@ -471,7 +486,10 @@ class ItemMapper extends Mapper
}
}
- public function readItem($itemId, $isRead, $lastModified, $userId)
+ /**
+ * @return void
+ */
+ public function readItem(int $itemId, bool $isRead, string $lastModified, string $userId)
{
$item = $this->find($userId, $itemId);
diff --git a/lib/Db/ItemMapperV2.php b/lib/Db/ItemMapperV2.php
index 10ebe056b..1925b846c 100644
--- a/lib/Db/ItemMapperV2.php
+++ b/lib/Db/ItemMapperV2.php
@@ -102,7 +102,7 @@ class ItemMapperV2 extends NewsMapperV2
* @param int $feedId ID of the feed
* @param string $guidHash hash to find with
*
- * @return Item|Entity
+ * @return Item
*
* @throws DoesNotExistException
* @throws MultipleObjectsReturnedException
diff --git a/lib/Db/Mysql/ItemMapper.php b/lib/Db/Mysql/ItemMapper.php
index 88c87038e..5ad3baf79 100644
--- a/lib/Db/Mysql/ItemMapper.php
+++ b/lib/Db/Mysql/ItemMapper.php
@@ -36,6 +36,8 @@ class ItemMapper extends \OCA\News\Db\ItemMapper
* starred items
*
* @param int $threshold the number of items that should be deleted
+ *
+ * @return void
*/
public function deleteReadOlderThanThreshold($threshold)
{
@@ -70,6 +72,9 @@ class ItemMapper extends \OCA\News\Db\ItemMapper
}
}
+ /**
+ * @return void
+ */
public function readItem($itemId, $isRead, $lastModified, $userId)
{
$item = $this->find($itemId, $userId);
diff --git a/lib/Migration/MigrateConfig.php b/lib/Migration/MigrateConfig.php
index 4ba34fb5e..3cf444f50 100644
--- a/lib/Migration/MigrateConfig.php
+++ b/lib/Migration/MigrateConfig.php
@@ -62,6 +62,9 @@ class MigrateConfig implements IRepairStep
return 'Migrate config to nextcloud managed config';
}
+ /**
+ * @return void
+ */
public function run(IOutput $output)
{
$version = $this->iConfig->getAppValue('news', 'installed_version', '0.0.0');
diff --git a/lib/Migration/MigrateStatusFlags.php b/lib/Migration/MigrateStatusFlags.php
index 514b16f4a..ac5c8ebe4 100644
--- a/lib/Migration/MigrateStatusFlags.php
+++ b/lib/Migration/MigrateStatusFlags.php
@@ -45,6 +45,9 @@ class MigrateStatusFlags implements IRepairStep
return 'Migrate binary status into separate boolean fields';
}
+ /**
+ * @return void
+ */
public function run(IOutput $output)
{
$version = $this->config->getAppValue('news', 'installed_version', '0.0.0');
diff --git a/lib/Migration/Version140200Date20200824201413.php b/lib/Migration/Version140200Date20200824201413.php
index ae17cda01..8c7298f6e 100644
--- a/lib/Migration/Version140200Date20200824201413.php
+++ b/lib/Migration/Version140200Date20200824201413.php
@@ -18,6 +18,8 @@ class Version140200Date20200824201413 extends SimpleMigrationStep {
* @param IOutput $output
* @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
* @param array $options
+ *
+ * @return void
*/
public function preSchemaChange(IOutput $output, Closure $schemaClosure, array $options) {
}
@@ -283,6 +285,8 @@ class Version140200Date20200824201413 extends SimpleMigrationStep {
* @param IOutput $output
* @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
* @param array $options
+ *
+ * @return void
*/
public function postSchemaChange(IOutput $output, Closure $schemaClosure, array $options) {
}
diff --git a/lib/Migration/Version150004Date20201009183830.php b/lib/Migration/Version150004Date20201009183830.php
index c6267