aboutsummaryrefslogtreecommitdiff
path: root/app/Models/Entry.php
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/Entry.php
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/Entry.php')
-rw-r--r--app/Models/Entry.php34
1 files changed, 19 insertions, 15 deletions
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);