summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Dolgov <[email protected]>2021-11-14 21:34:11 +0300
committerAndrew Dolgov <[email protected]>2021-11-14 21:34:11 +0300
commit410df099846bea3329027ad0389405fafff6cda5 (patch)
treed867b2f552ec4f3c9341aba306fa98e9d5e9b52d
parent39d5ed40c5de4da260cc693e1a3c066c4bb36b90 (diff)
fix phpstan warnings
-rw-r--r--init.php39
1 files changed, 25 insertions, 14 deletions
diff --git a/init.php b/init.php
index 894d87e..ac61cb8 100644
--- a/init.php
+++ b/init.php
@@ -4,10 +4,10 @@ class Api_Resize_Media extends Plugin {
const MAX_WIDTH = 1024;
const DEFAULT_QUALITY = 80;
- /* @var PluginHost $host */
+ /** @var PluginHost $host */
private $host;
- /* @var DiskCache $cache */
+ /** @var DiskCache $cache */
private $cache;
function about() {
@@ -35,8 +35,9 @@ class Api_Resize_Media extends Plugin {
$host->add_hook($host::HOOK_ARTICLE_FILTER, $this, 999);
}
- private function make_thumbnail($input_filename, $output_filename, $dim_max_x = 600, $dim_max_y = 600,
- $content_type = "", $force_stamp = false, $quality = self::DEFAULT_QUALITY) {
+ private function make_thumbnail(string $input_filename, string $output_filename,
+ int $dim_max_x = 600, int $dim_max_y = 600,
+ string $content_type = "", bool $force_stamp = false, int $quality = self::DEFAULT_QUALITY) : void {
if ($content_type == "image/webp") {
$o_im = @imagecreatefromwebp($input_filename);
@@ -108,7 +109,14 @@ class Api_Resize_Media extends Plugin {
}
}
- function prepare_thumbnails(string $url, array $widths, bool $force_stamp) {
+ /**
+ * @param string $url
+ * @param array<int> $widths
+ * @param bool $force_stamp
+ * @return void
+ * @throws PDOException
+ */
+ function prepare_thumbnails(string $url, array $widths, bool $force_stamp) : void {
Debug::log("[api_resize_media] checking URL $url (force_stamp=$force_stamp)...",
Debug::LOG_VERBOSE);
@@ -169,7 +177,7 @@ class Api_Resize_Media extends Plugin {
}
}
- public function api_resize() {
+ public function api_resize() : void {
$url = validate_url($_REQUEST["url"]);
$width = (int) $_REQUEST["width"];
@@ -204,7 +212,6 @@ class Api_Resize_Media extends Plugin {
$force_stamp,
$quality);
- // @phpstan-ignore-next-line
if ($this->cache->exists($resized_filename)) {
header("Location: " . $this->cache->get_url($resized_filename));
return;
@@ -233,7 +240,6 @@ class Api_Resize_Media extends Plugin {
$force_stamp,
$quality);
- // @phpstan-ignore-next-line
if ($this->cache->exists($resized_filename)) {
header("Location: " . $this->cache->get_url($resized_filename));
return;
@@ -273,7 +279,7 @@ class Api_Resize_Media extends Plugin {
}
}
- private function rewrite_url_if_needed($url, $width, $force_stamp = false) {
+ private function rewrite_url_if_needed(string $url, int $width, bool $force_stamp = false) : string {
if (strpos($url, "data:") !== 0 && $width > 0) {
if ($width > self::MAX_WIDTH)
@@ -294,7 +300,12 @@ class Api_Resize_Media extends Plugin {
return $url;
}
- private function process_article($row, $width) {
+ /**
+ * @param array<string,mixed> $row
+ * @param int $width
+ * @return array<string,mixed>
+ */
+ private function process_article(array $row, int $width) : array {
$need_saving = false;
$article = isset($row['headline']) ? $row['headline'] : $row['article'];
@@ -372,7 +383,7 @@ class Api_Resize_Media extends Plugin {
return $article;
}
- function hook_article_image($enclosures, $content, $site_url) {
+ function hook_article_image($enclosures, $content, $site_url, $article) {
$width = (int) clean($_REQUEST["resize_width"] ?? 0);
$article = $this->process_article(["headline" => ["content" => $content]], $width);
@@ -380,7 +391,7 @@ class Api_Resize_Media extends Plugin {
return ["", "", $article["content"]];
}
- function hook_enclosure_entry($enc) {
+ function hook_enclosure_entry($enc, $id, $rv) {
$force_width = (int) $this->host->profile_get($this, "force_width", 0);
$enc["content_url"] = $this->rewrite_url_if_needed($enc["content_url"], $force_width);
@@ -458,7 +469,7 @@ class Api_Resize_Media extends Plugin {
}
// https://stackoverflow.com/questions/280658/can-i-detect-animated-gifs-using-php-and-gd
- function is_animated_gif ($filename) {
+ function is_animated_gif(string $filename) : bool {
$raw = file_get_contents($filename);
if ($raw) {
@@ -548,7 +559,7 @@ class Api_Resize_Media extends Plugin {
<?php
}
- function save() {
+ function save() : void {
$force_width = (int) $_POST["force_width"];
$quality = (int) $_POST["quality"];
$prepare_widths = array_map("intval",