From 75ca887ea4f170c5b063f0c7dd91da506e41b104 Mon Sep 17 00:00:00 2001 From: redalert2fan <42489779+redalert2fan@users.noreply.github.com> Date: Sat, 8 Aug 2026 16:17:34 +0100 Subject: [PATCH] Fix remaining type errors across misc files gadgetapi: cast POST summary/text to string (is_string check already guards). big_jobs: guard fopen() false before fclose(). bot_curl: type the user agent as non-empty-string for the curl stub. setup: guard ob_get_contents() false before mb_trim. Resolves the 4 remaining PHPStan level 7 errors not covered by open PRs. --- src/gadgetapi.php | 4 ++-- src/includes/big_jobs.php | 5 ++++- src/includes/bot_curl.php | 4 +++- src/includes/setup.php | 4 +++- 4 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/gadgetapi.php b/src/gadgetapi.php index a19fef608c..76de1fef99 100644 --- a/src/gadgetapi.php +++ b/src/gadgetapi.php @@ -21,8 +21,8 @@ if (!is_string(@$_POST['text']) || !is_string(@$_POST['summary'])) { throw new Exception('not a string'); // @codeCoverageIgnore } - $originalText = $_POST['text']; - $editSummary = $_POST['summary']; + $originalText = (string) $_POST['text']; + $editSummary = (string) $_POST['summary']; unset($_GET, $_POST, $_REQUEST); // Memory minimize if (mb_strlen($originalText) < 6) { diff --git a/src/includes/big_jobs.php b/src/includes/big_jobs.php index 50ece872db..43290f22f4 100644 --- a/src/includes/big_jobs.php +++ b/src/includes/big_jobs.php @@ -7,7 +7,10 @@ /** "hard" as in "try hard" and ignore errors */ function hard_touch(string $file): void { touch($file); - @fclose(@fopen($file, 'a')); // Do something else to file + $handle = @fopen($file, 'a'); // Do something else to file + if ($handle !== false) { + @fclose($handle); + } } function big_jobs_name(): string { // NEVER save this string. Always use this function so that clearstatcache is called diff --git a/src/includes/bot_curl.php b/src/includes/bot_curl.php index 84e27d30fe..c2c4cfc8eb 100644 --- a/src/includes/bot_curl.php +++ b/src/includes/bot_curl.php @@ -24,11 +24,13 @@ function bot_curl_init(float $time, array $ops): CurlHandle { report_error("curl_init failure"); // @codeCoverageIgnore } // 1 - Global Defaults + /** @var non-empty-string $user_agent */ + $user_agent = BOT_USER_AGENT; curl_setopt_array($ch, [ CURLOPT_FOLLOWLOCATION => true, CURLOPT_BUFFERSIZE => 524288, // 512kB chunks CURLOPT_MAXREDIRS => 20, // No infinite loops for us, 20 for Elsevier and Springer websites - CURLOPT_USERAGENT => BOT_USER_AGENT, + CURLOPT_USERAGENT => $user_agent, CURLOPT_AUTOREFERER => true, CURLOPT_REFERER => "https://en.wikipedia.org", CURLOPT_COOKIESESSION => true, diff --git a/src/includes/setup.php b/src/includes/setup.php index 406c0a9e73..ecba08431a 100644 --- a/src/includes/setup.php +++ b/src/includes/setup.php @@ -99,7 +99,9 @@ function bot_debug_log(string $log_this): void { ob_start(); /** @psalm-suppress MissingFile */ include_once __DIR__ . '/../env.php'; - $env_output = mb_trim(ob_get_contents()); + $env_output_contents = ob_get_contents(); + $env_output = ($env_output_contents === false) ? '' : mb_trim($env_output_contents); + unset($env_output_contents); if ($env_output) { bot_debug_log("got this:\n" . $env_output); // Something unexpected, so log it }