fixes done by psalm

Signed-off-by: Benjamin Brahmer <info@b-brahmer.de>
This commit is contained in:
Benjamin Brahmer 2021-01-06 20:16:33 +01:00 committed by Sean Molenaar
parent cc582c5dc8
commit 7180e11bdb
22 changed files with 188 additions and 78 deletions

View File

@ -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;

View File

@ -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();

View File

@ -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();

View File

@ -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)];

View File

@ -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);
}

View File

@ -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 {

View File

@ -189,6 +189,8 @@ class PageController extends Controller
* @NoAdminRequired
*
* @param string $lang
*
* @return Http\JSONResponse|array
*/
public function explore(string $lang)
{

View File

@ -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;
}

View File

@ -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);

View File

@ -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

View File

@ -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);

View File

@ -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');

View File

@ -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');

View File

@ -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) {
}

View File

@ -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');

View File

@ -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) {
}

View File

@ -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;
}

View File

@ -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);
}

View File

@ -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';

View File

@ -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->findByGuidHash($feedId, $guidHash);
@ -196,13 +199,16 @@ class ItemService extends Service
/**
* Read or unread an item
*
* @param int $itemId the id of the item that should be read
* @param boolean $isRead if true the item will be marked as read,
* @param int $itemId the id of the item that should be read
* @param boolean $isRead if true the item will be marked as read,
* if false unread
* @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 read($itemId, $isRead, $userId)
public function read($itemId, $isRead, $userId): void
{
try {
$lastModified = $this->timeFactory->getMicroTime();
@ -220,8 +226,10 @@ class ItemService extends Service
* used to prevent marking items as read that
* the users hasn't seen yet
* @param string $userId the name of the user
*
* @return void
*/
public function readAll($highestItemId, $userId)
public function readAll($highestItemId, $userId): void
{
$time = $this->timeFactory->getMicroTime();
$this->oldItemMapper->readAll($highestItemId, $time, $userId);
@ -236,8 +244,10 @@ class ItemService extends Service
* used to prevent marking items as read that
* the users hasn't seen yet
* @param string $userId the name of the user
*
* @return void
*/
public function readFolder(?int $folderId, $highestItemId, $userId)
public function readFolder(?int $folderId, $highestItemId, $userId): void
{
$time = $this->timeFactory->getMicroTime();
$this->oldItemMapper->readFolder(
@ -257,8 +267,10 @@ class ItemService extends Service
* used to prevent marking items as read that
* the users hasn't seen yet
* @param string $userId the name of the user
*
* @return void
*/
public function readFeed($feedId, $highestItemId, $userId)
public function readFeed($feedId, $highestItemId, $userId): void
{
$time = $this->timeFactory->getMicroTime();
$this->oldItemMapper->readFeed($feedId, $highestItemId, $time, $userId);
@ -270,8 +282,10 @@ class ItemService extends Service
* count of $this->autoPurgeCount starting by the oldest. This is to clean
* up the database so that old entries don't spam your db. As criteria for
* old, the id is taken
*
* @return void
*/
public function autoPurgeOld()
public function autoPurgeOld(): void
{
$count = $this->config->getAppValue(
Application::NAME,
@ -325,8 +339,10 @@ class ItemService extends Service
/**
* Regenerates the search index for all items
*
* @return void
*/
public function generateSearchIndices()
public function generateSearchIndices(): void
{
$this->oldItemMapper->updateSearchIndices();
}

View File

@ -43,20 +43,20 @@ class UpdaterService
}
public function beforeUpdate()
public function beforeUpdate(): void
{
$this->folderService->purgeDeleted(null, null);
$this->feedService->purgeDeleted(null, null);
}
public function update()
public function update(): void
{
$this->feedService->fetchAll();
}
public function afterUpdate()
public function afterUpdate(): void
{
$this->itemService->purgeOverThreshold(null);
}

View File

@ -17,6 +17,9 @@ class AdminSection implements IIconSection
$this->l = $l;
}
/**
* @return string
*/
public function getID()
{
return 'news';
@ -32,6 +35,9 @@ class AdminSection implements IIconSection
return 10;
}
/**
* @return string
*/
public function getIcon()
{
return $this->url->imagePath('news', 'app-dark.svg');