fix some more warnings reported by phpstan

master
Andrew Dolgov 4 years ago
parent b6e1a5c91a
commit c94f1b6ff8

@ -6,7 +6,7 @@ class DbUpdater {
private $need_version;
function __construct($pdo, $db_type, $need_version) {
$this->pdo = Db::pdo(); //$pdo;
$this->pdo = $pdo;
$this->db_type = $db_type;
$this->need_version = (int) $need_version;
}
@ -24,7 +24,7 @@ class DbUpdater {
$filename = "schema/versions/".$this->db_type."/$version.sql";
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 {
user_error("DB Updater: schema file for version $version is not found.");
return false;

@ -5,8 +5,6 @@ class Digest
/**
* 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.
*/
static function send_headlines_digests() {
@ -18,7 +16,7 @@ class Digest
if (DB_TYPE == "pgsql") {
$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)";
}
@ -113,7 +111,7 @@ class Digest
if (DB_TYPE == "pgsql") {
$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)";
}

@ -329,7 +329,9 @@ class DiskCache {
}
if ($need_saving) {
$doc->removeChild($doc->firstChild); //remove doctype
if (isset($doc->firstChild))
$doc->removeChild($doc->firstChild); //remove doctype
$res = $doc->saveHTML();
}
}
@ -384,7 +386,7 @@ class DiskCache {
$mimetype_blacklist = [ "image/svg+xml" ];
/* 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);
header("Content-type: text/plain");
@ -403,7 +405,7 @@ class DiskCache {
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);
return readfile($filename);

@ -136,7 +136,7 @@ class Dlg extends Handler_Protected {
// and add the $min_size set above
$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: " .
$size . "px\" title=\"$value articles tagged with " .

@ -53,7 +53,7 @@ class FeedParser {
$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);
if ($root) {
@ -106,7 +106,7 @@ class FeedParser {
$articles = $xpath->query("//atom:entry");
if (!$articles || $articles->length == 0)
if (empty($articles) || $articles->length == 0)
$articles = $xpath->query("//atom03:entry");
foreach ($articles as $article) {

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

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

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

Loading…
Cancel
Save