From: Antonio Ospite Date: Tue, 13 Nov 2018 16:56:44 +0000 (+0100) Subject: src/Tweeper.php: make code more robust by properly check return values X-Git-Tag: v1.4.0~8 X-Git-Url: https://git.ao2.it/tweeper.git/commitdiff_plain/5333d3c8ec110a4349dfc3b56168a157afc70082?ds=sidebyside;hp=01dfd03d97afd0d5d06a36af37d96892905340ad src/Tweeper.php: make code more robust by properly check return values Check return values to catch error earlier, and while at it also emit more error messages in case of failures. --- diff --git a/src/Tweeper.php b/src/Tweeper.php index cfa3812..22d16ab 100644 --- a/src/Tweeper.php +++ b/src/Tweeper.php @@ -124,7 +124,14 @@ class Tweeper { CURLOPT_SSL_VERIFYPEER => FALSE, CURLOPT_USERAGENT => Tweeper::$userAgent, )); - curl_exec($ch); + + $ret = curl_exec($ch); + if (FALSE === $ret) { + trigger_error(curl_error($ch)); + curl_close($ch); + return FALSE; + } + $url_info = curl_getinfo($ch); if (FALSE === $url_info) { trigger_error(curl_error($ch)); @@ -160,6 +167,10 @@ class Tweeper { ); $url_info = Tweeper::getUrlInfo($url); + if (FALSE === $url_info) { + error_log("Failed to retrieve info for URL: " . $url); + return ''; + } $supported = in_array($url_info['content_type'], $supported_content_types); if (!$supported) { @@ -320,6 +331,9 @@ class Tweeper { } $stylesheet_contents = Tweeper::getUrlContents($stylesheet); + if (FALSE === $stylesheet_contents) { + return NULL; + } $xslDoc = new DOMDocument(); $xslDoc->loadXML($stylesheet_contents);