aboutsummaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorGravatar Alexandre Alapetite <alexandre@alapetite.fr> 2023-04-23 11:58:15 +0200
committerGravatar GitHub <noreply@github.com> 2023-04-23 11:58:15 +0200
commit115724622fa32e1b7981e378e87ccfb770450cb1 (patch)
tree4d7072768076fd76f2f1877757f3e2e395ab2ded /app
parent8abe53d879ef188a5c1cc394894ce211fcfa9f92 (diff)
PHPStan Level 7 for ten more files (#5327)
* PHPStan Level 7 for nine more files * Minor syntax * One more
Diffstat (limited to 'app')
-rw-r--r--app/Controllers/indexController.php4
-rw-r--r--app/Models/CategoryDAO.php4
-rw-r--r--app/Models/Entry.php4
-rw-r--r--app/Models/EntryDAO.php12
-rw-r--r--app/Models/Feed.php4
-rw-r--r--app/Models/FeedDAO.php6
-rw-r--r--app/Models/ReadingMode.php14
-rw-r--r--app/Models/TagDAO.php8
-rw-r--r--app/Models/Themes.php6
-rw-r--r--app/Models/View.php4
-rw-r--r--app/Services/ExportService.php11
-rw-r--r--app/Services/ImportService.php4
-rw-r--r--app/views/index/reader.phtml1
-rw-r--r--app/views/user/details.phtml4
14 files changed, 42 insertions, 44 deletions
diff --git a/app/Controllers/indexController.php b/app/Controllers/indexController.php
index 895161a90..21a94d53d 100644
--- a/app/Controllers/indexController.php
+++ b/app/Controllers/indexController.php
@@ -244,9 +244,9 @@ class FreshRSS_index_Controller extends FreshRSS_ActionController {
/**
* This method returns a list of entries based on the Context object.
- * @return iterable<FreshRSS_Entry>
+ * @return Traversable<FreshRSS_Entry>
*/
- public static function listEntriesByContext(): iterable {
+ public static function listEntriesByContext(): Traversable {
$entryDAO = FreshRSS_Factory::createEntryDao();
$get = FreshRSS_Context::currentGet(true);
diff --git a/app/Models/CategoryDAO.php b/app/Models/CategoryDAO.php
index 4855a43d9..e5301cb2c 100644
--- a/app/Models/CategoryDAO.php
+++ b/app/Models/CategoryDAO.php
@@ -214,8 +214,8 @@ SQL;
}
}
- /** @return iterable<array<string,string|int>> */
- public function selectAll(): iterable {
+ /** @return Traversable<array<string,string|int>> */
+ public function selectAll(): Traversable {
$sql = 'SELECT id, name, kind, `lastUpdate`, error, attributes FROM `_category`';
$stm = $this->pdo->query($sql);
if ($stm != false) {
diff --git a/app/Models/Entry.php b/app/Models/Entry.php
index b5a742535..accd13c27 100644
--- a/app/Models/Entry.php
+++ b/app/Models/Entry.php
@@ -220,8 +220,8 @@ HTML;
return $content;
}
- /** @return iterable<array{'url':string,'type'?:string,'medium'?:string,'length'?:int,'title'?:string,'description'?:string,'credit'?:string,'height'?:int,'width'?:int,'thumbnails'?:array<string>}> */
- public function enclosures(bool $searchBodyImages = false): iterable {
+ /** @return Traversable<array{'url':string,'type'?:string,'medium'?:string,'length'?:int,'title'?:string,'description'?:string,'credit'?:string,'height'?:int,'width'?:int,'thumbnails'?:array<string>}> */
+ public function enclosures(bool $searchBodyImages = false): Traversable {
$attributeEnclosures = $this->attributes('enclosures');
if (is_array($attributeEnclosures)) {
// FreshRSS 1.20.1+: The enclosures are saved as attributes
diff --git a/app/Models/EntryDAO.php b/app/Models/EntryDAO.php
index 365ee67fa..19547ac31 100644
--- a/app/Models/EntryDAO.php
+++ b/app/Models/EntryDAO.php
@@ -696,8 +696,8 @@ SQL;
}
}
- /** @return iterable<array<string,string|int>> */
- public function selectAll(): iterable {
+ /** @return Traversable<array<string,string|int>> */
+ public function selectAll(): Traversable {
$sql = 'SELECT id, guid, title, author, '
. (static::isCompressed() ? 'UNCOMPRESS(content_bin) AS content' : 'content')
. ', link, date, `lastSeen`, ' . static::sqlHexEncode('hash') . ' AS hash, is_read, is_favorite, id_feed, tags, attributes '
@@ -1149,11 +1149,11 @@ SQL;
/**
* @param int $id category/feed/tag ID
- * @return iterable<FreshRSS_Entry>
+ * @return Traversable<FreshRSS_Entry>
*/
public function listWhere(string $type = 'a', int $id = 0, int $state = FreshRSS_Entry::STATE_ALL,
string $order = 'DESC', int $limit = 1, string $firstId = '',
- ?FreshRSS_BooleanSearch $filters = null, int $date_min = 0): iterable {
+ ?FreshRSS_BooleanSearch $filters = null, int $date_min = 0): Traversable {
$stm = $this->listWhereRaw($type, $id, $state, $order, $limit, $firstId, $filters, $date_min);
if ($stm) {
while ($row = $stm->fetch(PDO::FETCH_ASSOC)) {
@@ -1164,9 +1164,9 @@ SQL;
/**
* @param array<string> $ids
- * @return iterable<FreshRSS_Entry>
+ * @return Traversable<FreshRSS_Entry>
*/
- public function listByIds(array $ids, string $order = 'DESC'): iterable {
+ public function listByIds(array $ids, string $order = 'DESC'): Traversable {
if (count($ids) < 1) {
return;
}
diff --git a/app/Models/Feed.php b/app/Models/Feed.php
index a877786b4..c0fce6e4a 100644
--- a/app/Models/Feed.php
+++ b/app/Models/Feed.php
@@ -480,8 +480,8 @@ class FreshRSS_Feed extends Minz_Model {
return $hasUniqueGuids ? $guids : $links;
}
- /** @return iterable<FreshRSS_Entry> */
- public function loadEntries(SimplePie $simplePie): iterable {
+ /** @return Traversable<FreshRSS_Entry> */
+ public function loadEntries(SimplePie $simplePie): Traversable {
$hasBadGuids = $this->attributes('hasBadGuids');
$items = $simplePie->get_items();
diff --git a/app/Models/FeedDAO.php b/app/Models/FeedDAO.php
index 42cb59063..a4d76fb62 100644
--- a/app/Models/FeedDAO.php
+++ b/app/Models/FeedDAO.php
@@ -286,8 +286,8 @@ class FreshRSS_FeedDAO extends Minz_ModelPdo {
}
}
- /** @return iterable<array<string,string|int>> */
- public function selectAll(): iterable {
+ /** @return Traversable<array<string,string|int>> */
+ public function selectAll(): Traversable {
$sql = <<<'SQL'
SELECT id, url, kind, category, name, website, description, `lastUpdate`,
priority, `pathEntries`, `httpAuth`, error, ttl, attributes
@@ -321,7 +321,7 @@ SQL;
return $feed == false ? null : $feed;
}
- /** @return array<string>|false */
+ /** @return array<int>|false */
public function listFeedsIds() {
$sql = 'SELECT id FROM `_feed`';
$stm = $this->pdo->query($sql);
diff --git a/app/Models/ReadingMode.php b/app/Models/ReadingMode.php
index 6f2fc889c..30ab13aad 100644
--- a/app/Models/ReadingMode.php
+++ b/app/Models/ReadingMode.php
@@ -17,9 +17,7 @@ class FreshRSS_ReadingMode {
* @var string
*/
protected $title;
- /**
- * @var string[]
- */
+ /** @var array{'c':string,'a':string,'params':array<string,mixed>} */
protected $urlParams;
/**
* @var bool
@@ -28,7 +26,7 @@ class FreshRSS_ReadingMode {
/**
* ReadingMode constructor.
- * @param array<string> $urlParams
+ * @param array{'c':string,'a':string,'params':array<string,mixed>} $urlParams
*/
public function __construct(string $id, string $title, array $urlParams, bool $active) {
$this->id = $id;
@@ -60,16 +58,12 @@ class FreshRSS_ReadingMode {
return $this;
}
- /**
- * @return array<string>
- */
+ /** @return array{'c':string,'a':string,'params':array<string,mixed>} */
public function getUrlParams(): array {
return $this->urlParams;
}
- /**
- * @param array<string> $urlParams
- */
+ /** @param array{'c':string,'a':string,'params':array<string,mixed>} $urlParams */
public function setUrlParams(array $urlParams): FreshRSS_ReadingMode {
$this->urlParams = $urlParams;
return $this;
diff --git a/app/Models/TagDAO.php b/app/Models/TagDAO.php
index 9dc664607..c0d6e3a36 100644
--- a/app/Models/TagDAO.php
+++ b/app/Models/TagDAO.php
@@ -153,8 +153,8 @@ SQL;
}
}
- /** @return iterable<array{'id':int,'name':string,'attributes':string}> */
- public function selectAll(): iterable {
+ /** @return Traversable<array{'id':int,'name':string,'attributes':string}> */
+ public function selectAll(): Traversable {
$sql = 'SELECT id, name, attributes FROM `_tag`';
$stm = $this->pdo->query($sql);
while ($row = $stm->fetch(PDO::FETCH_ASSOC)) {
@@ -162,8 +162,8 @@ SQL;
}
}
- /** @return iterable<array{'id_tag':int,'id_entry':string}> */
- public function selectEntryTag(): iterable {
+ /** @return Traversable<array{'id_tag':int,'id_entry':string}> */
+ public function selectEntryTag(): Traversable {
$sql = 'SELECT id_tag, id_entry FROM `_entrytag`';
$stm = $this->pdo->query($sql);
while ($row = $stm->fetch(PDO::FETCH_ASSOC)) {
diff --git a/app/Models/Themes.php b/app/Models/Themes.php
index ce63b24b2..20d825e4b 100644
--- a/app/Models/Themes.php
+++ b/app/Models/Themes.php
@@ -11,7 +11,7 @@ class FreshRSS_Themes extends Minz_Model {
/** @return array<string> */
public static function getList(): array {
return array_values(array_diff(
- scandir(PUBLIC_PATH . self::$themesUrl),
+ scandir(PUBLIC_PATH . self::$themesUrl) ?: [],
array('..', '.')
));
}
@@ -37,7 +37,7 @@ class FreshRSS_Themes extends Minz_Model {
if (is_dir($theme_dir)) {
$json_filename = $theme_dir . '/metadata.json';
if (file_exists($json_filename)) {
- $content = file_get_contents($json_filename);
+ $content = file_get_contents($json_filename) ?: '';
$res = json_decode($content, true);
if ($res &&
!empty($res['name']) &&
@@ -75,7 +75,7 @@ class FreshRSS_Themes extends Minz_Model {
}
self::$themeIconsUrl = self::$themesUrl . $theme_id . '/icons/';
self::$themeIcons = is_dir(PUBLIC_PATH . self::$themeIconsUrl) ? array_fill_keys(array_diff(
- scandir(PUBLIC_PATH . self::$themeIconsUrl),
+ scandir(PUBLIC_PATH . self::$themeIconsUrl) ?: [],
array('..', '.')
), 1) : array();
return $infos;
diff --git a/app/Models/View.php b/app/Models/View.php
index 87302a4e1..c5415c58e 100644
--- a/app/Models/View.php
+++ b/app/Models/View.php
@@ -15,7 +15,7 @@ class FreshRSS_View extends Minz_View {
public $category;
/** @var string */
public $current_user;
- /** @var array<FreshRSS_Entry> */
+ /** @var iterable<FreshRSS_Entry> */
public $entries;
/** @var FreshRSS_Entry */
public $entry;
@@ -49,7 +49,7 @@ class FreshRSS_View extends Minz_View {
public $signalError;
// Manage users
- /** @var array<string,string|int|bool> */
+ /** @var array{'feed_count':int|false,'article_count':int|false,'database_size':int,'language':string,'mail_login':string,'enabled':bool,'is_admin':bool,'last_user_activity':string,'is_default':bool} */
public $details;
/** @var bool */
public $disable_aside;
diff --git a/app/Services/ExportService.php b/app/Services/ExportService.php
index 10d5ca2cc..c19c505af 100644
--- a/app/Services/ExportService.php
+++ b/app/Services/ExportService.php
@@ -43,7 +43,7 @@ class FreshRSS_Export_Service {
public function generateOpml(): array {
$view = new FreshRSS_View();
$day = date('Y-m-d');
- $view->categories = $this->category_dao->listCategories(true, true);
+ $view->categories = $this->category_dao->listCategories(true, true) ?: [];
$view->excludeMutedFeeds = false;
return [
@@ -67,7 +67,7 @@ class FreshRSS_Export_Service {
*/
public function generateStarredEntries(string $type): array {
$view = new FreshRSS_View();
- $view->categories = $this->category_dao->listCategories(true);
+ $view->categories = $this->category_dao->listCategories(true) ?: [];
$day = date('Y-m-d');
$view->list_title = _t('sub.import_export.starred_list');
@@ -99,7 +99,7 @@ class FreshRSS_Export_Service {
}
$view = new FreshRSS_View();
- $view->categories = $this->category_dao->listCategories(true);
+ $view->categories = $this->category_dao->listCategories(true) ?: [];
$view->feed = $feed;
$day = date('Y-m-d');
$filename = "feed_{$day}_" . $feed->categoryId() . '_' . $feed->id() . '.json';
@@ -127,7 +127,7 @@ class FreshRSS_Export_Service {
* @return array<string,string> Keys are filenames and values are contents.
*/
public function generateAllFeedEntries(int $max_number_entries): array {
- $feed_ids = $this->feed_dao->listFeedsIds();
+ $feed_ids = $this->feed_dao->listFeedsIds() ?: [];
$exported_files = [];
foreach ($feed_ids as $feed_id) {
@@ -154,6 +154,9 @@ class FreshRSS_Export_Service {
// From https://stackoverflow.com/questions/1061710/php-zip-files-on-the-fly
$zip_file = tempnam('/tmp', 'zip');
+ if ($zip_file == false) {
+ return [$zip_filename, false];
+ }
$zip_archive = new ZipArchive();
$zip_archive->open($zip_file, ZipArchive::OVERWRITE);
diff --git a/app/Services/ImportService.php b/app/Services/ImportService.php
index 3707e4c5e..e5d558233 100644
--- a/app/Services/ImportService.php
+++ b/app/Services/ImportService.php
@@ -56,7 +56,7 @@ class FreshRSS_Import_Service {
// Get the categories by names so we can use this array to retrieve
// existing categories later.
- $categories = $this->catDAO->listCategories(false);
+ $categories = $this->catDAO->listCategories(false) ?: [];
$categories_by_names = [];
foreach ($categories as $category) {
$categories_by_names[$category->name()] = $category;
@@ -180,7 +180,7 @@ class FreshRSS_Import_Service {
if (isset($feed_elt['frss:filtersActionRead'])) {
$feed->_filtersAction(
'read',
- preg_split('/[\n\r]+/', $feed_elt['frss:filtersActionRead'])
+ preg_split('/[\n\r]+/', $feed_elt['frss:filtersActionRead']) ?: []
);
}
diff --git a/app/views/index/reader.phtml b/app/views/index/reader.phtml
index dde501a92..221c92496 100644
--- a/app/views/index/reader.phtml
+++ b/app/views/index/reader.phtml
@@ -53,6 +53,7 @@ $MAX_TAGS_DISPLAYED = FreshRSS_Context::$user_conf->show_tags_max;
<?php
$feed = FreshRSS_CategoryDAO::findFeed($this->categories, $item->feedId()); //We most likely already have the feed object in cache
if ($feed == null) $feed = $item->feed();
+ if ($feed == null) continue;
$favoriteUrl = array('c' => 'entry', 'a' => 'bookmark', 'params' => array('id' => $item->id()));
if ($item->isFavorite()) {
$favoriteUrl['params']['is_favorite'] = 0;
diff --git a/app/views/user/details.phtml b/app/views/user/details.phtml
index d5cfe731c..3387584eb 100644
--- a/app/views/user/details.phtml
+++ b/app/views/user/details.phtml
@@ -28,14 +28,14 @@
<div class="form-group">
<label class="group-name"><?= _t('admin.user.feed_count') ?></label>
<div class="group-controls">
- <?= format_number($this->details['feed_count']) ?>
+ <?= format_number($this->details['feed_count'] ?: 0) ?>
</div>
</div>
<div class="form-group">
<label class="group-name"><?= _t('admin.user.article_count') ?></label>
<div class="group-controls">
- <?= format_number($this->details['article_count']) ?>
+ <?= format_number($this->details['article_count'] ?: 0) ?>
</div>
</div>