From 59e4b50b95546665659c8e4c4972f4eed909154f Mon Sep 17 00:00:00 2001 From: YY Date: Fri, 15 Feb 2019 09:44:42 +0000 Subject: [PATCH] Apply fixes from StyleCI --- GoogleTranslateForFree.php | 12 ++++++------ example.php | 6 +++--- src/GoogleTranslateForFree.php | 12 ++++++------ 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/GoogleTranslateForFree.php b/GoogleTranslateForFree.php index 2cf37b1..b29c4cd 100644 --- a/GoogleTranslateForFree.php +++ b/GoogleTranslateForFree.php @@ -52,7 +52,7 @@ public static function translate($source, $target, $text, $attempts = 5) */ protected static function requestTranslationArray($source, $target, $text, $attempts) { - $arr = array(); + $arr = []; foreach ($text as $value) { // timeout 0.5 sec usleep(500000); @@ -75,11 +75,11 @@ protected static function requestTranslation($source, $target, $text, $attempts) // Google translate URL $url = 'https://translate.google.com/translate_a/single?client=at&dt=t&dt=ld&dt=qca&dt=rm&dt=bd&dj=1&hl=uk-RU&ie=UTF-8&oe=UTF-8&inputm=2&otf=2&iid=1dd3b944-fa62-4b55-b330-74909a99969e'; - $fields = array( + $fields = [ 'sl' => urlencode($source), 'tl' => urlencode($target), - 'q' => urlencode($text), - ); + 'q' => urlencode($text), + ]; if (strlen($fields['q']) >= 5000) { throw new \Exception('Maximum number of characters exceeded: 5000'); @@ -132,7 +132,7 @@ protected static function getSentencesFromJSON($json) */ protected static function curlRequest($url, $fields, $fields_string, $i, $attempts) { - ++$i; + $i++; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_POST, count($fields)); @@ -153,7 +153,7 @@ protected static function curlRequest($url, $fields, $fields_string, $i, $attemp if ($i >= $attempts) { //echo 'Could not connect and get data.',PHP_EOL; - return null; + return; //die('Could not connect and get data.'.PHP_EOL); } else { // timeout 1.5 sec diff --git a/example.php b/example.php index 1fd469b..c5e4c8d 100644 --- a/example.php +++ b/example.php @@ -1,6 +1,6 @@ translate($source, $target, $text, $attempts); -var_dump($result); +var_dump($result); //Array $source = 'en'; $target = 'ru'; $attempts = 5; -$arr = array('hello','world'); +$arr = ['hello', 'world']; $tr = new GoogleTranslateForFree(); $result = $tr->translate($source, $target, $arr, $attempts); diff --git a/src/GoogleTranslateForFree.php b/src/GoogleTranslateForFree.php index fb610f0..06b8f89 100644 --- a/src/GoogleTranslateForFree.php +++ b/src/GoogleTranslateForFree.php @@ -54,7 +54,7 @@ public static function translate($source, $target, $text, $attempts = 5) */ protected static function requestTranslationArray($source, $target, $text, $attempts) { - $arr = array(); + $arr = []; foreach ($text as $value) { // timeout 0.5 sec usleep(500000); @@ -77,11 +77,11 @@ protected static function requestTranslation($source, $target, $text, $attempts) // Google translate URL $url = 'https://translate.google.com/translate_a/single?client=at&dt=t&dt=ld&dt=qca&dt=rm&dt=bd&dj=1&hl=uk-RU&ie=UTF-8&oe=UTF-8&inputm=2&otf=2&iid=1dd3b944-fa62-4b55-b330-74909a99969e'; - $fields = array( + $fields = [ 'sl' => urlencode($source), 'tl' => urlencode($target), - 'q' => urlencode($text), - ); + 'q' => urlencode($text), + ]; if (strlen($fields['q']) >= 5000) { throw new \Exception('Maximum number of characters exceeded: 5000'); @@ -134,7 +134,7 @@ protected static function getSentencesFromJSON($json) */ protected static function curlRequest($url, $fields, $fields_string, $i, $attempts) { - ++$i; + $i++; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_POST, count($fields)); @@ -155,7 +155,7 @@ protected static function curlRequest($url, $fields, $fields_string, $i, $attemp if ($i >= $attempts) { //echo 'Could not connect and get data.',PHP_EOL; - return null; + return; //die('Could not connect and get data.'.PHP_EOL); } else { // timeout 1.5 sec