aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Alexandre Alapetite <alexandre@alapetite.fr> 2023-03-22 08:26:39 +0100
committerGravatar GitHub <noreply@github.com> 2023-03-22 08:26:39 +0100
commit1a0616562db5c096dc7ca187f0210b3d57bffebf (patch)
tree4f721c9f06bb601b5ccbf95307f37ba2de0480d7
parent247215ffaa2966919115f283fb67a0096df8dc1c (diff)
Remove FreshRSS_Searchable for better types (#5212)
* Remove FreshRSS_Searchable for better types The interface was not used, and it was preventing more precise types for the different `searchById()` methods, as they each have different input and output types. * Fix type
-rw-r--r--app/Models/CategoryDAO.php5
-rw-r--r--app/Models/EntryDAO.php5
-rw-r--r--app/Models/FeedDAO.php7
-rw-r--r--app/Models/Searchable.php10
-rw-r--r--app/Models/TagDAO.php7
-rw-r--r--p/api/fever.php2
6 files changed, 9 insertions, 27 deletions
diff --git a/app/Models/CategoryDAO.php b/app/Models/CategoryDAO.php
index c855f1495..02845ebe7 100644
--- a/app/Models/CategoryDAO.php
+++ b/app/Models/CategoryDAO.php
@@ -1,6 +1,6 @@
<?php
-class FreshRSS_CategoryDAO extends Minz_ModelPdo implements FreshRSS_Searchable {
+class FreshRSS_CategoryDAO extends Minz_ModelPdo {
const DEFAULTCATEGORYID = 1;
@@ -224,8 +224,7 @@ SQL;
}
}
- /** @return FreshRSS_Category|null */
- public function searchById($id) {
+ public function searchById(int $id): ?FreshRSS_Category {
$sql = 'SELECT * FROM `_category` WHERE id=:id';
$stm = $this->pdo->prepare($sql);
if ($stm &&
diff --git a/app/Models/EntryDAO.php b/app/Models/EntryDAO.php
index aab17d01e..0740f1ac4 100644
--- a/app/Models/EntryDAO.php
+++ b/app/Models/EntryDAO.php
@@ -1,6 +1,6 @@
<?php
-class FreshRSS_EntryDAO extends Minz_ModelPdo implements FreshRSS_Searchable {
+class FreshRSS_EntryDAO extends Minz_ModelPdo {
public static function isCompressed(): bool {
return true;
@@ -732,8 +732,7 @@ SQL;
return isset($res[0]) ? FreshRSS_Entry::fromArray($res[0]) : null;
}
- /** @return FreshRSS_Entry|null */
- public function searchById($id) {
+ public function searchById(string $id): ?FreshRSS_Entry {
$sql = 'SELECT id, guid, title, author, '
. (static::isCompressed() ? 'UNCOMPRESS(content_bin) AS content' : 'content')
. ', link, date, is_read, is_favorite, id_feed, tags, attributes '
diff --git a/app/Models/FeedDAO.php b/app/Models/FeedDAO.php
index 1aae5fee5..1047a218b 100644
--- a/app/Models/FeedDAO.php
+++ b/app/Models/FeedDAO.php
@@ -1,6 +1,6 @@
<?php
-class FreshRSS_FeedDAO extends Minz_ModelPdo implements FreshRSS_Searchable {
+class FreshRSS_FeedDAO extends Minz_ModelPdo {
protected function addColumn(string $name) {
if ($this->pdo->inTransaction()) {
@@ -284,10 +284,7 @@ SQL;
}
}
- /**
- * @return FreshRSS_Feed|null
- */
- public function searchById($id) {
+ public function searchById(int $id): ?FreshRSS_Feed {
$sql = 'SELECT * FROM `_feed` WHERE id=:id';
$stm = $this->pdo->prepare($sql);
$stm->bindParam(':id', $id, PDO::PARAM_INT);
diff --git a/app/Models/Searchable.php b/app/Models/Searchable.php
deleted file mode 100644
index a15a44ed7..000000000
--- a/app/Models/Searchable.php
+++ /dev/null
@@ -1,10 +0,0 @@
-<?php
-
-interface FreshRSS_Searchable {
-
- /**
- * @param int|string $id
- * @return Minz_Model
- */
- public function searchById($id);
-}
diff --git a/app/Models/TagDAO.php b/app/Models/TagDAO.php
index 35123606b..ca927ef38 100644
--- a/app/Models/TagDAO.php
+++ b/app/Models/TagDAO.php
@@ -1,6 +1,6 @@
<?php
-class FreshRSS_TagDAO extends Minz_ModelPdo implements FreshRSS_Searchable {
+class FreshRSS_TagDAO extends Minz_ModelPdo {
public function sqlIgnore(): string {
return 'IGNORE';
@@ -197,10 +197,7 @@ SQL;
}
}
- /**
- * @return FreshRSS_Tag|null
- */
- public function searchById($id) {
+ public function searchById(int $id): ?FreshRSS_Tag {
$sql = 'SELECT * FROM `_tag` WHERE id=?';
$stm = $this->pdo->prepare($sql);
$values = array($id);
diff --git a/p/api/fever.php b/p/api/fever.php
index c83b28da3..1bc7068ab 100644
--- a/p/api/fever.php
+++ b/p/api/fever.php
@@ -474,7 +474,7 @@ final class FeverAPI
$group_ids = explode(',', $_REQUEST['group_ids']);
$feeds = [];
foreach ($group_ids as $id) {
- $category = $categoryDAO->searchById($id); //TODO: Transform to SQL query without loop! Consider FreshRSS_CategoryDAO::listCategories(true)
+ $category = $categoryDAO->searchById((int)$id); //TODO: Transform to SQL query without loop! Consider FreshRSS_CategoryDAO::listCategories(true)
if ($category == null) {
continue;
}