aboutsummaryrefslogtreecommitdiff
path: root/app/Models
diff options
context:
space:
mode:
authorGravatar Alexandre Alapetite <alexandre@alapetite.fr> 2025-01-08 13:26:09 +0100
committerGravatar GitHub <noreply@github.com> 2025-01-08 13:26:09 +0100
commit50adb559823f935582f3ed308b8d4352c5f216ed (patch)
tree74f09efadfcaf28f82505e791e267596f4026053 /app/Models
parentfa701b39f3775ac4250a82fabcec8970b446789b (diff)
Add some missing PHP native types (#7191)
* Add some missing PHP native types Replaces https://github.com/FreshRSS/FreshRSS/pull/7184 * Clean some types
Diffstat (limited to 'app/Models')
-rw-r--r--app/Models/AttributesTrait.php2
-rw-r--r--app/Models/BooleanSearch.php2
-rw-r--r--app/Models/Category.php3
-rw-r--r--app/Models/Entry.php34
-rw-r--r--app/Models/EntryDAO.php2
-rw-r--r--app/Models/EntryDAOSQLite.php2
-rw-r--r--app/Models/Feed.php13
-rw-r--r--app/Models/Tag.php12
-rw-r--r--app/Models/TagDAO.php2
9 files changed, 39 insertions, 33 deletions
diff --git a/app/Models/AttributesTrait.php b/app/Models/AttributesTrait.php
index f30b11b5d..05fcb3c1b 100644
--- a/app/Models/AttributesTrait.php
+++ b/app/Models/AttributesTrait.php
@@ -48,7 +48,7 @@ trait FreshRSS_AttributesTrait {
}
/** @param string|array<string,mixed> $values Values, not HTML-encoded */
- public function _attributes($values): void {
+ public function _attributes(string|array $values): void {
if (is_string($values)) {
$values = json_decode($values, true);
}
diff --git a/app/Models/BooleanSearch.php b/app/Models/BooleanSearch.php
index f7273151e..1832bd419 100644
--- a/app/Models/BooleanSearch.php
+++ b/app/Models/BooleanSearch.php
@@ -412,7 +412,7 @@ class FreshRSS_BooleanSearch implements \Stringable {
}
/** @param FreshRSS_BooleanSearch|FreshRSS_Search $search */
- public function add($search): void {
+ public function add(FreshRSS_BooleanSearch|FreshRSS_Search $search): void {
$this->searches[] = $search;
}
diff --git a/app/Models/Category.php b/app/Models/Category.php
index feaf7b79c..da902d6bd 100644
--- a/app/Models/Category.php
+++ b/app/Models/Category.php
@@ -65,8 +65,7 @@ class FreshRSS_Category extends Minz_Model {
return $this->error;
}
- /** @param bool|int $value */
- public function _error($value): void {
+ public function _error(bool|int $value): void {
$this->error = (bool)$value;
}
public function isDefault(): bool {
diff --git a/app/Models/Entry.php b/app/Models/Entry.php
index c32506319..0919489fc 100644
--- a/app/Models/Entry.php
+++ b/app/Models/Entry.php
@@ -37,6 +37,7 @@ class FreshRSS_Entry extends Minz_Model {
/**
* @param string|array<string> $tags
+ * @param int|numeric-string $pubdate
*/
public function __construct(int $feedId = 0, string $guid = '', string $title = '', string $authors = '', string $content = '',
string $link = '', int|string $pubdate = 0, bool|int|null $is_read = false, bool|int|null $is_favorite = false, $tags = '') {
@@ -59,6 +60,10 @@ class FreshRSS_Entry extends Minz_Model {
$dao['content'] = '';
}
+ if (!is_numeric($dao['date'] ?? null)) {
+ $dao['date'] = 0;
+ }
+
$dao['attributes'] = empty($dao['attributes']) ? [] : json_decode($dao['attributes'], true);
if (!is_array($dao['attributes'])) {
$dao['attributes'] = [];
@@ -487,7 +492,7 @@ HTML;
}
/** @param int|numeric-string $value String is for compatibility with 32-bit platforms */
- public function _id($value): void {
+ public function _id(int|string $value): void {
if (is_int($value)) {
$value = (string)$value;
}
@@ -510,7 +515,7 @@ HTML;
$this->_authors($value);
}
/** @param array<string>|string $value */
- public function _authors($value): void {
+ public function _authors(array|string $value): void {
$this->hash = '';
if (!is_array($value)) {
if (str_contains($value, ';')) {
@@ -531,8 +536,8 @@ HTML;
$this->hash = '';
$this->link = trim($value);
}
- /** @param int|string $value */
- public function _date($value): void {
+ /** @param int|numeric-string $value */
+ public function _date(int|string $value): void {
$value = (int)$value;
$this->date = $value > 1 ? $value : time();
}
@@ -541,20 +546,20 @@ HTML;
$this->lastSeen = $value > 0 ? $value : 0;
}
- /** @param int|string $value */
- public function _dateAdded($value, bool $microsecond = false): void {
+ /** @param int|numeric-string $value */
+ public function _dateAdded(int|string $value, bool $microsecond = false): void {
if ($microsecond) {
$this->date_added = (string)($value);
} else {
$this->date_added = $value . '000000';
}
}
- /** @param bool|int|null $value */
- public function _isRead($value): void {
+
+ public function _isRead(bool|int|null $value): void {
$this->is_read = $value === null ? null : (bool)$value;
}
- /** @param bool|int|null $value */
- public function _isFavorite($value): void {
+
+ public function _isFavorite(bool|int|null $value): void {
$this->is_favorite = $value === null ? null : (bool)$value;
}
@@ -563,14 +568,13 @@ HTML;
$this->feedId = $this->feed == null ? 0 : $this->feed->id();
}
- /** @param int|string $id */
- private function _feedId($id): void {
+ private function _feedId(int $id): void {
$this->feed = null;
- $this->feedId = (int)$id;
+ $this->feedId = $id;
}
/** @param array<string>|string $value */
- public function _tags($value): void {
+ public function _tags(array|string $value): void {
$this->hash = '';
if (!is_array($value)) {
$value = preg_split('/\s*[#,]\s*/', $value, -1, PREG_SPLIT_NO_EMPTY) ?: [];
@@ -1052,7 +1056,7 @@ HTML;
* @param numeric-string|int $dec Decimal number
* @return string 64-bit hexa http://code.google.com/p/google-reader-api/wiki/ItemId
*/
- private static function dec2hex($dec): string {
+ private static function dec2hex(string|int $dec): string {
return PHP_INT_SIZE < 8 ? // 32-bit ?
str_pad(gmp_strval(gmp_init($dec, 10), 16), 16, '0', STR_PAD_LEFT) :
str_pad(dechex((int)($dec)), 16, '0', STR_PAD_LEFT);
diff --git a/app/Models/EntryDAO.php b/app/Models/EntryDAO.php
index 6075b0759..c169e0e24 100644
--- a/app/Models/EntryDAO.php
+++ b/app/Models/EntryDAO.php
@@ -344,7 +344,7 @@ SQL;
*
* @param numeric-string|list<numeric-string> $ids
*/
- public function markFavorite($ids, bool $is_favorite = true): int|false {
+ public function markFavorite(string|array $ids, bool $is_favorite = true): int|false {
if (!is_array($ids)) {
$ids = [$ids];
}
diff --git a/app/Models/EntryDAOSQLite.php b/app/Models/EntryDAOSQLite.php
index 6951afb27..e4cb9727e 100644
--- a/app/Models/EntryDAOSQLite.php
+++ b/app/Models/EntryDAOSQLite.php
@@ -153,7 +153,7 @@ SQL;
* @return int|false affected rows
*/
#[\Override]
- public function markReadTag($id = 0, string $idMax = '0', ?FreshRSS_BooleanSearch $filters = null, int $state = 0, bool $is_read = true): int|false {
+ public function markReadTag(int $id = 0, string $idMax = '0', ?FreshRSS_BooleanSearch $filters = null, int $state = 0, bool $is_read = true): int|false {
FreshRSS_UserDAO::touch();
if ($idMax == 0) {
$idMax = time() . '000000';
diff --git a/app/Models/Feed.php b/app/Models/Feed.php
index 645dbcf3c..dd508299d 100644
--- a/app/Models/Feed.php
+++ b/app/Models/Feed.php
@@ -287,8 +287,8 @@ class FreshRSS_Feed extends Minz_Model {
$this->categoryId = $this->category == null ? 0 : $this->category->id();
}
- /** @param int|string $id */
- public function _categoryId($id): void {
+ /** @param int|numeric-string $id */
+ public function _categoryId(int|string $id): void {
$this->category = null;
$this->categoryId = (int)$id;
}
@@ -321,8 +321,8 @@ class FreshRSS_Feed extends Minz_Model {
public function _httpAuth(string $value): void {
$this->httpAuth = $value;
}
- /** @param bool|int $value */
- public function _error($value): void {
+
+ public function _error(bool|int $value): void {
$this->error = (bool)$value;
}
public function _mute(bool $value): void {
@@ -350,7 +350,7 @@ class FreshRSS_Feed extends Minz_Model {
/**
* @throws Minz_FileNotExistException
*/
- if (CACHE_PATH == '') {
+ if (trim(CACHE_PATH) === '') {
throw new Minz_FileNotExistException(
'CACHE_PATH',
Minz_Exception::ERROR
@@ -549,6 +549,9 @@ class FreshRSS_Feed extends Minz_Model {
$authors = $item->get_authors();
$link = $item->get_permalink();
$date = $item->get_date('U');
+ if (!is_numeric($date)) {
+ $date = 0;
+ }
//Tag processing (tag == category)
$categories = $item->get_categories();
diff --git a/app/Models/Tag.php b/app/Models/Tag.php
index 9a3baffcd..dc74dcabd 100644
--- a/app/Models/Tag.php
+++ b/app/Models/Tag.php
@@ -17,8 +17,8 @@ class FreshRSS_Tag extends Minz_Model {
return $this->id;
}
- public function _id(int|string $value): void {
- $this->id = (int)$value;
+ public function _id(int $value): void {
+ $this->id = $value;
}
public function name(): string {
@@ -37,8 +37,8 @@ class FreshRSS_Tag extends Minz_Model {
return $this->nbEntries;
}
- public function _nbEntries(int|string $value): void {
- $this->nbEntries = (int)$value;
+ public function _nbEntries(int $value): void {
+ $this->nbEntries = $value;
}
public function nbUnread(): int {
@@ -49,7 +49,7 @@ class FreshRSS_Tag extends Minz_Model {
return $this->nbUnread;
}
- public function _nbUnread(int|string $value): void {
- $this->nbUnread = (int)$value;
+ public function _nbUnread(int $value): void {
+ $this->nbUnread = $value;
}
}
diff --git a/app/Models/TagDAO.php b/app/Models/TagDAO.php
index 16b068a51..2f12c96d4 100644
--- a/app/Models/TagDAO.php
+++ b/app/Models/TagDAO.php
@@ -407,7 +407,7 @@ SQL;
}
/**
- * @param iterable<array{id:int,name:string,attributes?:string}> $listDAO
+ * @param iterable<array{id:int,name:string,attributes?:string,unreads?:int}> $listDAO
* @return array<int,FreshRSS_Tag> where the key is the label ID
*/
private static function daoToTags(iterable $listDAO): array {