aboutsummaryrefslogtreecommitdiff
path: root/app/Models
diff options
context:
space:
mode:
authorGravatar Alexandre Alapetite <alexandre@alapetite.fr> 2025-01-10 08:13:09 +0100
committerGravatar GitHub <noreply@github.com> 2025-01-10 08:13:09 +0100
commit5368f38753a3e655ed3d7d7dfc7af2cc22de7980 (patch)
treedecb975aa750660cea965bf61399df2335493b9d /app/Models
parent3280ec617f8081bf0d5349e441ae564a42fdc500 (diff)
Reduce undeeded use of elvis operator ?: (#7204)
Diffstat (limited to 'app/Models')
-rw-r--r--app/Models/CategoryDAO.php3
-rw-r--r--app/Models/Context.php8
-rw-r--r--app/Models/DatabaseDAOSQLite.php5
-rw-r--r--app/Models/Entry.php3
-rw-r--r--app/Models/EntryDAO.php8
-rw-r--r--app/Models/EntryDAOSQLite.php3
-rw-r--r--app/Models/Search.php8
-rw-r--r--app/Models/TagDAO.php40
-rw-r--r--app/Models/View.php2
9 files changed, 39 insertions, 41 deletions
diff --git a/app/Models/CategoryDAO.php b/app/Models/CategoryDAO.php
index a41d23e10..5d191f321 100644
--- a/app/Models/CategoryDAO.php
+++ b/app/Models/CategoryDAO.php
@@ -289,8 +289,7 @@ SQL;
. 'ORDER BY c.name, f.name';
$stm = $this->pdo->prepare($sql);
$values = [ ':priority' => FreshRSS_Feed::PRIORITY_CATEGORY ];
- if ($stm !== false && $stm->execute($values)) {
- $res = $stm->fetchAll(PDO::FETCH_ASSOC) ?: [];
+ if ($stm !== false && $stm->execute($values) && ($res = $stm->fetchAll(PDO::FETCH_ASSOC)) !== false) {
/** @var list<array{c_name:string,c_id:int,c_kind:int,c_last_update:int,c_error:int|bool,c_attributes?:string,
* id?:int,name?:string,url?:string,kind?:int,category?:int,website?:string,priority?:int,error?:int|bool,attributes?:string,cache_nbEntries?:int,cache_nbUnreads?:int,ttl?:int}> $res */
return self::daoToCategoriesPrepopulated($res);
diff --git a/app/Models/Context.php b/app/Models/Context.php
index 0c8161c8b..8bee4630a 100644
--- a/app/Models/Context.php
+++ b/app/Models/Context.php
@@ -177,7 +177,7 @@ final class FreshRSS_Context {
public static function categories(): array {
if (empty(self::$categories)) {
$catDAO = FreshRSS_Factory::createCategoryDao();
- self::$categories = $catDAO->listSortedCategories(true, false);
+ self::$categories = $catDAO->listSortedCategories(prePopulateFeeds: true, details: false);
}
return self::$categories;
}
@@ -191,7 +191,7 @@ final class FreshRSS_Context {
public static function labels(bool $precounts = false): array {
if (empty(self::$tags) || $precounts) {
$tagDAO = FreshRSS_Factory::createTagDao();
- self::$tags = $tagDAO->listTags($precounts) ?: [];
+ self::$tags = $tagDAO->listTags($precounts);
}
return self::$tags;
}
@@ -400,7 +400,7 @@ final class FreshRSS_Context {
if (empty(self::$categories)) {
$catDAO = FreshRSS_Factory::createCategoryDao();
$details = $type === 'f'; // Load additional feed details in the case of feed view
- self::$categories = $catDAO->listCategories(true, $details);
+ self::$categories = $catDAO->listCategories(prePopulateFeeds: true, details: $details);
}
switch ($type) {
@@ -505,7 +505,7 @@ final class FreshRSS_Context {
if (empty(self::$categories)) {
$catDAO = FreshRSS_Factory::createCategoryDao();
- self::$categories = $catDAO->listCategories(true);
+ self::$categories = $catDAO->listCategories(prePopulateFeeds: true);
}
if (FreshRSS_Context::userConf()->onread_jump_next && strlen($get) > 2) {
diff --git a/app/Models/DatabaseDAOSQLite.php b/app/Models/DatabaseDAOSQLite.php
index f59f6c9ae..c425135b5 100644
--- a/app/Models/DatabaseDAOSQLite.php
+++ b/app/Models/DatabaseDAOSQLite.php
@@ -37,10 +37,9 @@ class FreshRSS_DatabaseDAOSQLite extends FreshRSS_DatabaseDAO {
public function getSchema(string $table): array {
$sql = 'PRAGMA table_info(' . $table . ')';
$stm = $this->pdo->query($sql);
- if ($stm !== false) {
- $res = $stm->fetchAll(PDO::FETCH_ASSOC);
+ if ($stm !== false && ($res = $stm->fetchAll(PDO::FETCH_ASSOC)) !== false) {
/** @var list<array{name:string,type:string,notnull:bool,dflt_value:string|int|bool|null}> $res */
- return $this->listDaoToSchema($res ?: []);
+ return $this->listDaoToSchema($res);
}
return [];
}
diff --git a/app/Models/Entry.php b/app/Models/Entry.php
index 0919489fc..f86948122 100644
--- a/app/Models/Entry.php
+++ b/app/Models/Entry.php
@@ -879,9 +879,8 @@ HTML;
if ($nodes != false) {
$filter_xpath = $path_entries_filter === '' ? '' : (new Gt\CssXPath\Translator($path_entries_filter, 'descendant-or-self::'))->asXPath();
foreach ($nodes as $node) {
- if ($filter_xpath !== '') {
+ if ($filter_xpath !== '' && ($filterednodes = $xpath->query($filter_xpath, $node)) !== false) {
// Remove unwanted elements once before sanitizing, for CSS selectors to also match original content
- $filterednodes = $xpath->query($filter_xpath, $node) ?: [];
foreach ($filterednodes as $filterednode) {
if ($filterednode === $node) {
continue 2;
diff --git a/app/Models/EntryDAO.php b/app/Models/EntryDAO.php
index c169e0e24..af229df54 100644
--- a/app/Models/EntryDAO.php
+++ b/app/Models/EntryDAO.php
@@ -1427,9 +1427,9 @@ SQL;
/**
* @param array<string> $guids
- * @return array<string,string>|false
+ * @return array<string,string> guid => hash
*/
- public function listHashForFeedGuids(int $id_feed, array $guids): array|false {
+ public function listHashForFeedGuids(int $id_feed, array $guids): array {
$result = [];
if (count($guids) < 1) {
return $result;
@@ -1437,7 +1437,7 @@ SQL;
// Split a query with too many variables parameters
$guidsChunks = array_chunk($guids, FreshRSS_DatabaseDAO::MAX_VARIABLE_NUMBER);
foreach ($guidsChunks as $guidsChunk) {
- $result += $this->listHashForFeedGuids($id_feed, $guidsChunk) ?: [];
+ $result += $this->listHashForFeedGuids($id_feed, $guidsChunk);
}
return $result;
}
@@ -1457,7 +1457,7 @@ SQL;
$info = $stm === false ? $this->pdo->errorInfo() : $stm->errorInfo();
Minz_Log::error('SQL error ' . __METHOD__ . json_encode($info)
. ' while querying feed ' . $id_feed);
- return false;
+ return [];
}
}
diff --git a/app/Models/EntryDAOSQLite.php b/app/Models/EntryDAOSQLite.php
index e4cb9727e..99e216e53 100644
--- a/app/Models/EntryDAOSQLite.php
+++ b/app/Models/EntryDAOSQLite.php
@@ -57,8 +57,7 @@ class FreshRSS_EntryDAOSQLite extends FreshRSS_EntryDAO {
/** @param array{0:string,1:int,2:string} $errorInfo */
#[\Override]
protected function autoUpdateDb(array $errorInfo): bool {
- if (($tableInfo = $this->pdo->query("PRAGMA table_info('entry')")) !== false) {
- $columns = $tableInfo->fetchAll(PDO::FETCH_COLUMN, 1) ?: [];
+ if (($tableInfo = $this->pdo->query("PRAGMA table_info('entry')")) !== false && ($columns = $tableInfo->fetchAll(PDO::FETCH_COLUMN, 1)) !== false) {
foreach (['attributes'] as $column) {
if (!in_array($column, $columns, true)) {
return $this->addColumn($column);
diff --git a/app/Models/Search.php b/app/Models/Search.php
index 3eb8b422a..5b88b1f3b 100644
--- a/app/Models/Search.php
+++ b/app/Models/Search.php
@@ -506,7 +506,7 @@ class FreshRSS_Search implements \Stringable {
$input = str_replace($matches[0], '', $input);
}
if (preg_match_all('/\\bintitle:(?P<search>[^\s"]*)/', $input, $matches)) {
- $this->intitle = array_merge($this->intitle ?: [], $matches['search']);
+ $this->intitle = array_merge($this->intitle ?? [], $matches['search']);
$input = str_replace($matches[0], '', $input);
}
$this->intitle = self::removeEmptyValues($this->intitle);
@@ -526,7 +526,7 @@ class FreshRSS_Search implements \Stringable {
$input = str_replace($matches[0], '', $input);
}
if (preg_match_all('/(?<=[\\s(]|^)[!-]intitle:(?P<search>[^\s"]*)/', $input, $matches)) {
- $this->not_intitle = array_merge($this->not_intitle ?: [], $matches['search']);
+ $this->not_intitle = array_merge($this->not_intitle ?? [], $matches['search']);
$input = str_replace($matches[0], '', $input);
}
$this->not_intitle = self::removeEmptyValues($this->not_intitle);
@@ -551,7 +551,7 @@ class FreshRSS_Search implements \Stringable {
$input = str_replace($matches[0], '', $input);
}
if (preg_match_all('/\\bauthor:(?P<search>[^\s"]*)/', $input, $matches)) {
- $this->author = array_merge($this->author ?: [], $matches['search']);
+ $this->author = array_merge($this->author ?? [], $matches['search']);
$input = str_replace($matches[0], '', $input);
}
$this->author = self::removeEmptyValues($this->author);
@@ -571,7 +571,7 @@ class FreshRSS_Search implements \Stringable {
$input = str_replace($matches[0], '', $input);
}
if (preg_match_all('/(?<=[\\s(]|^)[!-]author:(?P<search>[^\s"]*)/', $input, $matches)) {
- $this->not_author = array_merge($this->not_author ?: [], $matches['search']);
+ $this->not_author = array_merge($this->not_author ?? [], $matches['search']);
$input = str_replace($matches[0], '', $input);
}
$this->not_author = self::removeEmptyValues($this->not_author);
diff --git a/app/Models/TagDAO.php b/app/Models/TagDAO.php
index 2f12c96d4..c2a653238 100644
--- a/app/Models/TagDAO.php
+++ b/app/Models/TagDAO.php
@@ -182,8 +182,8 @@ SQL;
return $res === null ? null : (current(self::daoToTags($res)) ?: null);
}
- /** @return array<int,FreshRSS_Tag>|false where the key is the label ID */
- public function listTags(bool $precounts = false): array|false {
+ /** @return array<int,FreshRSS_Tag> where the key is the label ID */
+ public function listTags(bool $precounts = false): array {
if ($precounts) {
$sql = <<<'SQL'
SELECT t.id, t.name, count(e.id) AS unreads
@@ -198,13 +198,12 @@ SQL;
}
$stm = $this->pdo->query($sql);
- if ($stm !== false) {
- $res = $stm->fetchAll(PDO::FETCH_ASSOC) ?: [];
+ if ($stm !== false && ($res = $stm->fetchAll(PDO::FETCH_ASSOC)) !== false) {
return self::daoToTags($res);
} else {
$info = $this->pdo->errorInfo();
Minz_Log::error('SQL error ' . __METHOD__ . json_encode($info));
- return false;
+ return [];
}
}
@@ -319,9 +318,9 @@ SQL;
}
/**
- * @return array<int,array{id:int,name:string,checked:bool}>|false
+ * @return list<array{id:int,name:string,checked:bool}>
*/
- public function getTagsForEntry(string $id_entry): array|false {
+ public function getTagsForEntry(string $id_entry): array {
$sql = <<<'SQL'
SELECT t.id, t.name, et.id_entry IS NOT NULL as checked
FROM `_tag` t
@@ -332,24 +331,27 @@ SQL;
$stm = $this->pdo->prepare($sql);
$values = [$id_entry];
- if ($stm !== false && $stm->execute($values)) {
- $lines = $stm->fetchAll(PDO::FETCH_ASSOC);
- for ($i = count($lines) - 1; $i >= 0; $i--) {
- $lines[$i]['id'] = (int)($lines[$i]['id']);
- $lines[$i]['checked'] = !empty($lines[$i]['checked']);
+ if ($stm !== false && $stm->execute($values) && ($lines = $stm->fetchAll(PDO::FETCH_ASSOC)) !== false) {
+ $result = [];
+ foreach ($lines as $line) {
+ $result[] = [
+ 'id' => (int)($line['id']),
+ 'name' => $line['name'],
+ 'checked' => !empty($line['checked']),
+ ];
}
- return $lines;
+ return $result;
}
$info = $stm === false ? $this->pdo->errorInfo() : $stm->errorInfo();
Minz_Log::error('SQL error ' . __METHOD__ . json_encode($info));
- return false;
+ return [];
}
/**
* @param list<FreshRSS_Entry|numeric-string> $entries
- * @return list<array{id_entry:int|numeric-string,id_tag:int,name:string}>|false
+ * @return list<array{id_entry:int|numeric-string,id_tag:int,name:string}>|null
*/
- public function getTagsForEntries(array $entries): array|false {
+ public function getTagsForEntries(array $entries): array|null {
$sql = <<<'SQL'
SELECT et.id_entry, et.id_tag, t.name
FROM `_tag` t
@@ -364,7 +366,7 @@ SQL;
foreach ($idsChunks as $idsChunk) {
$valuesChunk = $this->getTagsForEntries($idsChunk);
if (!is_array($valuesChunk)) {
- return false;
+ return null;
}
$values = array_merge($values, $valuesChunk);
}
@@ -384,7 +386,7 @@ SQL;
}
$info = $stm === false ? $this->pdo->errorInfo() : $stm->errorInfo();
Minz_Log::error('SQL error ' . __METHOD__ . json_encode($info));
- return false;
+ return null;
}
/**
@@ -395,7 +397,7 @@ SQL;
*/
public function getEntryIdsTagNames(array $entries): array {
$result = [];
- foreach ($this->getTagsForEntries($entries) ?: [] as $line) {
+ foreach ($this->getTagsForEntries($entries) ?? [] as $line) {
$entryId = 'e_' . $line['id_entry'];
$tagName = $line['name'];
if (empty($result[$entryId])) {
diff --git a/app/Models/View.php b/app/Models/View.php
index 943c50055..dd616b888 100644
--- a/app/Models/View.php
+++ b/app/Models/View.php
@@ -24,7 +24,7 @@ class FreshRSS_View extends Minz_View {
public int $nbUnreadTags;
/** @var array<int,FreshRSS_Tag> where the key is the label ID */
public array $tags;
- /** @var array<int,array{id:int,name:string,checked:bool}> */
+ /** @var list<array{id:int,name:string,checked:bool}> */
public array $tagsForEntry;
/** @var array<string,array<string>> */
public array $tagsForEntries;