Skip to content

Commit

Permalink
Apply fixes from StyleCI
Browse files Browse the repository at this point in the history
  • Loading branch information
dejurin authored and StyleCIBot committed Feb 15, 2019
1 parent 520044a commit 59e4b50
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 15 deletions.
12 changes: 6 additions & 6 deletions GoogleTranslateForFree.php
Expand Up @@ -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);
Expand All @@ -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');
Expand Down Expand Up @@ -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));
Expand All @@ -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
Expand Down
6 changes: 3 additions & 3 deletions example.php
@@ -1,6 +1,6 @@
<?php

require_once ('GoogleTranslateForFree.php');
require_once 'GoogleTranslateForFree.php';

//Single
$source = 'en';
Expand All @@ -11,13 +11,13 @@
$tr = new GoogleTranslateForFree();
$result = $tr->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);
Expand Down
12 changes: 6 additions & 6 deletions src/GoogleTranslateForFree.php
Expand Up @@ -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);
Expand All @@ -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');
Expand Down Expand Up @@ -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));
Expand All @@ -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
Expand Down

0 comments on commit 59e4b50

Please sign in to comment.