From 9dac9c5a0db520697794c00d29424e617aca55bd Mon Sep 17 00:00:00 2001
From: wn_ <invalid@email.com>
Date: Mon, 1 Nov 2021 20:36:48 +0000
Subject: [PATCH] Address PHPStan warnings in 'classes/urlhelper.php'.

Intentionally skipping the line 66 one for now; adding an 'is_array' check clears the warning, but there's a larger topic of how to handle an invalid '' that doesn't result in an array.

------ ---------------------------------------------------------------------
Line   classes/urlhelper.php
------ ---------------------------------------------------------------------
66     Offset 'path' on array{scheme: string} in isset() does not exist.
165    Parameter #2 $associative of function get_headers expects bool, int
        given.
167    Parameter #2 $associative of function get_headers expects bool, int
        given.
278    Negated boolean expression is always true.
309    Negated boolean expression is always true.
------ ---------------------------------------------------------------------
---
 classes/urlhelper.php | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/classes/urlhelper.php b/classes/urlhelper.php
index 0e4834b72..4d11b5a4d 100644
--- a/classes/urlhelper.php
+++ b/classes/urlhelper.php
@@ -162,8 +162,12 @@ class UrlHelper {
 
 			$context = stream_context_create($context_options);
 
+			// PHP 8 changed the second param from int to bool, but we still support PHP >= 7.1.0
+			// @phpstan-ignore-next-line
 			$headers = get_headers($url, 0, $context);
 		} else {
+			// PHP 8 changed the second param from int to bool, but we still support PHP >= 7.1.0
+			// @phpstan-ignore-next-line
 			$headers = get_headers($url, 0);
 		}
 
@@ -275,7 +279,7 @@ class UrlHelper {
 
 			curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout ? $timeout : Config::get(Config::FILE_FETCH_CONNECT_TIMEOUT));
 			curl_setopt($ch, CURLOPT_TIMEOUT, $timeout ? $timeout : Config::get(Config::FILE_FETCH_TIMEOUT));
-			curl_setopt($ch, CURLOPT_FOLLOWLOCATION, !ini_get("open_basedir") && $followlocation);
+			curl_setopt($ch, CURLOPT_FOLLOWLOCATION, $followlocation);
 			curl_setopt($ch, CURLOPT_MAXREDIRS, 20);
 			curl_setopt($ch, CURLOPT_BINARYTRANSFER, true);
 			curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
@@ -283,6 +287,7 @@ class UrlHelper {
 			curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
 			curl_setopt($ch, CURLOPT_USERAGENT, $useragent ? $useragent : Config::get_user_agent());
 			curl_setopt($ch, CURLOPT_ENCODING, "");
+			curl_setopt($ch, CURLOPT_COOKIEJAR, "/dev/null");
 
 			if  ($http_referrer)
 				curl_setopt($ch, CURLOPT_REFERER, $http_referrer);
@@ -306,10 +311,6 @@ class UrlHelper {
 
 			}
 
-			if (!ini_get("open_basedir")) {
-				curl_setopt($ch, CURLOPT_COOKIEJAR, "/dev/null");
-			}
-
 			if (Config::get(Config::HTTP_PROXY)) {
 				curl_setopt($ch, CURLOPT_PROXY, Config::get(Config::HTTP_PROXY));
 			}
-- 
GitLab