diff options
author | Benjamin Brahmer <info@b-brahmer.de> | 2021-01-06 20:16:33 +0100 |
---|---|---|
committer | Sean Molenaar <SMillerDev@users.noreply.github.com> | 2021-01-08 22:45:10 +0100 |
commit | 7180e11bdb3f27a1a282a137ca95279b39944b5b (patch) | |
tree | 17fd8152b8fabcb760395b45b5e47e66022304a9 /lib | |
parent | cc582c5dc8f5c5ec7052f4e2cab8530b9307afaa (diff) |
fixes done by psalm
Signed-off-by: Benjamin Brahmer <info@b-brahmer.de>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Config/LegacyConfig.php | 7 | ||||
-rw-r--r-- | lib/Controller/ApiController.php | 4 | ||||
-rw-r--r-- | lib/Controller/Controller.php | 4 | ||||
-rw-r--r-- | lib/Controller/FolderController.php | 6 | ||||
-rw-r--r-- | lib/Controller/ItemApiController.php | 46 | ||||
-rw-r--r-- | lib/Controller/ItemController.php | 4 | ||||
-rw-r--r-- | lib/Controller/PageController.php | 2 | ||||
-rw-r--r-- | lib/Db/Item.php | 2 | ||||
-rw-r--r-- | lib/Db/ItemMapper.php | 98 | ||||
-rw-r--r-- | lib/Db/ItemMapperV2.php | 2 | ||||
-rw-r--r-- | lib/Db/Mysql/ItemMapper.php | 5 | ||||
-rw-r--r-- | lib/Migration/MigrateConfig.php | 3 | ||||
-rw-r--r-- | lib/Migration/MigrateStatusFlags.php | 3 | ||||
-rw-r--r-- | lib/Migration/Version140200Date20200824201413.php | 4 | ||||
-rw-r--r-- | lib/Migration/Version150004Date20201009183830.php | 4 | ||||
-rw-r--r-- | lib/Migration/Version150005Date20201009192341.php | 4 | ||||
-rw-r--r-- | lib/Plugin/Client/Plugin.php | 4 | ||||
-rw-r--r-- | lib/Service/FolderServiceV2.php | 4 | ||||
-rw-r--r-- | lib/Service/ImportService.php | 4 | ||||
-rw-r--r-- | lib/Service/ItemService.php | 44 | ||||
-rw-r--r-- | lib/Service/UpdaterService.php | 6 | ||||
-rw-r--r-- | lib/Settings/AdminSection.php | 6 |
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 c6267ac04..635d8d592 100644 --- a/lib/Migration/Version150004Date20201009183830.php +++ b/lib/Migration/Version150004Date20201009183830.php @@ -26,6 +26,8 @@ class Version150004Date20201009183830 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) { } @@ -63,6 +65,8 @@ class Version150004Date20201009183830 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) { $item_name = $this->connection->getQueryBuilder()->getTableName('news_items'); diff --git a/lib/Migration/Version150005Date20201009192341.php b/lib/Migration/Version150005Date20201009192341.php index 937d3f50b..00d2d9553 100644 --- a/lib/Migration/Version150005Date20201009192341.php +++ b/lib/Migration/Version150005Date20201009192341.php @@ -27,6 +27,8 @@ class Version150005Date20201009192341 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) { $qb = $this->connection->getQueryBuilder(); @@ -92,6 +94,8 @@ class Version150005Date20201009192341 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/Plugin/Client/Plugin.php b/lib/Plugin/Client/Plugin.php index 7c587e6bb..373968056 100644 --- a/lib/Plugin/Client/Plugin.php +++ b/lib/Plugin/Client/Plugin.php @@ -26,12 +26,12 @@ class Plugin private static $scripts = []; private static $styles = []; - public static function registerStyle($appName, $styleName) + public static function registerStyle($appName, $styleName): void { self::$styles[$appName] = $styleName; } - public static function registerScript($appName, $scriptName) + public static function registerScript($appName, $scriptName): void { self::$scripts[$appName] = $scriptName; } diff --git a/lib/Service/FolderServiceV2.php b/lib/Service/FolderServiceV2.php index 25903c17b..c60d13172 100644 --- a/lib/Service/FolderServiceV2.php +++ b/lib/Service/FolderServiceV2.php @@ -116,8 +116,10 @@ class FolderServiceV2 extends Service * * @param string|null $userID The user to purge * @param int|null $minTimestamp The timestamp to purge from + * + * @return void */ - public function purgeDeleted(?string $userID, ?int $minTimestamp) + public function purgeDeleted(?string $userID, ?int $minTimestamp): void { $this->mapper->purgeDeleted($userID, $minTimestamp); } diff --git a/lib/Service/ImportService.php b/lib/Service/ImportService.php index c3334fad2..e7b6ab7be 100644 --- a/lib/Service/ImportService.php +++ b/lib/Service/ImportService.php @@ -71,9 +71,9 @@ class ImportService * @param string $userId * @param array $json * - * @return array|null + * @return \OCP\AppFramework\Db\Entity|null */ - public function importArticles(string $userId, array $json) + public function importArticles(string $userId, array $json): ?\OCP\AppFramework\Db\Entity { $url = 'http://nextcloud/nofeed'; diff --git a/lib/Service/ItemService.php b/lib/Service/ItemService.php index 1b459d49c..70f89cfc2 100644 --- a/lib/Service/ItemService.php +++ b/lib/Service/ItemService.php @@ -172,14 +172,17 @@ class ItemService extends Service /** * Star or unstar an item * - * @param int $feedId the id of the item's feed that should be starred - * @param string $guidHash the guidHash of the item that should be starred - * @param boolean $isStarred if true the item will be marked as starred, + * @param int $feedId the id of the item's feed that should be starred + * @param string $guidHash the guidHash of the item that should be starred + * @param boolean $isStarred if true the item will be marked as starred, * if false unstar - * @param string $userId the name of the user for security reasons + * @param string $userId the name of the user for security reasons + * * @throws ServiceNotFoundException if the item does not exist + * + * @return void */ - public function star($feedId, $guidHash, $isStarred, $userId) + public function star($feedId, $guidHash, $isStarred, $userId): void { try { $item = $this->mapper->findByGuidHas |