Fix type-safety issues around curl in new checking HTTP status function

This commit is contained in:
Joshua Ramon Enslin 2023-08-18 15:12:45 +02:00
parent 88458df949
commit b143845aea
Signed by: jrenslin
GPG Key ID: 46016F84501B70AE

View File

@ -428,11 +428,14 @@ final class MD_STD {
*/ */
public static function checkUrlIsReachable(string $url):bool { public static function checkUrlIsReachable(string $url):bool {
if (empty($url)) {
throw new MDInvalidUrl("Input URL cannot be empty");
}
if (filter_var($url, FILTER_VALIDATE_URL) === false) { if (filter_var($url, FILTER_VALIDATE_URL) === false) {
throw new MDInvalidUrl("URL to check (" . $url . ") does not seem to be a valid URL"); throw new MDInvalidUrl("URL to check (" . $url . ") does not seem to be a valid URL");
} }
$ch = curl_init($url); $ch = self::curl_init($url, 5000);
curl_setopt_array($ch, [ curl_setopt_array($ch, [
CURLOPT_AUTOREFERER => true, CURLOPT_AUTOREFERER => true,
CURLOPT_CONNECTTIMEOUT => 5, CURLOPT_CONNECTTIMEOUT => 5,