From: Antonio Ospite Date: Mon, 8 Jun 2020 21:58:50 +0000 (+0200) Subject: Fix style issues pointed out by PHP_CodeSniffer X-Git-Tag: v1.4.2~5 X-Git-Url: https://git.ao2.it/tweeper.git/commitdiff_plain/fae2bb79789ff07d7cdeb6b609b3fd9b43b107b8?ds=sidebyside Fix style issues pointed out by PHP_CodeSniffer Fix the following errors from PHP_CodeSniffer with the help og phpcbf: FILE: /home/ao2/Proj/Tweeper/tweeper/tweeper.php ---------------------------------------------------------------------- FOUND 3 ERRORS AFFECTING 3 LINES ---------------------------------------------------------------------- 54 | ERROR | [x] Short array syntax must be used to define arrays 65 | ERROR | [x] Short array syntax must be used to define arrays 124 | ERROR | [x] Short array syntax must be used to define arrays ---------------------------------------------------------------------- PHPCBF CAN FIX THE 3 MARKED SNIFF VIOLATIONS AUTOMATICALLY ---------------------------------------------------------------------- FILE: /home/ao2/Proj/Tweeper/tweeper/src/Tweeper.php ---------------------------------------------------------------------- FOUND 15 ERRORS AFFECTING 12 LINES ---------------------------------------------------------------------- 162 | ERROR | [x] Short array syntax must be used to define arrays 169 | ERROR | [x] Short array syntax must be used to define arrays 183 | ERROR | [x] Short array syntax must be used to define arrays 212 | ERROR | [x] Short array syntax must be used to define arrays 313 | ERROR | [x] Short array syntax must be used to define arrays 313 | ERROR | [x] Short array syntax must be used to define arrays 315 | ERROR | [x] Short array syntax must be used to define arrays 378 | ERROR | [x] Short array syntax must be used to define arrays 378 | ERROR | [x] Short array syntax must be used to define arrays 437 | ERROR | [x] Short array syntax must be used to define arrays 466 | ERROR | [x] Short array syntax must be used to define arrays 466 | ERROR | [x] Short array syntax must be used to define arrays ---------------------------------------------------------------------- PHPCBF CAN FIX THE 12 MARKED SNIFF VIOLATIONS AUTOMATICALLY ---------------------------------------------------------------------- Time: 273ms; Memory: 10MB --- diff --git a/src/Tweeper.php b/src/Tweeper.php index 7b2654d..10e07e3 100644 --- a/src/Tweeper.php +++ b/src/Tweeper.php @@ -159,16 +159,16 @@ class Tweeper { */ private static function getUrlContents($url) { $ch = curl_init($url); - curl_setopt_array($ch, array( + curl_setopt_array($ch, [ CURLOPT_HEADER => FALSE, CURLOPT_CONNECTTIMEOUT => Tweeper::$maxConnectionTimeout, // Follow http redirects to get the real URL. CURLOPT_FOLLOWLOCATION => TRUE, CURLOPT_COOKIEFILE => "", CURLOPT_RETURNTRANSFER => TRUE, - CURLOPT_HTTPHEADER => array('Accept-language: en'), + CURLOPT_HTTPHEADER => ['Accept-language: en'], CURLOPT_USERAGENT => Tweeper::$userAgent, - )); + ]); $contents = Tweeper::curlExec($ch); curl_close($ch); @@ -180,7 +180,7 @@ class Tweeper { */ private static function getUrlInfo($url) { $ch = curl_init($url); - curl_setopt_array($ch, array( + curl_setopt_array($ch, [ CURLOPT_HEADER => TRUE, CURLOPT_NOBODY => TRUE, CURLOPT_CONNECTTIMEOUT => Tweeper::$maxConnectionTimeout, @@ -188,7 +188,7 @@ class Tweeper { CURLOPT_FOLLOWLOCATION => TRUE, CURLOPT_RETURNTRANSFER => TRUE, CURLOPT_USERAGENT => Tweeper::$userAgent, - )); + ]); $ret = Tweeper::curlExec($ch); if (FALSE === $ret) { @@ -209,7 +209,7 @@ class Tweeper { * Generate an RSS element. */ public static function generateEnclosure($url) { - $supported_content_types = array( + $supported_content_types = [ "application/octet-stream", "application/ogg", "application/pdf", @@ -228,7 +228,7 @@ class Tweeper { "video/mp4", "video/mpeg", "video/ogg", - ); + ]; $url_info = Tweeper::getUrlInfo($url); if (FALSE === $url_info) { @@ -310,13 +310,13 @@ class Tweeper { $encoder = new XmlEncoder(); $normalizer = new ObjectNormalizer(); - $serializer = new Serializer(array($normalizer), array($encoder)); + $serializer = new Serializer([$normalizer], [$encoder]); - $serializer_options = array( + $serializer_options = [ 'xml_encoding' => "UTF-8", 'xml_format_output' => TRUE, 'xml_root_node_name' => $root_node_name, - ); + ]; $xml_data = $serializer->serialize($data, 'xml', $serializer_options); if (!$xml_data) { @@ -375,7 +375,7 @@ class Tweeper { // If there is a host-specific method to get the XML data, use it! $get_xml_host_method = 'getXml' . Tweeper::toUpperCamelCase($host, '.'); if (method_exists($this, $get_xml_host_method)) { - $xml_data = call_user_func_array(array($this, $get_xml_host_method), array($html)); + $xml_data = call_user_func_array([$this, $get_xml_host_method], [$html]); $xmlDoc->loadXML($xml_data); } else { @@ -434,7 +434,7 @@ class Tweeper { if (TRUE === $validate_scheme) { $scheme = $url["scheme"]; - if (!in_array($scheme, array("http", "https"))) { + if (!in_array($scheme, ["http", "https"])) { trigger_error("unsupported scheme: $scheme", E_USER_WARNING); return NULL; } @@ -463,7 +463,7 @@ class Tweeper { $preprocess_html_host_method = 'preprocessHtml' . Tweeper::toUpperCamelCase($host, '.'); if (method_exists($this, $preprocess_html_host_method)) { - $html = call_user_func_array(array($this, $preprocess_html_host_method), array($html)); + $html = call_user_func_array([$this, $preprocess_html_host_method], [$html]); } $xmlDoc = $this->htmlToXml($html, $host); diff --git a/tweeper.php b/tweeper.php index e8f6b87..bcc85fe 100644 --- a/tweeper.php +++ b/tweeper.php @@ -51,18 +51,18 @@ function usage($argv) { * Parse command line options. */ function parse_options_cli($argv, $argc) { - $options = array( + $options = [ 'generate_enclosure' => FALSE, 'show_usernames' => TRUE, 'show_multimedia' => TRUE, 'verbose_output' => TRUE, - ); + ]; if ($argc < 2) { return $options; } - $cli_options = getopt("em:u:v:h", array("help")); + $cli_options = getopt("em:u:v:h", ["help"]); foreach ($cli_options as $opt => $val) { switch ($opt) { case 'e': @@ -121,12 +121,12 @@ function parse_options_cli($argv, $argc) { * Parse options passed from a query string. */ function parse_options_query_string() { - $options = array( + $options = [ 'generate_enclosure' => FALSE, 'show_usernames' => TRUE, 'show_multimedia' => TRUE, 'verbose_output' => TRUE, - ); + ]; if (isset($_GET['src_url'])) { $options['src_url'] = $_GET['src_url'];