From 5333d3c8ec110a4349dfc3b56168a157afc70082 Mon Sep 17 00:00:00 2001 From: Antonio Ospite Date: Tue, 13 Nov 2018 17:56:44 +0100 Subject: [PATCH] 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. --- src/Tweeper.php | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) 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); -- 2.1.4