diff --git a/src/GoogleTranslate.php b/src/GoogleTranslate.php index eec6946..6af7073 100644 --- a/src/GoogleTranslate.php +++ b/src/GoogleTranslate.php @@ -2,7 +2,6 @@ namespace Stichoza\GoogleTranslate; -use BadMethodCallException; use ErrorException; use GuzzleHttp\Client; use GuzzleHttp\Exception\RequestException; @@ -121,7 +120,7 @@ public function __construct(string $target = 'en', string $source = null, array * @param string $target Language code * @return GoogleTranslate */ - public function setTarget(string $target) : self + public function setTarget(string $target): self { $this->target = $target; return $this; @@ -133,7 +132,7 @@ public function setTarget(string $target) : self * @param string|null $source Language code * @return GoogleTranslate */ - public function setSource(string $source = null) : self + public function setSource(string $source = null): self { $this->source = $source ?? 'auto'; return $this; @@ -145,7 +144,7 @@ public function setSource(string $source = null) : self * @param string $url Google Translate URL base * @return GoogleTranslate */ - public function setUrl(string $url) : self + public function setUrl(string $url): self { $this->url = $url; return $this; @@ -157,7 +156,7 @@ public function setUrl(string $url) : self * @param array $options guzzleHttp client options. * @return GoogleTranslate */ - public function setOptions(array $options = null) : self + public function setOptions(array $options = null): self { $this->options = $options ?? []; return $this; @@ -169,7 +168,7 @@ public function setOptions(array $options = null) : self * @param TokenProviderInterface $tokenProvider * @return GoogleTranslate */ - public function setTokenProvider(TokenProviderInterface $tokenProvider) : self + public function setTokenProvider(TokenProviderInterface $tokenProvider): self { $this->tokenProvider = $tokenProvider; return $this; @@ -218,7 +217,7 @@ public static function trans(string $string, string $target = 'en', string $sour * @throws ErrorException If the HTTP request fails * @throws UnexpectedValueException If received data cannot be decoded */ - public function translate(string $string) : string + public function translate(string $string): string { /* * if source lang and target lang are the same @@ -293,7 +292,7 @@ public function translate(string $string) : string * @throws UnexpectedValueException If received data cannot be decoded * @return array|string Response */ - public function getResponse(string $string) : array + public function getResponse(string $string): array { $queryArray = array_merge($this->urlParams, [ 'sl' => $this->source, @@ -331,7 +330,7 @@ public function getResponse(string $string) : array * @param string $lang Langauge code to verify * @return bool */ - protected function isValidLocale(string $lang) : bool + protected function isValidLocale(string $lang): bool { return (bool) preg_match('/^([a-z]{2})(-[A-Z]{2})?$/', $lang); } diff --git a/src/Tokens/GoogleTokenGenerator.php b/src/Tokens/GoogleTokenGenerator.php index c99dc1f..27720df 100644 --- a/src/Tokens/GoogleTokenGenerator.php +++ b/src/Tokens/GoogleTokenGenerator.php @@ -18,7 +18,7 @@ class GoogleTokenGenerator implements TokenProviderInterface * @param string $text Text to translate * @return string Token */ - public function generateToken(string $source, string $target, string $text) : string + public function generateToken(string $source, string $target, string $text): string { return $this->TL($text); } @@ -144,7 +144,8 @@ private function unsignedRightShift($a, $b) * * @return number */ - private function JS_charCodeAt($str, $index) { + private function JS_charCodeAt($str, $index) + { $utf16 = mb_convert_encoding($str, 'UTF-16LE', 'UTF-8'); return ord($utf16[$index*2]) + (ord($utf16[$index*2+1]) << 8); } @@ -156,7 +157,8 @@ private function JS_charCodeAt($str, $index) { * * @return number */ - private function JS_length($str) { + private function JS_length($str) + { $utf16 = mb_convert_encoding($str, 'UTF-16LE', 'UTF-8'); return strlen($utf16)/2; } diff --git a/src/Tokens/SampleTokenGenerator.php b/src/Tokens/SampleTokenGenerator.php index 59ab422..e167c05 100644 --- a/src/Tokens/SampleTokenGenerator.php +++ b/src/Tokens/SampleTokenGenerator.php @@ -15,7 +15,7 @@ class SampleTokenGenerator implements TokenProviderInterface * @param string $text Text to translate * @return string Token */ - public function generateToken(string $source, string $target, string $text) : string + public function generateToken(string $source, string $target, string $text): string { return sprintf('%d.%d', rand(10000, 99999), rand(10000, 99999)); } diff --git a/src/Tokens/TokenProviderInterface.php b/src/Tokens/TokenProviderInterface.php index d38d6bf..7f5b1a9 100644 --- a/src/Tokens/TokenProviderInterface.php +++ b/src/Tokens/TokenProviderInterface.php @@ -15,5 +15,5 @@ interface TokenProviderInterface * @param string $text Text to translate * @return string Token */ - public function generateToken(string $source, string $target, string $text) : string; + public function generateToken(string $source, string $target, string $text): string; }