fix some more warnings reported by phpstan

This commit is contained in:
Andrew Dolgov 2021-02-06 17:38:24 +03:00
parent b6e1a5c91a
commit c94f1b6ff8
8 changed files with 23 additions and 18 deletions

View File

@ -6,7 +6,7 @@ class DbUpdater {
private $need_version; private $need_version;
function __construct($pdo, $db_type, $need_version) { function __construct($pdo, $db_type, $need_version) {
$this->pdo = Db::pdo(); //$pdo; $this->pdo = $pdo;
$this->db_type = $db_type; $this->db_type = $db_type;
$this->need_version = (int) $need_version; $this->need_version = (int) $need_version;
} }
@ -24,7 +24,7 @@ class DbUpdater {
$filename = "schema/versions/".$this->db_type."/$version.sql"; $filename = "schema/versions/".$this->db_type."/$version.sql";
if (file_exists($filename)) { if (file_exists($filename)) {
return explode(";", preg_replace("/[\r\n]/", "", file_get_contents($filename))); return explode(";", (string)preg_replace("/[\r\n]/", "", (string)file_get_contents($filename)));
} else { } else {
user_error("DB Updater: schema file for version $version is not found."); user_error("DB Updater: schema file for version $version is not found.");
return false; return false;

View File

@ -5,8 +5,6 @@ class Digest
/** /**
* Send by mail a digest of last articles. * Send by mail a digest of last articles.
* *
* @param mixed $link The database connection.
* @param integer $limit The maximum number of articles by digest.
* @return boolean Return false if digests are not enabled. * @return boolean Return false if digests are not enabled.
*/ */
static function send_headlines_digests() { static function send_headlines_digests() {
@ -18,7 +16,7 @@ class Digest
if (DB_TYPE == "pgsql") { if (DB_TYPE == "pgsql") {
$interval_qpart = "last_digest_sent < NOW() - INTERVAL '1 days'"; $interval_qpart = "last_digest_sent < NOW() - INTERVAL '1 days'";
} else if (DB_TYPE == "mysql") { } else /* if (DB_TYPE == "mysql") */ {
$interval_qpart = "last_digest_sent < DATE_SUB(NOW(), INTERVAL 1 DAY)"; $interval_qpart = "last_digest_sent < DATE_SUB(NOW(), INTERVAL 1 DAY)";
} }
@ -113,7 +111,7 @@ class Digest
if (DB_TYPE == "pgsql") { if (DB_TYPE == "pgsql") {
$interval_qpart = "ttrss_entries.date_updated > NOW() - INTERVAL '$days days'"; $interval_qpart = "ttrss_entries.date_updated > NOW() - INTERVAL '$days days'";
} else if (DB_TYPE == "mysql") { } else /* if (DB_TYPE == "mysql") */ {
$interval_qpart = "ttrss_entries.date_updated > DATE_SUB(NOW(), INTERVAL $days DAY)"; $interval_qpart = "ttrss_entries.date_updated > DATE_SUB(NOW(), INTERVAL $days DAY)";
} }

View File

@ -329,7 +329,9 @@ class DiskCache {
} }
if ($need_saving) { if ($need_saving) {
$doc->removeChild($doc->firstChild); //remove doctype if (isset($doc->firstChild))
$doc->removeChild($doc->firstChild); //remove doctype
$res = $doc->saveHTML(); $res = $doc->saveHTML();
} }
} }
@ -384,7 +386,7 @@ class DiskCache {
$mimetype_blacklist = [ "image/svg+xml" ]; $mimetype_blacklist = [ "image/svg+xml" ];
/* only serve video and images */ /* only serve video and images */
if (!preg_match("/(image|audio|video)\//", $mimetype) || in_array($mimetype, $mimetype_blacklist)) { if (!preg_match("/(image|audio|video)\//", (string)$mimetype) || in_array($mimetype, $mimetype_blacklist)) {
http_response_code(400); http_response_code(400);
header("Content-type: text/plain"); header("Content-type: text/plain");
@ -403,7 +405,7 @@ class DiskCache {
header("Content-type: $mimetype"); header("Content-type: $mimetype");
$stamp = gmdate("D, d M Y H:i:s", filemtime($filename)) . " GMT"; $stamp = gmdate("D, d M Y H:i:s", (int)filemtime($filename)) . " GMT";
header("Last-Modified: $stamp", true); header("Last-Modified: $stamp", true);
return readfile($filename); return readfile($filename);

View File

@ -136,7 +136,7 @@ class Dlg extends Handler_Protected {
// and add the $min_size set above // and add the $min_size set above
$size = round($min_size + (($value - $min_qty) * $step)); $size = round($min_size + (($value - $min_qty) * $step));
$key_escaped = str_replace("'", "\\'", $key); $key_escaped = str_replace("'", "\\'", (string)$key);
echo "<a href=\"#\" onclick=\"Feeds.open({feed:'$key_escaped'}) \" style=\"font-size: " . echo "<a href=\"#\" onclick=\"Feeds.open({feed:'$key_escaped'}) \" style=\"font-size: " .
$size . "px\" title=\"$value articles tagged with " . $size . "px\" title=\"$value articles tagged with " .

View File

@ -53,7 +53,7 @@ class FeedParser {
$root = $xpath->query("(//atom03:feed|//atom:feed|//channel|//rdf:rdf|//rdf:RDF)"); $root = $xpath->query("(//atom03:feed|//atom:feed|//channel|//rdf:rdf|//rdf:RDF)");
if ($root && $root->length > 0) { if (!empty($root) && $root->length > 0) {
$root = $root->item(0); $root = $root->item(0);
if ($root) { if ($root) {
@ -106,7 +106,7 @@ class FeedParser {
$articles = $xpath->query("//atom:entry"); $articles = $xpath->query("//atom:entry");
if (!$articles || $articles->length == 0) if (empty($articles) || $articles->length == 0)
$articles = $xpath->query("//atom03:entry"); $articles = $xpath->query("//atom03:entry");
foreach ($articles as $article) { foreach ($articles as $article) {

View File

@ -196,6 +196,8 @@ class Labels
$sth->execute([$caption, $owner_uid, $fg_color, $bg_color]); $sth->execute([$caption, $owner_uid, $fg_color, $bg_color]);
$result = $sth->rowCount(); $result = $sth->rowCount();
} else {
$result = false;
} }
if (!$tr_in_progress) $pdo->commit(); if (!$tr_in_progress) $pdo->commit();

View File

@ -272,7 +272,7 @@ class Opml extends Handler_Protected {
$doc->preserveWhiteSpace = false; $doc->preserveWhiteSpace = false;
$doc->loadXML($out); $doc->loadXML($out);
$xpath = new DOMXpath($doc); $xpath = new DOMXPath($doc);
$outlines = $xpath->query("//outline[@title]"); $outlines = $xpath->query("//outline[@title]");
// cleanup empty categories // cleanup empty categories
@ -534,10 +534,11 @@ class Opml extends Handler_Protected {
$outlines = $root_node->childNodes; $outlines = $root_node->childNodes;
} else { } else {
$xpath = new DOMXpath($doc); $xpath = new DOMXPath($doc);
$outlines = $xpath->query("//opml/body/outline"); $outlines = $xpath->query("//opml/body/outline");
$cat_id = 0; $cat_id = 0;
$cat_title = false;
} }
#$this->opml_notice("[CAT] $cat_title id: $cat_id P_id: $parent_id"); #$this->opml_notice("[CAT] $cat_title id: $cat_id P_id: $parent_id");
@ -593,7 +594,7 @@ class Opml extends Handler_Protected {
} }
if (is_uploaded_file($_FILES['opml_file']['tmp_name'])) { if (is_uploaded_file($_FILES['opml_file']['tmp_name'])) {
$tmp_file = tempnam(CACHE_DIR . '/upload', 'opml'); $tmp_file = (string)tempnam(CACHE_DIR . '/upload', 'opml');
$result = move_uploaded_file($_FILES['opml_file']['tmp_name'], $result = move_uploaded_file($_FILES['opml_file']['tmp_name'],
$tmp_file); $tmp_file);
@ -607,13 +608,15 @@ class Opml extends Handler_Protected {
return; return;
} }
$loaded = false;
if (is_file($tmp_file)) { if (is_file($tmp_file)) {
$doc = new DOMDocument(); $doc = new DOMDocument();
libxml_disable_entity_loader(false); libxml_disable_entity_loader(false);
$loaded = $doc->load($tmp_file); $loaded = $doc->load($tmp_file);
libxml_disable_entity_loader(true); libxml_disable_entity_loader(true);
unlink($tmp_file); unlink($tmp_file);
} else if (!$doc) { } else if (empty($doc)) {
print_error(__('Error: unable to find moved OPML file.')); print_error(__('Error: unable to find moved OPML file.'));
return; return;
} }

View File

@ -390,13 +390,13 @@ class PluginHost {
if ($sth->fetch()) { if ($sth->fetch()) {
$sth = $this->pdo_data->prepare("UPDATE ttrss_plugin_storage SET content = ? $sth = $this->pdo_data->prepare("UPDATE ttrss_plugin_storage SET content = ?
WHERE owner_uid= ? AND name = ?"); WHERE owner_uid= ? AND name = ?");
$sth->execute([(string)$content, $this->owner_uid, $plugin]); $sth->execute([$content, $this->owner_uid, $plugin]);
} else { } else {
$sth = $this->pdo_data->prepare("INSERT INTO ttrss_plugin_storage $sth = $this->pdo_data->prepare("INSERT INTO ttrss_plugin_storage
(name,owner_uid,content) VALUES (name,owner_uid,content) VALUES
(?, ?, ?)"); (?, ?, ?)");
$sth->execute([$plugin, $this->owner_uid, (string)$content]); $sth->execute([$plugin, $this->owner_uid, $content]);
} }
$this->pdo_data->commit(); $this->pdo_data->commit();