Skip to content

Commit

Permalink
Style changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Stichoza committed Feb 11, 2020
1 parent 2d048a9 commit 18920ba
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 14 deletions.
17 changes: 8 additions & 9 deletions src/GoogleTranslate.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace Stichoza\GoogleTranslate;

use BadMethodCallException;
use ErrorException;
use GuzzleHttp\Client;
use GuzzleHttp\Exception\RequestException;
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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);
}
Expand Down
8 changes: 5 additions & 3 deletions src/Tokens/GoogleTokenGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
}
Expand All @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Tokens/SampleTokenGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down
2 changes: 1 addition & 1 deletion src/Tokens/TokenProviderInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

0 comments on commit 18920ba

Please sign in to comment.