aboutsummaryrefslogtreecommitdiff
path: root/app/Models
diff options
context:
space:
mode:
authorGravatar Luc SANCHEZ <4697568+ColonelMoutarde@users.noreply.github.com> 2024-06-05 22:04:06 +0200
committerGravatar GitHub <noreply@github.com> 2024-06-05 22:04:06 +0200
commitf99c8d5f54c67e0abc3f3189b4f5e3e4571e114c (patch)
treed7d74a628cd9614dd4093220139b6c073f3a5c54 /app/Models
parent8fc8ac3aefca73a4cd509313a2f1ad73ef7f2e1a (diff)
Modernize code to php7.4 (#6043)
* Modernize code to php7.4 * Modernize code to php7.4 * Modernize code to php7.4 * Modernize code to php7.4 * Modernize code to php7.4 * Modernize code to php7.4 * Modernize code to php7.4 * Modernize code to php7.4 * Modernize code to php7.4 * Modernize code to php7.4 * Modernize code to php7.4 * Modernize code to php7.4 * Modernize code to php7.4 * Consistency --------- Co-authored-by: Luc <sanchezluc+freshrss@gmail.com> Co-authored-by: Alexandre Alapetite <alexandre@alapetite.fr>
Diffstat (limited to 'app/Models')
-rw-r--r--app/Models/Auth.php2
-rw-r--r--app/Models/Entry.php14
-rw-r--r--app/Models/EntryDAOSQLite.php4
-rw-r--r--app/Models/Feed.php14
-rw-r--r--app/Models/FilterActionsTrait.php6
-rw-r--r--app/Models/Search.php4
-rw-r--r--app/Models/Share.php4
-rw-r--r--app/Models/StatsDAO.php10
-rw-r--r--app/Models/TagDAO.php2
9 files changed, 25 insertions, 35 deletions
diff --git a/app/Models/Auth.php b/app/Models/Auth.php
index c66bb5016..ecb8ead2f 100644
--- a/app/Models/Auth.php
+++ b/app/Models/Auth.php
@@ -8,7 +8,7 @@ class FreshRSS_Auth {
/**
* Determines if user is connected.
*/
- public const DEFAULT_COOKIE_DURATION = 7776000;
+ public const DEFAULT_COOKIE_DURATION = 7_776_000;
private static bool $login_ok = false;
diff --git a/app/Models/Entry.php b/app/Models/Entry.php
index 956134c78..2325252f7 100644
--- a/app/Models/Entry.php
+++ b/app/Models/Entry.php
@@ -244,12 +244,12 @@ HTML;
$content .= '<p class="enclosure-content"><img src="' . $elink . '" alt="" title="' . $etitle . '" /></p>';
} elseif ($medium === 'audio' || strpos($mime, 'audio') === 0) {
$content .= '<p class="enclosure-content"><audio preload="none" src="' . $elink
- . ($length == null ? '' : '" data-length="' . intval($length))
+ . ($length == null ? '' : '" data-length="' . (int)$length)
. ($mime == '' ? '' : '" data-type="' . htmlspecialchars($mime, ENT_COMPAT, 'UTF-8'))
. '" controls="controls" title="' . $etitle . '"></audio> <a download="" href="' . $elink . '">💾</a></p>';
} elseif ($medium === 'video' || strpos($mime, 'video') === 0) {
$content .= '<p class="enclosure-content"><video preload="none" src="' . $elink
- . ($length == null ? '' : '" data-length="' . intval($length))
+ . ($length == null ? '' : '" data-length="' . (int)$length)
. ($mime == '' ? '' : '" data-type="' . htmlspecialchars($mime, ENT_COMPAT, 'UTF-8'))
. '" controls="controls" title="' . $etitle . '"></video> <a download="" href="' . $elink . '">💾</a></p>';
} else { //e.g. application, text, unknown
@@ -401,10 +401,10 @@ HTML;
if ($microsecond) {
return $this->date_added;
} else {
- return intval(substr($this->date_added, 0, -6));
+ return (int)substr($this->date_added, 0, -6);
}
} else {
- $date = intval(substr($this->date_added, 0, -6));
+ $date = (int)substr($this->date_added, 0, -6);
return timestamptodate($date);
}
}
@@ -519,7 +519,7 @@ HTML;
}
/** @param int|string $value */
public function _date($value): void {
- $value = intval($value);
+ $value = (int)$value;
$this->date = $value > 1 ? $value : time();
}
@@ -552,7 +552,7 @@ HTML;
/** @param int|string $id */
private function _feedId($id): void {
$this->feed = null;
- $this->feedId = intval($id);
+ $this->feedId = (int)$id;
}
/** @param array<string>|string $value */
@@ -966,7 +966,7 @@ HTML;
(self::enclosureIsImage($enclosure) ? 'image' : ''),
];
if (!empty($enclosure['length'])) {
- $media['length'] = intval($enclosure['length']);
+ $media['length'] = (int)$enclosure['length'];
}
$item['enclosure'][] = $media;
}
diff --git a/app/Models/EntryDAOSQLite.php b/app/Models/EntryDAOSQLite.php
index 91894b8ac..44c248e82 100644
--- a/app/Models/EntryDAOSQLite.php
+++ b/app/Models/EntryDAOSQLite.php
@@ -135,9 +135,7 @@ SQL;
Minz_Log::debug('Calling markReadTag(0) is deprecated!');
}
- $sql = 'UPDATE `_entry` '
- . 'SET is_read = ? '
- . 'WHERE is_read <> ? AND id <= ? AND '
+ $sql = 'UPDATE `_entry` SET is_read = ? WHERE is_read <> ? AND id <= ? AND '
. 'id IN (SELECT et.id_entry FROM `_entrytag` et '
. ($id == 0 ? '' : 'WHERE et.id_tag = ?')
. ')';
diff --git a/app/Models/Feed.php b/app/Models/Feed.php
index 625c3c931..ebe69a84c 100644
--- a/app/Models/Feed.php
+++ b/app/Models/Feed.php
@@ -47,7 +47,7 @@ class FreshRSS_Feed extends Minz_Model {
private string $url = '';
private int $kind = 0;
private int $categoryId = 0;
- private ?FreshRSS_Category $category;
+ private ?FreshRSS_Category $category = null;
private int $nbEntries = -1;
private int $nbNotRead = -1;
private string $name = '';
@@ -291,7 +291,7 @@ class FreshRSS_Feed extends Minz_Model {
/** @param int|string $id */
public function _categoryId($id): void {
$this->category = null;
- $this->categoryId = intval($id);
+ $this->categoryId = (int)$id;
}
public function _name(string $value): void {
@@ -330,7 +330,7 @@ class FreshRSS_Feed extends Minz_Model {
$this->mute = $value;
}
public function _ttl(int $value): void {
- $value = min($value, 100000000);
+ $value = min($value, 100_000_000);
$this->ttl = abs($value);
$this->mute = $value < self::TTL_DEFAULT;
}
@@ -492,7 +492,7 @@ class FreshRSS_Feed extends Minz_Model {
//Tag processing (tag == category)
$categories = $item->get_categories();
- $tags = array();
+ $tags = [];
if (is_array($categories)) {
foreach ($categories as $category) {
$text = html_only_entity_decode($category->get_label());
@@ -550,13 +550,13 @@ class FreshRSS_Feed extends Minz_Model {
$attributeEnclosure['medium'] = $medium;
}
if ($length != '') {
- $attributeEnclosure['length'] = intval($length);
+ $attributeEnclosure['length'] = (int)$length;
}
if ($height != '') {
- $attributeEnclosure['height'] = intval($height);
+ $attributeEnclosure['height'] = (int)$height;
}
if ($width != '') {
- $attributeEnclosure['width'] = intval($width);
+ $attributeEnclosure['width'] = (int)$width;
}
if (!empty($enclosure->get_thumbnails())) {
diff --git a/app/Models/FilterActionsTrait.php b/app/Models/FilterActionsTrait.php
index 57e3d8f12..495dc3eee 100644
--- a/app/Models/FilterActionsTrait.php
+++ b/app/Models/FilterActionsTrait.php
@@ -32,9 +32,9 @@ trait FreshRSS_FilterActionsTrait {
private function _filterActions(?array $filterActions): void {
$this->filterActions = $filterActions;
if ($this->filterActions !== null && !empty($this->filterActions)) {
- $this->_attribute('filters', array_map(static function (?FreshRSS_FilterAction $af) {
- return $af == null ? null : $af->toJSON();
- }, $this->filterActions));
+ $this->_attribute('filters', array_map(
+ static fn(?FreshRSS_FilterAction $af) => $af == null ? null : $af->toJSON(),
+ $this->filterActions));
} else {
$this->_attribute('filters', null);
}
diff --git a/app/Models/Search.php b/app/Models/Search.php
index 00cb408f9..31b3d8d5a 100644
--- a/app/Models/Search.php
+++ b/app/Models/Search.php
@@ -235,9 +235,7 @@ class FreshRSS_Search {
* @return array<string>
*/
private static function removeEmptyValues(?array $anArray): array {
- return empty($anArray) ? [] : array_filter($anArray, static function(string $value) {
- return $value !== '';
- });
+ return empty($anArray) ? [] : array_filter($anArray, static fn(string $value) => $value !== '');
}
/**
diff --git a/app/Models/Share.php b/app/Models/Share.php
index 57177c78c..8d2d70a6a 100644
--- a/app/Models/Share.php
+++ b/app/Models/Share.php
@@ -50,9 +50,7 @@ class FreshRSS_Share {
self::register($share_options);
}
- uasort(self::$list_sharing, static function (FreshRSS_Share $a, FreshRSS_Share $b) {
- return strcasecmp($a->name() ?? '', $b->name() ?? '');
- });
+ uasort(self::$list_sharing, static fn(FreshRSS_Share $a, FreshRSS_Share $b) => strcasecmp($a->name() ?? '', $b->name() ?? ''));
}
/**
diff --git a/app/Models/StatsDAO.php b/app/Models/StatsDAO.php
index 9bdc255e3..3ee481776 100644
--- a/app/Models/StatsDAO.php
+++ b/app/Models/StatsDAO.php
@@ -222,7 +222,7 @@ SQL;
$interval_in_days = $period;
}
- return intval($res[0]['count']) / ($interval_in_days / $period);
+ return (int)$res[0]['count'] / ($interval_in_days / $period);
}
/**
@@ -230,9 +230,7 @@ SQL;
* @return array<int,int>
*/
protected function initStatsArray(int $min, int $max): array {
- return array_map(function () {
- return 0;
- }, array_flip(range($min, $max)));
+ return array_map(fn() => 0, array_flip(range($min, $max)));
}
/**
@@ -369,9 +367,7 @@ SQL;
* @return array<string>
*/
private function convertToTranslatedJson(array $data = []): array {
- $translated = array_map(static function (string $a) {
- return _t('gen.date.' . $a);
- }, $data);
+ $translated = array_map(static fn(string $a) => _t('gen.date.' . $a), $data);
return $translated;
}
diff --git a/app/Models/TagDAO.php b/app/Models/TagDAO.php
index 9730ef20a..7e3f54457 100644
--- a/app/Models/TagDAO.php
+++ b/app/Models/TagDAO.php
@@ -230,7 +230,7 @@ SQL;
if ($id_tag === null) {
$sql .= ' GROUP BY t.id';
} else {
- $sql .= ' WHERE t.id=' . intval($id_tag);
+ $sql .= ' WHERE t.id=' . $id_tag;
}
$res = $this->fetchAssoc($sql);
if ($res == null) {