aboutsummaryrefslogtreecommitdiff
path: root/app/Models
diff options
context:
space:
mode:
authorGravatar Alexandre Alapetite <alexandre@alapetite.fr> 2023-05-11 13:02:04 +0200
committerGravatar GitHub <noreply@github.com> 2023-05-11 13:02:04 +0200
commit6e2f2f1c1e98ecd86aa89c6547beb742d7385d18 (patch)
tree7ba9f5aebb01d12045b9067a86b5060ba13dca18 /app/Models
parentfe7d9bbcd68660a59b813346c236b61b25a51c80 (diff)
A few additional PHPStan rules (#5388)
A subset of https://github.com/phpstan/phpstan-strict-rules
Diffstat (limited to 'app/Models')
-rw-r--r--app/Models/ActionController.php1
-rw-r--r--app/Models/BooleanSearch.php12
-rw-r--r--app/Models/CategoryDAO.php6
-rw-r--r--app/Models/CategoryDAOSQLite.php2
-rw-r--r--app/Models/Context.php8
-rw-r--r--app/Models/DatabaseDAO.php4
-rw-r--r--app/Models/DatabaseDAOSQLite.php10
-rw-r--r--app/Models/Entry.php18
-rw-r--r--app/Models/EntryDAOSQLite.php2
-rw-r--r--app/Models/Feed.php8
-rw-r--r--app/Models/FeedDAO.php6
-rw-r--r--app/Models/FeedDAOSQLite.php2
-rw-r--r--app/Models/FormAuth.php2
-rw-r--r--app/Models/Search.php4
-rw-r--r--app/Models/Share.php6
-rw-r--r--app/Models/StatsDAO.php2
-rw-r--r--app/Models/TagDAO.php2
17 files changed, 46 insertions, 49 deletions
diff --git a/app/Models/ActionController.php b/app/Models/ActionController.php
index 2e0aaa730..69548feb3 100644
--- a/app/Models/ActionController.php
+++ b/app/Models/ActionController.php
@@ -4,6 +4,7 @@ class FreshRSS_ActionController extends Minz_ActionController {
/**
* @var FreshRSS_View
+ * @phpstan-ignore-next-line
*/
protected $view;
}
diff --git a/app/Models/BooleanSearch.php b/app/Models/BooleanSearch.php
index ea03165d5..d4d8a42ab 100644
--- a/app/Models/BooleanSearch.php
+++ b/app/Models/BooleanSearch.php
@@ -43,12 +43,12 @@ class FreshRSS_BooleanSearch {
*/
private function parseUserQueryNames(string $input): string {
$all_matches = [];
- if (preg_match_all('/\bsearch:(?P<delim>[\'"])(?P<search>.*)(?P=delim)/U', $input, $matches)) {
- $all_matches[] = $matches;
+ if (preg_match_all('/\bsearch:(?P<delim>[\'"])(?P<search>.*)(?P=delim)/U', $input, $matchesFound)) {
+ $all_matches[] = $matchesFound;
}
- if (preg_match_all('/\bsearch:(?P<search>[^\s"]*)/', $input, $matches)) {
- $all_matches[] = $matches;
+ if (preg_match_all('/\bsearch:(?P<search>[^\s"]*)/', $input, $matchesFound)) {
+ $all_matches[] = $matchesFound;
}
if (!empty($all_matches)) {
@@ -82,8 +82,8 @@ class FreshRSS_BooleanSearch {
private function parseUserQueryIds(string $input): string {
$all_matches = [];
- if (preg_match_all('/\bS:(?P<search>\d+)/', $input, $matches)) {
- $all_matches[] = $matches;
+ if (preg_match_all('/\bS:(?P<search>\d+)/', $input, $matchesFound)) {
+ $all_matches[] = $matchesFound;
}
if (!empty($all_matches)) {
diff --git a/app/Models/CategoryDAO.php b/app/Models/CategoryDAO.php
index e89ceb773..ccfd5c08a 100644
--- a/app/Models/CategoryDAO.php
+++ b/app/Models/CategoryDAO.php
@@ -430,13 +430,13 @@ SQL;
$list = [];
$previousLine = [];
$feedsDao = [];
- $feedDao = FreshRSS_Factory::createFeedDAO();
+ $feedDao = FreshRSS_Factory::createFeedDao();
foreach ($listDAO as $line) {
if (!empty($previousLine['c_id']) && $line['c_id'] !== $previousLine['c_id']) {
// End of the current category, we add it to the $list
$cat = new FreshRSS_Category(
$previousLine['c_name'],
- $feedDao->daoToFeed($feedsDao, $previousLine['c_id'])
+ $feedDao::daoToFeed($feedsDao, $previousLine['c_id'])
);
$cat->_id($previousLine['c_id']);
$cat->_kind($previousLine['c_kind']);
@@ -454,7 +454,7 @@ SQL;
if ($previousLine != null) {
$cat = new FreshRSS_Category(
$previousLine['c_name'],
- $feedDao->daoToFeed($feedsDao, $previousLine['c_id'])
+ $feedDao::daoToFeed($feedsDao, $previousLine['c_id'])
);
$cat->_id($previousLine['c_id']);
$cat->_kind($previousLine['c_kind']);
diff --git a/app/Models/CategoryDAOSQLite.php b/app/Models/CategoryDAOSQLite.php
index 870106f20..c076d25f1 100644
--- a/app/Models/CategoryDAOSQLite.php
+++ b/app/Models/CategoryDAOSQLite.php
@@ -7,7 +7,7 @@ class FreshRSS_CategoryDAOSQLite extends FreshRSS_CategoryDAO {
if ($tableInfo = $this->pdo->query("PRAGMA table_info('category')")) {
$columns = $tableInfo->fetchAll(PDO::FETCH_COLUMN, 1);
foreach (['kind', 'lastUpdate', 'error', 'attributes'] as $column) {
- if (!in_array($column, $columns)) {
+ if (!in_array($column, $columns, true)) {
return $this->addColumn($column);
}
}
diff --git a/app/Models/Context.php b/app/Models/Context.php
index ce29ebd5c..c10119d7d 100644
--- a/app/Models/Context.php
+++ b/app/Models/Context.php
@@ -251,14 +251,14 @@ final class FreshRSS_Context {
* Return the current get as a string or an array.
*
* If $array is true, the first item of the returned value is 'f' or 'c' or 't' and the second is the id.
- * @phpstan-return ($asArray is true ? array{'c'|'f'|'t',bool|int} : string)
+ * @phpstan-return ($asArray is true ? array{'a'|'c'|'f'|'s'|'t'|'T',bool|int} : string)
* @return string|array{string,bool|int}
*/
public static function currentGet(bool $asArray = false) {
if (self::$current_get['all']) {
- return 'a';
+ return $asArray ? ['a', true] : 'a';
} elseif (self::$current_get['starred']) {
- return 's';
+ return $asArray ? ['s', true] : 's';
} elseif (self::$current_get['feed']) {
if ($asArray) {
return array('f', self::$current_get['feed']);
@@ -278,7 +278,7 @@ final class FreshRSS_Context {
return 't_' . self::$current_get['tag'];
}
} elseif (self::$current_get['tags']) {
- return 'T';
+ return $asArray ? ['T', true] : 'T';
}
return '';
}
diff --git a/app/Models/DatabaseDAO.php b/app/Models/DatabaseDAO.php
index 384e59b16..edbfd72cc 100644
--- a/app/Models/DatabaseDAO.php
+++ b/app/Models/DatabaseDAO.php
@@ -83,7 +83,7 @@ class FreshRSS_DatabaseDAO extends Minz_ModelPdo {
$ok = count($columns) === count($schema);
foreach ($columns as $c) {
- $ok &= in_array($c['name'], $schema);
+ $ok &= in_array($c['name'], $schema, true);
}
return (bool)$ok;
@@ -131,7 +131,7 @@ class FreshRSS_DatabaseDAO extends Minz_ModelPdo {
/**
* @param array<string,string|int|bool|null> $dao
- * @return array<string,string|int|bool|null>
+ * @return array{'name':string,'type':string,'notnull':bool,'default':mixed}
*/
public function daoToSchema(array $dao): array {
return [
diff --git a/app/Models/DatabaseDAOSQLite.php b/app/Models/DatabaseDAOSQLite.php
index 8bd8d60ed..5168f5e19 100644
--- a/app/Models/DatabaseDAOSQLite.php
+++ b/app/Models/DatabaseDAOSQLite.php
@@ -50,14 +50,14 @@ class FreshRSS_DatabaseDAOSQLite extends FreshRSS_DatabaseDAO {
}
/**
- * @param array<string,string> $dao
- * @return array<string,string|bool>
+ * @param array<string,string|int|bool|null> $dao
+ * @return array{'name':string,'type':string,'notnull':bool,'default':mixed}
*/
public function daoToSchema(array $dao): array {
return [
- 'name' => $dao['name'],
- 'type' => strtolower($dao['type']),
- 'notnull' => $dao['notnull'] === '1' ? true : false,
+ 'name' => (string)$dao['name'],
+ 'type' => strtolower((string)$dao['type']),
+ 'notnull' => $dao['notnull'] == '1' ? true : false,
'default' => $dao['dflt_value'],
];
}
diff --git a/app/Models/Entry.php b/app/Models/Entry.php
index b0beaaa99..2b0216bbe 100644
--- a/app/Models/Entry.php
+++ b/app/Models/Entry.php
@@ -156,9 +156,9 @@ class FreshRSS_Entry extends Minz_Model {
$content = $this->content;
- $thumbnail = $this->attributes('thumbnail');
- if (!empty($thumbnail['url'])) {
- $elink = $thumbnail['url'];
+ $thumbnailAttribute = $this->attributes('thumbnail');
+ if (!empty($thumbnailAttribute['url'])) {
+ $elink = $thumbnailAttribute['url'];
if ($allowDuplicateEnclosures || !self::containsLink($content, $elink)) {
$content .= <<<HTML
<figure class="enclosure">
@@ -243,7 +243,7 @@ HTML;
if ($searchEnclosures || $searchBodyImages) {
$dom = new DOMDocument();
$dom->loadHTML('<?xml version="1.0" encoding="UTF-8" ?>' . $this->content, LIBXML_NONET | LIBXML_NOERROR | LIBXML_NOWARNING);
- $xpath = new DOMXpath($dom);
+ $xpath = new DOMXPath($dom);
}
if ($searchEnclosures) {
// Legacy code for database entries < FreshRSS 1.20.1
@@ -522,10 +522,10 @@ HTML;
// Searches are combined by OR and are not recursive
$ok = true;
if ($filter->getEntryIds()) {
- $ok &= in_array($this->id, $filter->getEntryIds());
+ $ok &= in_array($this->id, $filter->getEntryIds(), true);
}
if ($ok && $filter->getNotEntryIds()) {
- $ok &= !in_array($this->id, $filter->getNotEntryIds());
+ $ok &= !in_array($this->id, $filter->getNotEntryIds(), true);
}
if ($ok && $filter->getMinDate()) {
$ok &= strnatcmp($this->id, $filter->getMinDate() . '000000') >= 0;
@@ -552,10 +552,10 @@ HTML;
$ok &= $this->date > $filter->getNotMaxPubdate();
}
if ($ok && $filter->getFeedIds()) {
- $ok &= in_array($this->feedId, $filter->getFeedIds());
+ $ok &= in_array($this->feedId, $filter->getFeedIds(), true);
}
if ($ok && $filter->getNotFeedIds()) {
- $ok &= !in_array($this->feedId, $filter->getFeedIds());
+ $ok &= !in_array($this->feedId, $filter->getFeedIds(), true);
}
if ($ok && $filter->getAuthor()) {
foreach ($filter->getAuthor() as $author) {
@@ -719,7 +719,7 @@ HTML;
$filterednode->parentNode->removeChild($filterednode);
}
}
- $content .= $doc->saveHtml($node) . "\n";
+ $content .= $doc->saveHTML($node) . "\n";
}
}
$html = trim(sanitizeHTML($content, $base));
diff --git a/app/Models/EntryDAOSQLite.php b/app/Models/EntryDAOSQLite.php
index bcd139f5f..58a61828b 100644
--- a/app/Models/EntryDAOSQLite.php
+++ b/app/Models/EntryDAOSQLite.php
@@ -27,7 +27,7 @@ class FreshRSS_EntryDAOSQLite extends FreshRSS_EntryDAO {
if ($tableInfo = $this->pdo->query("PRAGMA table_info('entry')")) {
$columns = $tableInfo->fetchAll(PDO::FETCH_COLUMN, 1) ?: [];
foreach (['attributes'] as $column) {
- if (!in_array($column, $columns)) {
+ if (!in_array($column, $columns, true)) {
return $this->addColumn($column);
}
}
diff --git a/app/Models/Feed.php b/app/Models/Feed.php
index f833b2834..b418d2641 100644
--- a/app/Models/Feed.php
+++ b/app/Models/Feed.php
@@ -504,7 +504,7 @@ class FreshRSS_Feed extends Minz_Model {
$text = html_only_entity_decode($category->get_label());
//Some feeds use a single category with comma-separated tags
$labels = explode(',', $text);
- if (is_array($labels)) {
+ if (!empty($labels)) {
foreach ($labels as $label) {
$tags[] = trim($label);
}
@@ -892,7 +892,7 @@ class FreshRSS_Feed extends Minz_Model {
*/
public function _filtersAction(string $action, array $filters): void {
$action = trim($action);
- if ($action == '' || !is_array($filters)) {
+ if ($action == '') {
return;
}
$filters = array_unique(array_map('trim', $filters));
@@ -969,8 +969,8 @@ class FreshRSS_Feed extends Minz_Model {
$hubFilename = PSHB_PATH . '/feeds/' . sha1($url) . '/!hub.json';
$hubFile = @file_get_contents($hubFilename);
$hubJson = $hubFile ? json_decode($hubFile, true) : array();
- if (!isset($hubJson['error']) || $hubJson['error'] !== (bool)$error) {
- $hubJson['error'] = (bool)$error;
+ if (!isset($hubJson['error']) || $hubJson['error'] !== $error) {
+ $hubJson['error'] = $error;
file_put_contents($hubFilename, json_encode($hubJson));
Minz_Log::warning('Set error to ' . ($error ? 1 : 0) . ' for ' . $url, PSHB_LOG);
}
diff --git a/app/Models/FeedDAO.php b/app/Models/FeedDAO.php
index 12597b46c..67543b597 100644
--- a/app/Models/FeedDAO.php
+++ b/app/Models/FeedDAO.php
@@ -585,10 +585,6 @@ SQL;
public static function daoToFeed(array $listDAO, ?int $catID = null): array {
$list = array();
- if (!is_array($listDAO)) {
- $listDAO = array($listDAO);
- }
-
foreach ($listDAO as $key => $dao) {
if (!isset($dao['name'])) {
continue;
@@ -611,7 +607,7 @@ SQL;
$myFeed->_lastUpdate($dao['lastUpdate'] ?? 0);
$myFeed->_priority($dao['priority'] ?? 10);
$myFeed->_pathEntries($dao['pathEntries'] ?? '');
- $myFeed->_httpAuth(base64_decode($dao['httpAuth'] ?? ''));
+ $myFeed->_httpAuth(base64_decode($dao['httpAuth'] ?? '', true) ?: '');
$myFeed->_error($dao['error'] ?? 0);
$myFeed->_ttl($dao['ttl'] ?? FreshRSS_Feed::TTL_DEFAULT);
$myFeed->_attributes('', $dao['attributes'] ?? '');
diff --git a/app/Models/FeedDAOSQLite.php b/app/Models/FeedDAOSQLite.php
index 08a352d5f..441a7d636 100644
--- a/app/Models/FeedDAOSQLite.php
+++ b/app/Models/FeedDAOSQLite.php
@@ -7,7 +7,7 @@ class FreshRSS_FeedDAOSQLite extends FreshRSS_FeedDAO {
if ($tableInfo = $this->pdo->query("PRAGMA table_info('feed')")) {
$columns = $tableInfo->fetchAll(PDO::FETCH_COLUMN, 1);
foreach (['attributes', 'kind'] as $column) {
- if (!in_array($column, $columns)) {
+ if (!in_array($column, $columns, true)) {
return $this->addColumn($column);
}
}
diff --git a/app/Models/FormAuth.php b/app/Models/FormAuth.php
index 476daba53..52c75d73d 100644
--- a/app/Models/FormAuth.php
+++ b/app/Models/FormAuth.php
@@ -21,7 +21,7 @@ class FreshRSS_FormAuth {
}
$token_file = DATA_PATH . '/tokens/' . $token . '.txt';
- $mtime = @filemtime($token_file);
+ $mtime = @filemtime($token_file) ?: 0;
$limits = FreshRSS_Context::$system_conf->limits;
$cookie_duration = empty($limits['cookie_duration']) ? FreshRSS_Auth::DEFAULT_COOKIE_DURATION : $limits['cookie_duration'];
if ($mtime + $cookie_duration < time()) {
diff --git a/app/Models/Search.php b/app/Models/Search.php
index d165b05f0..d2ba23eda 100644
--- a/app/Models/Search.php
+++ b/app/Models/Search.php
@@ -142,7 +142,7 @@ class FreshRSS_Search {
return $this->label_ids;
}
/** @return array<int>|'*'|null */
- public function getNotlabelIds() {
+ public function getNotLabelIds() {
return $this->not_label_ids;
}
/** @return array<string>|null */
@@ -150,7 +150,7 @@ class FreshRSS_Search {
return $this->label_names;
}
/** @return array<string>|null */
- public function getNotlabelNames(): ?array {
+ public function getNotLabelNames(): ?array {
return $this->not_label_names;
}
diff --git a/app/Models/Share.php b/app/Models/Share.php
index b01d285f3..a0bae22b3 100644
--- a/app/Models/Share.php
+++ b/app/Models/Share.php
@@ -137,11 +137,11 @@ class FreshRSS_Share {
$this->isDeprecated = $isDeprecated;
$this->transforms = $transforms;
- if (!in_array($form_type, array('simple', 'advanced'))) {
+ if (!in_array($form_type, ['simple', 'advanced'], true)) {
$form_type = 'simple';
}
$this->form_type = $form_type;
- if (!in_array($method, array('GET', 'POST'))) {
+ if (!in_array($method, ['GET', 'POST'], true)) {
$method = 'GET';
}
$this->method = $method;
@@ -304,7 +304,7 @@ class FreshRSS_Share {
* @return string the transformed data.
*/
private static function transform(string $data, array $transform): string {
- if (!is_array($transform) || empty($transform)) {
+ if (empty($transform)) {
return $data;
}
diff --git a/app/Models/StatsDAO.php b/app/Models/StatsDAO.php
index fb21407a5..53219843e 100644
--- a/app/Models/StatsDAO.php
+++ b/app/Models/StatsDAO.php
@@ -58,7 +58,7 @@ SQL;
*/
public function calculateEntryCount(): array {
$count = $this->initEntryCountArray();
- $midnight = mktime(0, 0, 0);
+ $midnight = mktime(0, 0, 0) ?: 0;
$oldest = $midnight - (self::ENTRY_COUNT_PERIOD * 86400);
// Get stats per day for the last 30 days
diff --git a/app/Models/TagDAO.php b/app/Models/TagDAO.php
index 32f67f0ab..7888caca8 100644
--- a/app/Models/TagDAO.php
+++ b/app/Models/TagDAO.php
@@ -378,7 +378,7 @@ INNER JOIN `_entrytag` et ON et.id_tag = t.id
SQL;
$values = array();
- if (is_array($entries) && count($entries) > 0) {
+ if (count($entries) > 0) {
if (count($entries) > FreshRSS_DatabaseDAO::MAX_VARIABLE_NUMBER) {
// Split a query with too many variables parameters
$idsChunks = array_chunk($entries, FreshRSS_DatabaseDAO::MAX_VARIABLE_NUMBER);