diff --git a/.dist/phpstan.neon.dist b/.dist/phpstan.neon.dist index 8b81b19c..161ba320 100644 --- a/.dist/phpstan.neon.dist +++ b/.dist/phpstan.neon.dist @@ -60,6 +60,8 @@ parameters: - ../fp-includes/smarty-5.8.4/** - ../fp-content/compile/** - ../fp-content/cache/** + - ../.setup.php (?) + - ../.setup/** (?) paths: - .. diff --git a/admin/panels/uploader/admin.uploader.php b/admin/panels/uploader/admin.uploader.php index 28d7eb03..468ee36e 100755 --- a/admin/panels/uploader/admin.uploader.php +++ b/admin/panels/uploader/admin.uploader.php @@ -449,6 +449,7 @@ function onupload() { */ if (function_exists('finfo_open')) { $finfo = finfo_open(FILEINFO_MIME_TYPE); + // @phpstan-ignore argument.type (PHPStan 2.2.10 reports the PHP 7.x fileinfo resource arm as incompatible in ranged phpVersion analysis) $mime = $finfo ? @finfo_file($finfo, $tmp_name) : false; if ($finfo) { if (!is_php85_plus()) { diff --git a/fp-includes/core/core.utils.php b/fp-includes/core/core.utils.php index 485f226f..f56600e8 100644 --- a/fp-includes/core/core.utils.php +++ b/fp-includes/core/core.utils.php @@ -624,26 +624,29 @@ function utils_geturl($url) { ); $ch = curl_init($url); - curl_setopt_array($ch, $options); - $content = curl_exec($ch); - $err = curl_errno($ch); - $errmsg = curl_error($ch); - $header = curl_getinfo($ch); - if (!is_php85_plus()) { - curl_close($ch); - } + if ($ch !== false) { + curl_setopt_array($ch, $options); + $content = curl_exec($ch); + $err = curl_errno($ch); + $errmsg = curl_error($ch); + // @phpstan-ignore argument.type (PHPStan 2.2.10 reports the PHP 7.x cURL resource arm as incompatible in ranged phpVersion analysis) + $header = curl_getinfo($ch); + if (!is_php85_plus()) { + curl_close($ch); + } - if (!is_array($header)) { - $header = array(); + if (!is_array($header)) { + $header = array(); + } + // Ensure required keys exist for callers. + $header += $default; + $header ['errno'] = $err; + $header ['errmsg'] = $errmsg; + $header ['content'] = $content; + $header ['transport'] = 'curl'; + + return $header; } - // Ensure required keys exist for callers. - $header += $default; - $header ['errno'] = $err; - $header ['errmsg'] = $errmsg; - $header ['content'] = $content; - $header ['transport'] = 'curl'; - - return $header; } // Fallback transport: allow_url_fopen (common on shared hosting without cURL) diff --git a/fp-plugins/mastodon/plugin.mastodon.php b/fp-plugins/mastodon/plugin.mastodon.php index 86b1fae5..36e11ea5 100644 --- a/fp-plugins/mastodon/plugin.mastodon.php +++ b/fp-plugins/mastodon/plugin.mastodon.php @@ -9915,41 +9915,44 @@ function plugin_mastodon_http_request_multipart($method, $url, $headers, $fields } $responseHeaders = array(); $ch = curl_init($url); - $options = array( - CURLOPT_RETURNTRANSFER => true, - CURLOPT_FOLLOWLOCATION => true, - CURLOPT_MAXREDIRS => 5, - CURLOPT_CONNECTTIMEOUT => 15, - CURLOPT_TIMEOUT => $timeout, - CURLOPT_CUSTOMREQUEST => $method, - CURLOPT_HTTPHEADER => $headers, - CURLOPT_POSTFIELDS => $payload, - CURLOPT_HEADERFUNCTION => function ($curl, $headerLine) use (&$responseHeaders) { - $len = strlen($headerLine); - $headerLine = trim($headerLine); - if ($headerLine !== '' && strpos($headerLine, ':') !== false) { - list($name, $value) = explode(':', $headerLine, 2); - $responseHeaders [strtolower(trim($name))] = trim($value); - } - return $len; - }, - CURLOPT_USERAGENT => 'FlatPress-Mastodon/0.1' - ); - curl_setopt_array($ch, $options); - $responseBody = curl_exec($ch); - $errorNo = curl_errno($ch); - $error = curl_error($ch); - $code = (int) curl_getinfo($ch, CURLINFO_HTTP_CODE); - if (!is_php85_plus()) { - curl_close($ch); + if ($ch !== false) { + $options = array( + CURLOPT_RETURNTRANSFER => true, + CURLOPT_FOLLOWLOCATION => true, + CURLOPT_MAXREDIRS => 5, + CURLOPT_CONNECTTIMEOUT => 15, + CURLOPT_TIMEOUT => $timeout, + CURLOPT_CUSTOMREQUEST => $method, + CURLOPT_HTTPHEADER => $headers, + CURLOPT_POSTFIELDS => $payload, + CURLOPT_HEADERFUNCTION => function ($curl, $headerLine) use (&$responseHeaders) { + $len = strlen($headerLine); + $headerLine = trim($headerLine); + if ($headerLine !== '' && strpos($headerLine, ':') !== false) { + list($name, $value) = explode(':', $headerLine, 2); + $responseHeaders [strtolower(trim($name))] = trim($value); + } + return $len; + }, + CURLOPT_USERAGENT => 'FlatPress-Mastodon/0.1' + ); + curl_setopt_array($ch, $options); + $responseBody = curl_exec($ch); + $errorNo = curl_errno($ch); + $error = curl_error($ch); + // @phpstan-ignore argument.type (PHPStan 2.2.10 reports the PHP 7.x cURL resource arm as incompatible in ranged phpVersion analysis) + $code = (int) curl_getinfo($ch, CURLINFO_HTTP_CODE); + if (!is_php85_plus()) { + curl_close($ch); + } + return array( + 'ok' => ($errorNo === 0 && $code >= 200 && $code < 300), + 'code' => $code, + 'headers' => $responseHeaders, + 'body' => is_string($responseBody) ? $responseBody : '', + 'error' => (string) $error + ); } - return array( - 'ok' => ($errorNo === 0 && $code >= 200 && $code < 300), - 'code' => $code, - 'headers' => $responseHeaders, - 'body' => is_string($responseBody) ? $responseBody : '', - 'error' => (string) $error - ); } $boundary = '----FlatPressMastodon' . md5(uniqid('', true)); @@ -11062,44 +11065,47 @@ function plugin_mastodon_http_request($method, $url, $headers, $body, $contentTy if (function_exists('curl_init')) { $responseHeaders = array(); $ch = curl_init($url); - $options = array( - CURLOPT_RETURNTRANSFER => true, - CURLOPT_FOLLOWLOCATION => true, - CURLOPT_MAXREDIRS => 5, - CURLOPT_CONNECTTIMEOUT => 15, - CURLOPT_TIMEOUT => $timeout, - CURLOPT_CUSTOMREQUEST => $method, - CURLOPT_HTTPHEADER => $headers, - CURLOPT_HEADERFUNCTION => function ($curl, $headerLine) use (&$responseHeaders) { - $len = strlen($headerLine); - $headerLine = trim($headerLine); - if ($headerLine !== '' && strpos($headerLine, ':') !== false) { - list($name, $value) = explode(':', $headerLine, 2); - $responseHeaders [strtolower(trim($name))] = trim($value); - } - return $len; - }, - CURLOPT_USERAGENT => 'FlatPress-Mastodon/0.1' - ); + if ($ch !== false) { + $options = array( + CURLOPT_RETURNTRANSFER => true, + CURLOPT_FOLLOWLOCATION => true, + CURLOPT_MAXREDIRS => 5, + CURLOPT_CONNECTTIMEOUT => 15, + CURLOPT_TIMEOUT => $timeout, + CURLOPT_CUSTOMREQUEST => $method, + CURLOPT_HTTPHEADER => $headers, + CURLOPT_HEADERFUNCTION => function ($curl, $headerLine) use (&$responseHeaders) { + $len = strlen($headerLine); + $headerLine = trim($headerLine); + if ($headerLine !== '' && strpos($headerLine, ':') !== false) { + list($name, $value) = explode(':', $headerLine, 2); + $responseHeaders [strtolower(trim($name))] = trim($value); + } + return $len; + }, + CURLOPT_USERAGENT => 'FlatPress-Mastodon/0.1' + ); - if ($method === 'POST' || $method === 'PUT' || $method === 'PATCH' || $method === 'DELETE') { - $options [CURLOPT_POSTFIELDS] = $body; - } - curl_setopt_array($ch, $options); - $responseBody = curl_exec($ch); - $errorNo = curl_errno($ch); - $error = curl_error($ch); - $code = (int) curl_getinfo($ch, CURLINFO_HTTP_CODE); - if (!is_php85_plus()) { - curl_close($ch); + if ($method === 'POST' || $method === 'PUT' || $method === 'PATCH' || $method === 'DELETE') { + $options [CURLOPT_POSTFIELDS] = $body; + } + curl_setopt_array($ch, $options); + $responseBody = curl_exec($ch); + $errorNo = curl_errno($ch); + $error = curl_error($ch); + // @phpstan-ignore argument.type (PHPStan 2.2.10 reports the PHP 7.x cURL resource arm as incompatible in ranged phpVersion analysis) + $code = (int) curl_getinfo($ch, CURLINFO_HTTP_CODE); + if (!is_php85_plus()) { + curl_close($ch); + } + return array( + 'ok' => ($errorNo === 0 && $code >= 200 && $code < 300), + 'code' => $code, + 'headers' => $responseHeaders, + 'body' => is_string($responseBody) ? $responseBody : '', + 'error' => (string) $error + ); } - return array( - 'ok' => ($errorNo === 0 && $code >= 200 && $code < 300), - 'code' => $code, - 'headers' => $responseHeaders, - 'body' => is_string($responseBody) ? $responseBody : '', - 'error' => (string) $error - ); } if (ini_get('allow_url_fopen')) { @@ -11551,6 +11557,7 @@ function plugin_mastodon_profile_avatar_type($body, $headers) { if (function_exists('finfo_open')) { $finfo = @finfo_open(FILEINFO_MIME_TYPE); if ($finfo) { + // @phpstan-ignore argument.type (PHPStan 2.2.10 reports the PHP 7.x fileinfo resource arm as incompatible in ranged phpVersion analysis) $detected = @finfo_buffer($finfo, $body); @finfo_close($finfo); $detected = is_string($detected) ? strtolower(trim($detected)) : ''; diff --git a/fp-plugins/newsletter/plugin.newsletter.php b/fp-plugins/newsletter/plugin.newsletter.php index ce4fe566..f8951c67 100644 --- a/fp-plugins/newsletter/plugin.newsletter.php +++ b/fp-plugins/newsletter/plugin.newsletter.php @@ -240,6 +240,7 @@ function plugin_newsletter_http_get(string $url, ?int &$httpCode = null, ?string $data = curl_exec($ch); $errno = curl_errno($ch); $errstr = curl_error($ch); + // @phpstan-ignore argument.type (PHPStan 2.2.10 reports the PHP 7.x cURL resource arm as incompatible in ranged phpVersion analysis) $code = (int) curl_getinfo($ch, CURLINFO_HTTP_CODE); if (!is_php85_plus()) { curl_close($ch);