Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 389f46a

Browse files
authoredNov 19, 2021
Merge pull request #27 from eric-pierce/master
Comply with PHPStan Rule Level 6, Update for Sanitize Changes
2 parents 324c122 + 8cb4b2e commit 389f46a

File tree

3 files changed

+42
-38
lines changed

3 files changed

+42
-38
lines changed
 

‎README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,3 +181,7 @@ v2.4 - 2021/02/16
181181

182182
* Includes fixes by froks to fix for the latest changes in tiny-tiny-rss
183183
* Includes updates to account for the "Undefined array key' error upgrade from notice to warning in PHP8
184+
185+
v3 - 2021/11/18
186+
187+
* Updated to respect PHPStan Rule Level 6

‎fever_api.php

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?php
2-
function param_to_bool($p) {
2+
function param_to_bool($p): bool {
33
return $p && ($p !== "f" && $p !== "false");
44
}
55

@@ -26,7 +26,7 @@ class FeverAPI extends Handler {
2626
private $xml;
2727

2828
// find the user in the db with a particular api key
29-
private function setUser()
29+
private function setUser(): void
3030
{
3131
$apikey = isset($_REQUEST["api_key"]) ? clean($_REQUEST["api_key"]) : "";
3232

@@ -77,7 +77,7 @@ private function setUser()
7777
}
7878

7979
// set whether xml or json
80-
private function setXml()
80+
private function setXml(): void
8181
{
8282
$this->xml = false;
8383
if (isset($_REQUEST["api"]))
@@ -89,7 +89,7 @@ private function setXml()
8989
}
9090
}
9191

92-
private function setIdHack()
92+
private function setIdHack(): void
9393
{
9494
$this->id_hack = false;
9595

@@ -110,7 +110,7 @@ private function setIdHack()
110110
}
111111

112112
// validate the api_key, user preferences
113-
function before($method) {
113+
function before($method): bool {
114114
/* classes/api.php before */
115115

116116
if (parent::before($method)) {
@@ -152,7 +152,7 @@ function before($method) {
152152

153153
// always include api_version, status as 'auth'
154154
// output json/xml
155-
function wrap($status, $reply)
155+
function wrap($status, $reply): void
156156
{
157157
/* classes/api.php wrap */
158158
$arr = array("api_version" => self::API_LEVEL,
@@ -189,7 +189,7 @@ function wrap($status, $reply)
189189

190190
// fever supports xml wrapped in <response> tags
191191
// TODO: holy crap replace this junk
192-
private function array_to_xml($array, $container = 'response', $is_root = true)
192+
private function array_to_xml($array, $container = 'response', $is_root = true): string
193193
{
194194
if (!is_array($array)) return array_to_xml(array($array));
195195

@@ -241,7 +241,7 @@ private function array_to_xml($array, $container = 'response', $is_root = true)
241241
}
242242

243243
// every authenticated method includes last_refreshed_on_time
244-
private function lastRefreshedOnTime()
244+
private function lastRefreshedOnTime(): int
245245
{
246246
$sth = $this->pdo->prepare("SELECT " . SUBSTRING_FOR_DATE . "(last_updated,1,19) AS last_updated
247247
FROM ttrss_feeds
@@ -261,7 +261,7 @@ private function lastRefreshedOnTime()
261261
return $last_refreshed_on_time;
262262
}
263263

264-
private function flattenGroups(&$groupsToGroups, &$groups, &$groupsToTitle, $index)
264+
private function flattenGroups(&$groupsToGroups, &$groups, &$groupsToTitle, $index): void
265265
{
266266
foreach ($groupsToGroups[$index] as $item)
267267
{
@@ -272,7 +272,7 @@ private function flattenGroups(&$groupsToGroups, &$groups, &$groupsToTitle, $ind
272272
}
273273
}
274274

275-
function getGroups()
275+
function getGroups(): array
276276
{
277277
// TODO: ordering of child categories etc
278278
$groups = array();
@@ -320,7 +320,7 @@ function getGroups()
320320
return $groups;
321321
}
322322

323-
function getFeeds()
323+
function getFeeds(): array
324324
{
325325
$feeds = array();
326326

@@ -344,7 +344,7 @@ function getFeeds()
344344
return $feeds;
345345
}
346346

347-
function getFavicons()
347+
function getFavicons(): array
348348
{
349349
$favicons = array();
350350

@@ -369,7 +369,7 @@ function getFavicons()
369369
return $favicons;
370370
}
371371

372-
function getLinks()
372+
function getLinks(): array
373373
{
374374
// TODO: is there a 'hot links' alternative in ttrss?
375375
// use ttrss_user_entries / score > 0 / unread
@@ -459,7 +459,7 @@ function getLinks()
459459
return $links;
460460
}
461461

462-
function formatBytes($bytes, $precision = 2) {
462+
function formatBytes($bytes, $precision = 2): string {
463463
$units = array('B', 'KB', 'MB', 'GB', 'TB');
464464

465465
$bytes = max($bytes, 0);
@@ -473,7 +473,7 @@ function formatBytes($bytes, $precision = 2) {
473473
return round($bytes, $precision) . ' ' . $units[$pow];
474474
}
475475

476-
function getItems()
476+
function getItems(): array
477477
{
478478
// items from specific groups, feeds
479479
$items = array();
@@ -590,10 +590,10 @@ function getItems()
590590

591591
while ($line = $sth->fetch())
592592
{
593-
$line_content = sanitize(
593+
$line_content = Sanitizer::sanitize(
594594
$line["content"],
595595
param_to_bool($line['hide_images']),
596-
false, $line["site_url"], false, $line["id"]);
596+
false, $line["site_url"], [], $line["id"]);
597597

598598
if ($this->add_attached_files){
599599
$enclosures = Article::_get_enclosures($line["id"]);
@@ -631,7 +631,7 @@ function getItems()
631631
return $items;
632632
}
633633

634-
function getTotalItems()
634+
function getTotalItems(): int
635635
{
636636
// number of total items
637637
$total_items = 0;
@@ -649,7 +649,7 @@ function getTotalItems()
649649
return $total_items;
650650
}
651651

652-
function getFeedsGroup()
652+
function getFeedsGroup(): array
653653
{
654654
$feeds_groups = array();
655655

@@ -683,7 +683,7 @@ function getFeedsGroup()
683683
return $feeds_groups;
684684
}
685685

686-
function getUnreadItemIds()
686+
function getUnreadItemIds(): string
687687
{
688688
$unreadItemIdsCSV = "";
689689
$sth = $this->pdo->prepare("SELECT ref_id
@@ -700,7 +700,7 @@ function getUnreadItemIds()
700700
return $unreadItemIdsCSV;
701701
}
702702

703-
function getSavedItemIds()
703+
function getSavedItemIds(): string
704704
{
705705
$savedItemIdsCSV = "";
706706
$sth = $this->pdo->prepare("SELECT ref_id
@@ -717,7 +717,7 @@ function getSavedItemIds()
717717
return $savedItemIdsCSV;
718718
}
719719

720-
function getEqualItems($id)
720+
function getEqualItems($id): string
721721
{
722722
//get all ids which have identical links (Reference is found by id)
723723
$sth = $this->pdo->prepare("SELECT id
@@ -741,7 +741,7 @@ function getEqualItems($id)
741741
return $ids;
742742
}
743743

744-
function setItem($id, $field_raw, $mode)
744+
function setItem($id, $field_raw, $mode): void
745745
{
746746
/* classes/api.php updateArticle */
747747

@@ -790,30 +790,30 @@ function setItem($id, $field_raw, $mode)
790790
}
791791
}
792792

793-
function setItemAsRead($id)
793+
function setItemAsRead($id): void
794794
{
795795
//action is true for all Equal Items
796796
$ids = $this->getEqualItems($id);
797797
$this->setItem($ids, 1, 0);
798798
}
799799

800-
function setItemAsUnread($id)
800+
function setItemAsUnread($id): void
801801
{
802802
$ids = $this->getEqualItems($id);
803803
$this->setItem($ids, 1, 1);
804804
}
805805

806-
function setItemAsSaved($id)
806+
function setItemAsSaved($id): void
807807
{
808808
$this->setItem($id, 0, 1);
809809
}
810810

811-
function setItemAsUnsaved($id)
811+
function setItemAsUnsaved($id): void
812812
{
813813
$this->setItem($id, 0, 0);
814814
}
815815

816-
function setFeed($id, $cat, $before=0)
816+
function setFeed($id, $cat, $before=0): void
817817
{
818818
/* classes/feeds.php catchup_feed */
819819

@@ -863,18 +863,18 @@ function setFeed($id, $cat, $before=0)
863863
}
864864
}
865865

866-
function setFeedAsRead($id, $before)
866+
function setFeedAsRead($id, $before): void
867867
{
868868
$this->setFeed($id, false, $before);
869869
}
870870

871-
function setGroupAsRead($id, $before)
871+
function setGroupAsRead($id, $before): void
872872
{
873873
$this->setFeed($id, true, $before);
874874
}
875875

876876
// this does all the processing, since the fever api does not have a specific variable that specifies the operation
877-
function index()
877+
function index(): void
878878
{
879879
$response_arr = array();
880880

@@ -926,7 +926,7 @@ function index()
926926

927927
}
928928

929-
function markId($id)
929+
function markId($id): void
930930
{
931931
if (is_numeric($id))
932932
{

‎init.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,21 @@
22
class Fever extends Plugin {
33
private $host;
44

5-
function about() {
5+
function about(): array {
66
return array(2.3,
77
"Emulates the Fever API for Tiny Tiny RSS",
88
"DigitalDJ, mestrode & murphy, eric-pierce");
99
}
1010

11-
function init($host) {
11+
function init($host): void {
1212
$this->host = $host;
1313

1414
$host->add_hook($host::HOOK_PREFS_TAB, $this);
1515
}
1616

1717
/* plugins/main/init.php hook_prefs_tab */
1818

19-
function hook_prefs_tab($args) {
19+
function hook_prefs_tab($args): void {
2020
if ($args != "prefPrefs") return;
2121

2222
print "<div dojoType=\"dijit.layout.AccordionPane\" title=\"" . __("Fever Emulation") . "\">";
@@ -56,7 +56,7 @@ function hook_prefs_tab($args) {
5656
print "</div>";
5757
}
5858

59-
function save()
59+
function save(): void
6060
{
6161
if (isset($_POST["password"]) && isset($_SESSION["uid"]))
6262
{
@@ -71,8 +71,8 @@ function save()
7171
}
7272
}
7373

74-
function api_version() {
75-
return 2;
74+
function api_version(): int {
75+
return 3;
7676
}
7777
}
7878

0 commit comments

Comments
 (0)