summaryrefslogtreecommitdiff
path: root/classes/rpc.php
diff options
context:
space:
mode:
authorAndrew Dolgov <[email protected]>2021-11-18 07:32:28 +0300
committerAndrew Dolgov <[email protected]>2021-11-18 07:32:28 +0300
commit63ec5a89657bb7f9650582b96e0bb255a0889b48 (patch)
tree074b61eedd7304ba1d8d7deec01d26973ef8e6b8 /classes/rpc.php
parent3a3fde1a2e0beac6d179c6449eaad726100710d7 (diff)
parent2d830c6281c19a7ee29cd379f5aedc82deef3775 (diff)
Merge branch 'wip-phpstan-level6'
Diffstat (limited to 'classes/rpc.php')
-rwxr-xr-xclasses/rpc.php88
1 files changed, 55 insertions, 33 deletions
diff --git a/classes/rpc.php b/classes/rpc.php
index 0432ed2d3..75d008b8b 100755
--- a/classes/rpc.php
+++ b/classes/rpc.php
@@ -1,13 +1,16 @@
<?php
class RPC extends Handler_Protected {
- /*function csrf_ignore($method) {
+ /*function csrf_ignore(string $method): bool {
$csrf_ignored = array("completelabels");
return array_search($method, $csrf_ignored) !== false;
}*/
- private function _translations_as_array() {
+ /**
+ * @return array<string, string>
+ */
+ private function _translations_as_array(): array {
global $text_domains;
@@ -37,7 +40,7 @@ class RPC extends Handler_Protected {
}
- function togglepref() {
+ function togglepref(): void {
$key = clean($_REQUEST["key"]);
set_pref($key, !get_pref($key));
$value = get_pref($key);
@@ -45,7 +48,7 @@ class RPC extends Handler_Protected {
print json_encode(array("param" =>$key, "value" => $value));
}
- function setpref() {
+ function setpref(): void {
// set_pref escapes input, so no need to double escape it here
$key = clean($_REQUEST['key']);
$value = $_REQUEST['value'];
@@ -55,7 +58,7 @@ class RPC extends Handler_Protected {
print json_encode(array("param" =>$key, "value" => $value));
}
- function mark() {
+ function mark(): void {
$mark = clean($_REQUEST["mark"]);
$id = clean($_REQUEST["id"]);
@@ -68,7 +71,7 @@ class RPC extends Handler_Protected {
print json_encode(array("message" => "UPDATE_COUNTERS"));
}
- function delete() {
+ function delete(): void {
$ids = explode(",", clean($_REQUEST["ids"]));
$ids_qmarks = arr_qmarks($ids);
@@ -81,7 +84,7 @@ class RPC extends Handler_Protected {
print json_encode(array("message" => "UPDATE_COUNTERS"));
}
- function publ() {
+ function publ(): void {
$pub = clean($_REQUEST["pub"]);
$id = clean($_REQUEST["id"]);
@@ -94,7 +97,7 @@ class RPC extends Handler_Protected {
print json_encode(array("message" => "UPDATE_COUNTERS"));
}
- function getRuntimeInfo() {
+ function getRuntimeInfo(): void {
$reply = [
'runtime-info' => $this->_make_runtime_info()
];
@@ -102,7 +105,7 @@ class RPC extends Handler_Protected {
print json_encode($reply);
}
- function getAllCounters() {
+ function getAllCounters(): void {
@$seq = (int) $_REQUEST['seq'];
$feed_id_count = (int)$_REQUEST["feed_id_count"];
@@ -133,7 +136,7 @@ class RPC extends Handler_Protected {
}
/* GET["cmode"] = 0 - mark as read, 1 - as unread, 2 - toggle */
- function catchupSelected() {
+ function catchupSelected(): void {
$ids = array_map("intval", clean($_REQUEST["ids"] ?? []));
$cmode = (int)clean($_REQUEST["cmode"]);
@@ -145,7 +148,7 @@ class RPC extends Handler_Protected {
"feeds" => Article::_feeds_of($ids)]);
}
- function markSelected() {
+ function markSelected(): void {
$ids = array_map("intval", clean($_REQUEST["ids"] ?? []));
$cmode = (int)clean($_REQUEST["cmode"]);
@@ -157,7 +160,7 @@ class RPC extends Handler_Protected {
"feeds" => Article::_feeds_of($ids)]);
}
- function publishSelected() {
+ function publishSelected(): void {
$ids = array_map("intval", clean($_REQUEST["ids"] ?? []));
$cmode = (int)clean($_REQUEST["cmode"]);
@@ -169,7 +172,7 @@ class RPC extends Handler_Protected {
"feeds" => Article::_feeds_of($ids)]);
}
- function sanityCheck() {
+ function sanityCheck(): void {
$_SESSION["hasSandbox"] = clean($_REQUEST["hasSandbox"]) === "true";
$_SESSION["clientTzOffset"] = clean($_REQUEST["clientTzOffset"]);
@@ -220,14 +223,14 @@ class RPC extends Handler_Protected {
print "</ul>";
}*/
- function catchupFeed() {
+ function catchupFeed(): void {
$feed_id = clean($_REQUEST['feed_id']);
$is_cat = clean($_REQUEST['is_cat']) == "true";
$mode = clean($_REQUEST['mode'] ?? '');
$search_query = clean($_REQUEST['search_query']);
$search_lang = clean($_REQUEST['search_lang']);
- Feeds::_catchup($feed_id, $is_cat, false, $mode, [$search_query, $search_lang]);
+ Feeds::_catchup($feed_id, $is_cat, null, $mode, [$search_query, $search_lang]);
// return counters here synchronously so that frontend can figure out next unread feed properly
print json_encode(['counters' => Counters::get_all()]);
@@ -235,7 +238,7 @@ class RPC extends Handler_Protected {
//print json_encode(array("message" => "UPDATE_COUNTERS"));
}
- function setWidescreen() {
+ function setWidescreen(): void {
$wide = (int) clean($_REQUEST["wide"]);
set_pref(Prefs::WIDESCREEN_MODE, $wide);
@@ -243,7 +246,7 @@ class RPC extends Handler_Protected {
print json_encode(["wide" => $wide]);
}
- static function updaterandomfeed_real() {
+ static function updaterandomfeed_real(): void {
$default_interval = (int) Prefs::get_default(Prefs::DEFAULT_UPDATE_INTERVAL);
@@ -336,19 +339,22 @@ class RPC extends Handler_Protected {
}
- function updaterandomfeed() {
+ function updaterandomfeed(): void {
self::updaterandomfeed_real();
}
- private function markArticlesById($ids, $cmode) {
+ /**
+ * @param array<int, int> $ids
+ */
+ private function markArticlesById(array $ids, int $cmode): void {
$ids_qmarks = arr_qmarks($ids);
- if ($cmode == 0) {
+ if ($cmode == Article::CATCHUP_MODE_MARK_AS_READ) {
$sth = $this->pdo->prepare("UPDATE ttrss_user_entries SET
marked = false, last_marked = NOW()
WHERE ref_id IN ($ids_qmarks) AND owner_uid = ?");
- } else if ($cmode == 1) {
+ } else if ($cmode == Article::CATCHUP_MODE_MARK_AS_UNREAD) {
$sth = $this->pdo->prepare("UPDATE ttrss_user_entries SET
marked = true, last_marked = NOW()
WHERE ref_id IN ($ids_qmarks) AND owner_uid = ?");
@@ -361,15 +367,18 @@ class RPC extends Handler_Protected {
$sth->execute(array_merge($ids, [$_SESSION['uid']]));
}
- private function publishArticlesById($ids, $cmode) {
+ /**
+ * @param array<int, int> $ids
+ */
+ private function publishArticlesById(array $ids, int $cmode): void {
$ids_qmarks = arr_qmarks($ids);
- if ($cmode == 0) {
+ if ($cmode == Article::CATCHUP_MODE_MARK_AS_READ) {
$sth = $this->pdo->prepare("UPDATE ttrss_user_entries SET
published = false, last_published = NOW()
WHERE ref_id IN ($ids_qmarks) AND owner_uid = ?");
- } else if ($cmode == 1) {
+ } else if ($cmode == Article::CATCHUP_MODE_MARK_AS_UNREAD) {
$sth = $this->pdo->prepare("UPDATE ttrss_user_entries SET
published = true, last_published = NOW()
WHERE ref_id IN ($ids_qmarks) AND owner_uid = ?");
@@ -382,7 +391,7 @@ class RPC extends Handler_Protected {
$sth->execute(array_merge($ids, [$_SESSION['uid']]));
}
- function log() {
+ function log(): void {
$msg = clean($_REQUEST['msg'] ?? "");
$file = basename(clean($_REQUEST['file'] ?? ""));
$line = (int) clean($_REQUEST['line'] ?? 0);
@@ -396,7 +405,7 @@ class RPC extends Handler_Protected {
}
}
- function checkforupdates() {
+ function checkforupdates(): void {
$rv = ["changeset" => [], "plugins" => []];
$version = Config::get_version(false);
@@ -425,7 +434,10 @@ class RPC extends Handler_Protected {
print json_encode($rv);
}
- private function _make_init_params() {
+ /**
+ * @return array<string, mixed>
+ */
+ private function _make_init_params(): array {
$params = array();
foreach ([Prefs::ON_CATCHUP_SHOW_NEXT_FEED, Prefs::HIDE_READ_FEEDS,
@@ -481,7 +493,7 @@ class RPC extends Handler_Protected {
return $params;
}
- private function image_to_base64($filename) {
+ private function image_to_base64(string $filename): string {
if (file_exists($filename)) {
$ext = pathinfo($filename, PATHINFO_EXTENSION);
@@ -493,7 +505,10 @@ class RPC extends Handler_Protected {
}
}
- static function _make_runtime_info() {
+ /**
+ * @return array<string, mixed>
+ */
+ static function _make_runtime_info(): array {
$data = array();
$pdo = Db::pdo();
@@ -562,7 +577,10 @@ class RPC extends Handler_Protected {
return $data;
}
- static function get_hotkeys_info() {
+ /**
+ * @return array<string, array<string, string>>
+ */
+ static function get_hotkeys_info(): array {
$hotkeys = array(
__("Navigation") => array(
"next_feed" => __("Open next feed"),
@@ -642,8 +660,12 @@ class RPC extends Handler_Protected {
return $hotkeys;
}
- // {3} - 3 panel mode only
- // {C} - combined mode only
+ /**
+ * {3} - 3 panel mode only
+ * {C} - combined mode only
+ *
+ * @return array{0: array<int, string>, 1: array<string, string>} $prefixes, $hotkeys
+ */
static function get_hotkeys_map() {
$hotkeys = array(
"k" => "next_feed",
@@ -728,7 +750,7 @@ class RPC extends Handler_Protected {
return array($prefixes, $hotkeys);
}
- function hotkeyHelp() {
+ function hotkeyHelp(): void {
$info = self::get_hotkeys_info();
$imap = self::get_hotkeys_map();
$omap = array();